[llvm-commits] [llvm] r102365 - in /llvm/trunk: lib/CodeGen/AsmPrinter/AsmPrinter.cpp test/CodeGen/X86/alignment.ll test/CodeGen/X86/unaligned-load.ll
Chris Lattner
sabre at nondot.org
Mon Apr 26 11:46:46 PDT 2010
Author: lattner
Date: Mon Apr 26 13:46:46 2010
New Revision: 102365
URL: http://llvm.org/viewvc/llvm-project?rev=102365&view=rev
Log:
fix PR6921 a different way. Intead of increasing the
alignment of globals with a specified alignment, we fix
common variables to obey their alignment. Add a comment
explaining why this behavior is important.
Added:
llvm/trunk/test/CodeGen/X86/alignment.ll
Modified:
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/trunk/test/CodeGen/X86/unaligned-load.ll
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=102365&r1=102364&r2=102365&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Mon Apr 26 13:46:46 2010
@@ -228,7 +228,15 @@
const TargetData *TD = TM.getTargetData();
unsigned Size = TD->getTypeAllocSize(GV->getType()->getElementType());
- unsigned AlignLog = TD->getPreferredAlignmentLog(GV);
+
+ // If the alignment is specified, we *must* obey it. Overaligning a global
+ // with a specified alignment is a prompt way to break globals emitted to
+ // sections and expected to be contiguous (e.g. ObjC metadata).
+ unsigned AlignLog;
+ if (unsigned GVAlign = GV->getAlignment())
+ AlignLog = Log2_32(GVAlign);
+ else
+ AlignLog = TD->getPreferredAlignmentLog(GV);
// Handle common and BSS local symbols (.lcomm).
if (GVKind.isCommon() || GVKind.isBSSLocal()) {
Added: llvm/trunk/test/CodeGen/X86/alignment.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/alignment.ll?rev=102365&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/alignment.ll (added)
+++ llvm/trunk/test/CodeGen/X86/alignment.ll Mon Apr 26 13:46:46 2010
@@ -0,0 +1,18 @@
+; RUN: llc %s -o - -mtriple=x86_64-linux-gnu | FileCheck %s
+
+; This cannot get rounded up to the preferred alignment (16) if they have an
+; explicit alignment specified.
+ at GlobalA = global { [384 x i8] } zeroinitializer, align 8
+
+; CHECK: .bss
+; CHECK: .globl GlobalA
+; CHECK: .align 8
+; CHECK: GlobalA:
+; CHECK: .zero 384
+
+; Common variables should not get rounded up to the preferred alignment (16) if
+; they have an explicit alignment specified.
+; PR6921
+ at GlobalB = common global { [384 x i8] } zeroinitializer, align 8
+
+; CHECK: .comm GlobalB,384,8
\ No newline at end of file
Modified: llvm/trunk/test/CodeGen/X86/unaligned-load.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/unaligned-load.ll?rev=102365&r1=102364&r2=102365&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/unaligned-load.ll (original)
+++ llvm/trunk/test/CodeGen/X86/unaligned-load.ll Mon Apr 26 13:46:46 2010
@@ -28,6 +28,7 @@
declare void @llvm.memcpy.i64(i8* nocapture, i8* nocapture, i64, i32) nounwind
+; CORE2: .section
; CORE2: .align 3
; CORE2-NEXT: _.str1:
; CORE2-NEXT: .asciz "DHRYSTONE PROGRAM, SOME STRING"
More information about the llvm-commits
mailing list