From 044698b39a5360f6132cdbecf484f78ae76cb6e1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 25 Apr 2010 05:30:43 +0000 Subject: [PATCH] Fix PR6921: globals were not getting correctly rounded up to their preferred alignment unless they were common or some other special case. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@102300 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 6 +++--- test/CodeGen/X86/alignment.ll | 16 ++++++++++++++++ test/CodeGen/X86/unaligned-load.ll | 5 +++-- 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 test/CodeGen/X86/alignment.ll diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 4660e1b2ccd..08e2ed60a39 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -285,7 +285,7 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) { OutStreamer.SwitchSection(TheSection); EmitLinkage(GV->getLinkage(), GVSym); - EmitAlignment(AlignLog, GV); + EmitAlignment(AlignLog, GV, AlignLog); if (isVerbose()) { WriteAsOperand(OutStreamer.GetCommentOS(), GV, @@ -987,7 +987,7 @@ bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) { unsigned Align = Log2_32(TD->getPointerPrefAlignment()); if (GV->getName() == "llvm.global_ctors") { OutStreamer.SwitchSection(getObjFileLowering().getStaticCtorSection()); - EmitAlignment(Align, 0); + EmitAlignment(Align); EmitXXStructorList(GV->getInitializer()); if (TM.getRelocationModel() == Reloc::Static && @@ -1001,7 +1001,7 @@ bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) { if (GV->getName() == "llvm.global_dtors") { OutStreamer.SwitchSection(getObjFileLowering().getStaticDtorSection()); - EmitAlignment(Align, 0); + EmitAlignment(Align); EmitXXStructorList(GV->getInitializer()); if (TM.getRelocationModel() == Reloc::Static && diff --git a/test/CodeGen/X86/alignment.ll b/test/CodeGen/X86/alignment.ll new file mode 100644 index 00000000000..e4ac2a072c9 --- /dev/null +++ b/test/CodeGen/X86/alignment.ll @@ -0,0 +1,16 @@ +; RUN: llc %s -o - -mtriple=x86_64-linux-gnu | FileCheck %s + +; This can get rounded up to the preferred alignment (16). +; PR6921 +@GlobalA = global { [384 x i8] } zeroinitializer, align 8 + +; CHECK: .bss +; CHECK: .globl GlobalA +; CHECK: .align 16 +; CHECK: GlobalA: +; CHECK: .zero 384 + +; Common variables should also get rounded up to the preferred alignment (16). +@GlobalB = common global { [384 x i8] } zeroinitializer, align 8 + +; CHECK: .comm GlobalB,384,16 \ No newline at end of file diff --git a/test/CodeGen/X86/unaligned-load.ll b/test/CodeGen/X86/unaligned-load.ll index e210531068e..a99af0605b1 100644 --- a/test/CodeGen/X86/unaligned-load.ll +++ b/test/CodeGen/X86/unaligned-load.ll @@ -28,8 +28,9 @@ return: declare void @llvm.memcpy.i64(i8* nocapture, i8* nocapture, i64, i32) nounwind -; CORE2: .align 3 +; CORE2: .section +; CORE2: .align 4 ; CORE2-NEXT: _.str1: ; CORE2-NEXT: .asciz "DHRYSTONE PROGRAM, SOME STRING" -; CORE2: .align 3 +; CORE2: .align 4 ; CORE2-NEXT: _.str3: