Hi, If we specify an explicit alignment attribute for globals (either at the Clang or LLVM IR level) we get asm alignment directives with values that seem to be `max(natural_alignment, specified_alignment)`. This seems to happen for multiple archs. GCC instead just emits the asked-for alignment. Is there a good reason for this LLVM behavior? Example: https://godbolt.org/z/B5ZcN_ (Clang) https://godbolt.org/z/qpV7PV (GCC) Thanks, Luís
If you request that the global should be placed in a specific section, LLVM will honor the precise alignment specified. Otherwise, LLVM assumes it's free to increase the alignment to whatever makes sense. LLVM IR doesn't try to distinguish whether the alignment was specified explicitly or implicitly at the source level. We could change that, I guess, but I'm not sure what the goal would be; programs don't really have control over the layout of their .data section anyway. -Eli> -----Original Message----- > From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Luís Marques > via llvm-dev > Sent: Wednesday, June 24, 2020 1:04 PM > To: llvm-dev <llvm-dev at lists.llvm.org> > Subject: [EXT] [llvm-dev] Over-alignment of globals? > > Hi, > > If we specify an explicit alignment attribute for globals (either at > the Clang or LLVM IR level) we get asm alignment directives with > values that seem to be `max(natural_alignment, specified_alignment)`. > This seems to happen for multiple archs. GCC instead just emits the > asked-for alignment. Is there a good reason for this LLVM behavior? > > Example: > https://godbolt.org/z/B5ZcN_ (Clang) > https://godbolt.org/z/qpV7PV (GCC) > > Thanks, > Luís > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Johannes Doerfert via llvm-dev
2020-Jun-24 21:36 UTC
[llvm-dev] Over-alignment of globals?
On 6/24/20 3:49 PM, Eli Friedman via llvm-dev wrote:> LLVM IR doesn't try to distinguish whether the alignment was specified explicitly or implicitly at the source level. We could change that, I guess, but I'm not sure what the goal would be; programs don't really have control over the layout of their .data section anyway.I would prefer not to add more complexity to the alignment of globals if we don't have a particular benefit. We'll introduce new exciting bugs otherwise, eventually ...> -Eli > >> -----Original Message----- >> From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Luís Marques >> via llvm-dev >> Sent: Wednesday, June 24, 2020 1:04 PM >> To: llvm-dev <llvm-dev at lists.llvm.org> >> Subject: [EXT] [llvm-dev] Over-alignment of globals? >> >> Hi, >> >> If we specify an explicit alignment attribute for globals (either at >> the Clang or LLVM IR level) we get asm alignment directives with >> values that seem to be `max(natural_alignment, specified_alignment)`. >> This seems to happen for multiple archs. GCC instead just emits the >> asked-for alignment. Is there a good reason for this LLVM behavior? >> >> Example: >> https://godbolt.org/z/B5ZcN_ (Clang) >> https://godbolt.org/z/qpV7PV (GCC) >> >> Thanks, >> Luís >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reasonably Related Threads
- MSP430 code generation from LLVM IR
- MSP430 code generation from LLVM IR
- MSP430 code generation from LLVM IR
- [LLVMdev] link bytecode files into a native executable with debug info
- lli cannot execute the bc file for RISCV, Unable to find target for this triple