clang promoting local to global

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

clang promoting local to global

Ryan Taylor-5
I have a const array allocated inside a function and the IR is showing this has a global function (ie. there is no allocation for the space inside the function).

For example:

const int32 local_array[256] = {constValue, constValue, ..... }

Is there any particular reason this may be occuring?

Thanks.

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: clang promoting local to global

Eli Friedman-2
On Wed, Aug 15, 2012 at 11:26 AM, Ryan Taylor <[hidden email]> wrote:
> I have a const array allocated inside a function and the IR is showing this
> has a global function (ie. there is no allocation for the space inside the
> function).
>
> For example:
>
> const int32 local_array[256] = {constValue, constValue, ..... }
>
> Is there any particular reason this may be occuring?

It's an optimization; IIRC, you can turn it off with -fno-merge-all-constants.

-Eli
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: clang promoting local to global

Ryan Taylor-5
Eli, thanks for responding, unfortunately, this did not resolve my issue. It's a locally allocated array in the C code, but I'm not seeing any alloca in the IR just geps from the variable, which is never setup.

On Wed, Aug 15, 2012 at 11:33 AM, Eli Friedman <[hidden email]> wrote:
On Wed, Aug 15, 2012 at 11:26 AM, Ryan Taylor <[hidden email]> wrote:
> I have a const array allocated inside a function and the IR is showing this
> has a global function (ie. there is no allocation for the space inside the
> function).
>
> For example:
>
> const int32 local_array[256] = {constValue, constValue, ..... }
>
> Is there any particular reason this may be occuring?

It's an optimization; IIRC, you can turn it off with -fno-merge-all-constants.

-Eli


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: clang promoting local to global

Eli Friedman-2
On Wed, Aug 15, 2012 at 11:40 AM, Ryan Taylor <[hidden email]> wrote:
> Eli, thanks for responding, unfortunately, this did not resolve my issue.
> It's a locally allocated array in the C code, but I'm not seeing any alloca
> in the IR just geps from the variable, which is never setup.

That's strange; I just checked, and -fno-merge-all-constants
definitely does have an effect for a simple testcase like the
following (just using clang -emit-llvm at -O0):

void f() { const int x[5] = {1,2,3,4}; }

What does your testcase look like?

-Eli
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: clang promoting local to global

Ryan Taylor-5
#define r10(p,q,r,s) 0x##s##r##q##p
   #undef r
   #define r r10
    const word it_tab[4][256] = { r(const, const, const, const), r(.......), r(.......) ....... };

All of this is done inside the function I want the alloc in. The variable is not declared/defined/used anywhere else.



On Wed, Aug 15, 2012 at 12:00 PM, Eli Friedman <[hidden email]> wrote:
On Wed, Aug 15, 2012 at 11:40 AM, Ryan Taylor <[hidden email]> wrote:
> Eli, thanks for responding, unfortunately, this did not resolve my issue.
> It's a locally allocated array in the C code, but I'm not seeing any alloca
> in the IR just geps from the variable, which is never setup.

That's strange; I just checked, and -fno-merge-all-constants
definitely does have an effect for a simple testcase like the
following (just using clang -emit-llvm at -O0):

void f() { const int x[5] = {1,2,3,4}; }

What does your testcase look like?

-Eli


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: clang promoting local to global

Ryan Taylor-5
So there are some #define (defined outside the function scope) that use it_tab that are used inside the function, is this why it is promoting it to a global?

On Wed, Aug 15, 2012 at 2:57 PM, Ryan Taylor <[hidden email]> wrote:
#define r10(p,q,r,s) 0x##s##r##q##p
   #undef r
   #define r r10
    const word it_tab[4][256] = { r(const, const, const, const), r(.......), r(.......) ....... };

All of this is done inside the function I want the alloc in. The variable is not declared/defined/used anywhere else.




On Wed, Aug 15, 2012 at 12:00 PM, Eli Friedman <[hidden email]> wrote:
On Wed, Aug 15, 2012 at 11:40 AM, Ryan Taylor <[hidden email]> wrote:
> Eli, thanks for responding, unfortunately, this did not resolve my issue.
> It's a locally allocated array in the C code, but I'm not seeing any alloca
> in the IR just geps from the variable, which is never setup.

That's strange; I just checked, and -fno-merge-all-constants
definitely does have an effect for a simple testcase like the
following (just using clang -emit-llvm at -O0):

void f() { const int x[5] = {1,2,3,4}; }

What does your testcase look like?

-Eli



_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: clang promoting local to global

Eli Friedman-2
On Wed, Aug 15, 2012 at 3:17 PM, Ryan Taylor <[hidden email]> wrote:
> So there are some #define (defined outside the function scope) that use
> it_tab that are used inside the function, is this why it is promoting it to
> a global?

Macros shouldn't matter. Please give a complete testcase and steps to
reproduce.  And please don't top-post.

-Eli

>
> On Wed, Aug 15, 2012 at 2:57 PM, Ryan Taylor <[hidden email]> wrote:
>>
>> #define r10(p,q,r,s) 0x##s##r##q##p
>>    #undef r
>>    #define r r10
>>     const word it_tab[4][256] = { r(const, const, const, const),
>> r(.......), r(.......) ....... };
>>
>> All of this is done inside the function I want the alloc in. The variable
>> is not declared/defined/used anywhere else.
>>
>>
>>
>>
>> On Wed, Aug 15, 2012 at 12:00 PM, Eli Friedman <[hidden email]>
>> wrote:
>>>
>>> On Wed, Aug 15, 2012 at 11:40 AM, Ryan Taylor <[hidden email]> wrote:
>>> > Eli, thanks for responding, unfortunately, this did not resolve my
>>> > issue.
>>> > It's a locally allocated array in the C code, but I'm not seeing any
>>> > alloca
>>> > in the IR just geps from the variable, which is never setup.
>>>
>>> That's strange; I just checked, and -fno-merge-all-constants
>>> definitely does have an effect for a simple testcase like the
>>> following (just using clang -emit-llvm at -O0):
>>>
>>> void f() { const int x[5] = {1,2,3,4}; }
>>>
>>> What does your testcase look like?
>>>
>>> -Eli
>>
>>
>
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: clang promoting local to global

Ryan Taylor-5


On Wed, Aug 15, 2012 at 4:10 PM, Eli Friedman <[hidden email]> wrote:
On Wed, Aug 15, 2012 at 3:17 PM, Ryan Taylor <[hidden email]> wrote:
> So there are some #define (defined outside the function scope) that use
> it_tab that are used inside the function, is this why it is promoting it to
> a global?

Macros shouldn't matter. Please give a complete testcase and steps to
reproduce.  And please don't top-post.

-Eli

>
> On Wed, Aug 15, 2012 at 2:57 PM, Ryan Taylor <[hidden email]> wrote:
>>
>> #define r10(p,q,r,s) 0x##s##r##q##p
>>    #undef r
>>    #define r r10
>>     const word it_tab[4][256] = { r(const, const, const, const),
>> r(.......), r(.......) ....... };
>>
>> All of this is done inside the function I want the alloc in. The variable
>> is not declared/defined/used anywhere else.
>>
>>
>>
>>
>> On Wed, Aug 15, 2012 at 12:00 PM, Eli Friedman <[hidden email]>
>> wrote:
>>>
>>> On Wed, Aug 15, 2012 at 11:40 AM, Ryan Taylor <[hidden email]> wrote:
>>> > Eli, thanks for responding, unfortunately, this did not resolve my
>>> > issue.
>>> > It's a locally allocated array in the C code, but I'm not seeing any
>>> > alloca
>>> > in the IR just geps from the variable, which is never setup.
>>>
>>> That's strange; I just checked, and -fno-merge-all-constants
>>> definitely does have an effect for a simple testcase like the
>>> following (just using clang -emit-llvm at -O0):
>>>
>>> void f() { const int x[5] = {1,2,3,4}; }
>>>
>>> What does your testcase look like?
>>>
>>> -Eli
>>
>>
>

#define other_def(x, tab, vf, rf, c)     (x ^ tab[0][x ^ c0 ^ vf ^ rf ^ c)
#define my_def(y,x,k,c)      defs(y,c) = (k}[c] ^ other_def(x, it_tab, inv_var, rf1, c)
void my_func() {
     #define r10(p,q,r,s) 0x##s##r##q##p
   #undef r
   #define r r10
    const word it_tab[4][256] = { r(const, const, const, const), r(.......), r(.......) ....... };
}

You prefer bottom posting? Ok.

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: clang promoting local to global

Richard Smith-33
On Wed, Aug 15, 2012 at 4:20 PM, Ryan Taylor <[hidden email]> wrote:
On Wed, Aug 15, 2012 at 4:10 PM, Eli Friedman <[hidden email]> wrote:
On Wed, Aug 15, 2012 at 3:17 PM, Ryan Taylor <[hidden email]> wrote:
> So there are some #define (defined outside the function scope) that use
> it_tab that are used inside the function, is this why it is promoting it to
> a global?

Macros shouldn't matter. Please give a complete testcase and steps to
reproduce.  And please don't top-post.

#define other_def(x, tab, vf, rf, c)     (x ^ tab[0][x ^ c0 ^ vf ^ rf ^ c)
#define my_def(y,x,k,c)      defs(y,c) = (k}[c] ^ other_def(x, it_tab, inv_var, rf1, c)
void my_func() {

     #define r10(p,q,r,s) 0x##s##r##q##p
   #undef r
   #define r r10
    const word it_tab[4][256] = { r(const, const, const, const), r(.......), r(.......) ....... };
}

That's not a complete testcase; it isn't valid C. Also, please give steps to reproduce the problem (what commands you ran) and tell us what output you got.

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev