alignment of internal Global Values

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

alignment of internal Global Values

Arnaud Allard de Grandmaison

Hi,

 

I am a bit puzzled by the alignement set on GlobalValues for which the only differences should be the linkage. I get the same behaviour with llvm-2.6 or with the svn head, using x86 as the target.

 

The following C code can be used to reproduce it:

 

short GV[] = { 1,2,3,4,5,6,7,8 };

 

int test(unsigned a)

{

  static short internalGV[] = { 1,2,3,4,5,6,7,8};

 

  return internalGV[a]++;

}

 

The IR output from clang looks like:

@GV = global [8 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8], align 2

@test.internalGV = internal global [8 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8]

 

Note the alignement specifier for GV, which does not show up for internalGV. The issue will happen later on, when the backend will choose some default alignement, which may even depend on the size of the global value : the size of the data section will depend on the visibility of its data. For example, running the above example with 16 elements in GV & internalGV will make a big difference in the x86 .S file : GV will still be 2 bytes aligned, whereas internalGV will be 16bytes aligned.

 

I can not see any obvious reason why this could be the desired behaviour, so I attached a patch to fix this.

 

Best regards,

--

Arnaud de Grandmaison


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

internalGV-alignment.patch (440 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: alignment of internal Global Values

Chris Lattner
<base href="x-msg://410/">
On Mar 8, 2010, at 9:24 AM, Arnaud Allard de Grandmaison wrote:

Hi,
 
I am a bit puzzled by the alignement set on GlobalValues for which the only differences should be the linkage. I get the same behaviour with llvm-2.6 or with the svn head, using x86 as the target.

Sounds like something that would be good to fix, but your patch doesn't build on mainline:

CGDecl.cpp: In member function ‘llvm::GlobalVariable* clang::CodeGen::CodeGenFunction::AddInitializerToGlobalBlockVarDecl(const clang::VarDecl&, llvm::GlobalVariable*)’:
CGDecl.cpp:190: error: ‘class clang::ASTContext’ has no member named ‘getDeclAlignInBytes’
make[2]: *** [/Volumes/Projects/cvs/llvm/tools/clang/lib/CodeGen/Debug/CGDecl.o] Error 1
m

-Chris

 
The following C code can be used to reproduce it:
 
short GV[] = { 1,2,3,4,5,6,7,8 };
 
int test(unsigned a)
{
  static short internalGV[] = { 1,2,3,4,5,6,7,8};
 
  return internalGV[a]++;
}
 
The IR output from clang looks like:
@GV = global [8 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8], align 2
@test.internalGV = internal global [8 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8]
 
Note the alignement specifier for GV, which does not show up for internalGV. The issue will happen later on, when the backend will choose some default alignement, which may even depend on the size of the global value : the size of the data section will depend on the visibility of its data. For example, running the above example with 16 elements in GV & internalGV will make a big difference in the x86 .S file : GV will still be 2 bytes aligned, whereas internalGV will be 16bytes aligned.
 
I can not see any obvious reason why this could be the desired behaviour, so I attached a patch to fix this.
 
Best regards,
--
Arnaud de Grandmaison
<internalGV-alignment.patch>_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: alignment of internal Global Values

Arnaud Allard de Grandmaison
All apologies. I should have check it against head.

The corrected patch is attached. It applies cleanly on the head of llvm + clang
--
Arnaud de Grandmaison
________________________________________
From: Chris Lattner [[hidden email]]
Sent: Monday, March 08, 2010 8:07 PM
To: Arnaud Allard de Grandmaison
Cc: [hidden email]
Subject: Re: [cfe-dev] alignment of internal Global Values

On Mar 8, 2010, at 9:24 AM, Arnaud Allard de Grandmaison wrote:

Hi,

I am a bit puzzled by the alignement set on GlobalValues for which the only differences should be the linkage. I get the same behaviour with llvm-2.6 or with the svn head, using x86 as the target.

Sounds like something that would be good to fix, but your patch doesn't build on mainline:

CGDecl.cpp: In member function ‘llvm::GlobalVariable* clang::CodeGen::CodeGenFunction::AddInitializerToGlobalBlockVarDecl(const clang::VarDecl&, llvm::GlobalVariable*)’:
CGDecl.cpp:190: error: ‘class clang::ASTContext’ has no member named ‘getDeclAlignInBytes’
make[2]: *** [/Volumes/Projects/cvs/llvm/tools/clang/lib/CodeGen/Debug/CGDecl.o] Error 1
m

-Chris


The following C code can be used to reproduce it:

short GV[] = { 1,2,3,4,5,6,7,8 };

int test(unsigned a)
{
  static short internalGV[] = { 1,2,3,4,5,6,7,8};

  return internalGV[a]++;
}

The IR output from clang looks like:
@GV = global [8 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8], align 2
@test.internalGV = internal global [8 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8]

Note the alignement specifier for GV, which does not show up for internalGV. The issue will happen later on, when the backend will choose some default alignement, which may even depend on the size of the global value : the size of the data section will depend on the visibility of its data. For example, running the above example with 16 elements in GV & internalGV will make a big difference in the x86 .S file : GV will still be 2 bytes aligned, whereas internalGV will be 16bytes aligned.

I can not see any obvious reason why this could be the desired behaviour, so I attached a patch to fix this.

Best regards,
--
Arnaud de Grandmaison
<internalGV-alignment.patch>_______________________________________________
cfe-dev mailing list
[hidden email]<mailto:[hidden email]>
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

internalGV-alignment.patch (698 bytes) Download Attachment
test_internalGV-alignment.c (240 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: alignment of internal Global Values

Chris Lattner
Thanks, applied in r98204,

-Chris

On Mar 8, 2010, at 1:00 PM, Arnaud Allard de Grandmaison wrote:

> All apologies. I should have check it against head.
>
> The corrected patch is attached. It applies cleanly on the head of llvm + clang
> --
> Arnaud de Grandmaison
> ________________________________________
> From: Chris Lattner [[hidden email]]
> Sent: Monday, March 08, 2010 8:07 PM
> To: Arnaud Allard de Grandmaison
> Cc: [hidden email]
> Subject: Re: [cfe-dev] alignment of internal Global Values
>
> On Mar 8, 2010, at 9:24 AM, Arnaud Allard de Grandmaison wrote:
>
> Hi,
>
> I am a bit puzzled by the alignement set on GlobalValues for which the only differences should be the linkage. I get the same behaviour with llvm-2.6 or with the svn head, using x86 as the target.
>
> Sounds like something that would be good to fix, but your patch doesn't build on mainline:
>
> CGDecl.cpp: In member function ‘llvm::GlobalVariable* clang::CodeGen::CodeGenFunction::AddInitializerToGlobalBlockVarDecl(const clang::VarDecl&, llvm::GlobalVariable*)’:
> CGDecl.cpp:190: error: ‘class clang::ASTContext’ has no member named ‘getDeclAlignInBytes’
> make[2]: *** [/Volumes/Projects/cvs/llvm/tools/clang/lib/CodeGen/Debug/CGDecl.o] Error 1
> m
>
> -Chris
>
>
> The following C code can be used to reproduce it:
>
> short GV[] = { 1,2,3,4,5,6,7,8 };
>
> int test(unsigned a)
> {
>  static short internalGV[] = { 1,2,3,4,5,6,7,8};
>
>  return internalGV[a]++;
> }
>
> The IR output from clang looks like:
> @GV = global [8 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8], align 2
> @test.internalGV = internal global [8 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8]
>
> Note the alignement specifier for GV, which does not show up for internalGV. The issue will happen later on, when the backend will choose some default alignement, which may even depend on the size of the global value : the size of the data section will depend on the visibility of its data. For example, running the above example with 16 elements in GV & internalGV will make a big difference in the x86 .S file : GV will still be 2 bytes aligned, whereas internalGV will be 16bytes aligned.
>
> I can not see any obvious reason why this could be the desired behaviour, so I attached a patch to fix this.
>
> Best regards,
> --
> Arnaud de Grandmaison
> <internalGV-alignment.patch>_______________________________________________
> cfe-dev mailing list
> [hidden email]<mailto:[hidden email]>
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
> <internalGV-alignment.patch><test_internalGV-alignment.c>_______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev