Index: llvm/trunk/lib/CodeGen/GlobalMerge.cpp =================================================================== --- llvm/trunk/lib/CodeGen/GlobalMerge.cpp +++ llvm/trunk/lib/CodeGen/GlobalMerge.cpp @@ -500,6 +500,11 @@ GlobalVariable::NotThreadLocal, AddrSpace); const StructLayout *MergedLayout = DL.getStructLayout(MergedTy); + // Set the alignment of the merged struct as the maximum alignment of the + // globals to prevent over-alignment. We don't handle globals that are not + // default aligned, so the alignment of the MergedLayout struct is + // equivalent. + MergedGV->setAlignment(MergedLayout->getAlignment()); for (ssize_t k = i, idx = 0; k != j; k = GlobalSet.find_next(k), ++idx) { GlobalValue::LinkageTypes Linkage = Globals[k]->getLinkage(); Index: llvm/trunk/test/CodeGen/AArch64/global-merge-1.ll =================================================================== --- llvm/trunk/test/CodeGen/AArch64/global-merge-1.ll +++ llvm/trunk/test/CodeGen/AArch64/global-merge-1.ll @@ -22,10 +22,10 @@ ;CHECK: .type .L_MergedGlobals,@object // @_MergedGlobals ;CHECK: .local .L_MergedGlobals -;CHECK: .comm .L_MergedGlobals,8,8 +;CHECK: .comm .L_MergedGlobals,8,4 ;CHECK: .set m, .L_MergedGlobals ;CHECK: .set n, .L_MergedGlobals+4 -;CHECK-APPLE-IOS: .zerofill __DATA,__bss,__MergedGlobals,8,3 ; @_MergedGlobals +;CHECK-APPLE-IOS: .zerofill __DATA,__bss,__MergedGlobals,8,2 ; @_MergedGlobals ;CHECK-APPLE-IOS-NOT: .set _m, l__MergedGlobals ;CHECK-APPLE-IOS-NOT: .set _n, l__MergedGlobals+4 Index: llvm/trunk/test/CodeGen/AArch64/global-merge-2.ll =================================================================== --- llvm/trunk/test/CodeGen/AArch64/global-merge-2.ll +++ llvm/trunk/test/CodeGen/AArch64/global-merge-2.ll @@ -29,7 +29,7 @@ ;CHECK: .type .L_MergedGlobals,@object // @_MergedGlobals ;CHECK: .local .L_MergedGlobals -;CHECK: .comm .L_MergedGlobals,12,8 +;CHECK: .comm .L_MergedGlobals,12,4 ;CHECK: .globl x ;CHECK: .set x, .L_MergedGlobals @@ -41,7 +41,7 @@ ;CHECK: .set z, .L_MergedGlobals+8 ;CHECK: .size z, 4 -;CHECK-APPLE-IOS: .zerofill __DATA,__common,__MergedGlobals_x,12,3 +;CHECK-APPLE-IOS: .zerofill __DATA,__common,__MergedGlobals_x,12,2 ;CHECK-APPLE-IOS: .globl _x ;CHECK-APPLE-IOS: .set {{.*}}, __MergedGlobals_x Index: llvm/trunk/test/CodeGen/AArch64/global-merge-3.ll =================================================================== --- llvm/trunk/test/CodeGen/AArch64/global-merge-3.ll +++ llvm/trunk/test/CodeGen/AArch64/global-merge-3.ll @@ -21,13 +21,13 @@ } ;CHECK: .type .L_MergedGlobals,@object // @_MergedGlobals -;CHECK: .p2align 4 +;CHECK: .p2align 2 ;CHECK: .L_MergedGlobals: ;CHECK: .size .L_MergedGlobals, 4004 ;CHECK-APPLE-IOS: .zerofill __DATA,__common,_y,4000,2 -;CHECK-APPLE-IOS: .p2align 4 +;CHECK-APPLE-IOS: .p2align 2 ;CHECK-APPLE-IOS: __MergedGlobals_x: ;CHECK-APPLE-IOS: .long 1 ;CHECK-APPLE-IOS: .space 4000 Index: llvm/trunk/test/CodeGen/AArch64/global-merge-4.ll =================================================================== --- llvm/trunk/test/CodeGen/AArch64/global-merge-4.ll +++ llvm/trunk/test/CodeGen/AArch64/global-merge-4.ll @@ -66,7 +66,7 @@ ;CHECK: .type .L_MergedGlobals,@object // @_MergedGlobals ;CHECK: .local .L_MergedGlobals -;CHECK: .comm .L_MergedGlobals,60,16 +;CHECK: .comm .L_MergedGlobals,60,4 attributes #0 = { nounwind ssp } attributes #1 = { nounwind readnone ssp } Index: llvm/trunk/test/CodeGen/AArch64/global-merge-group-by-use.ll =================================================================== --- llvm/trunk/test/CodeGen/AArch64/global-merge-group-by-use.ll +++ llvm/trunk/test/CodeGen/AArch64/global-merge-group-by-use.ll @@ -88,8 +88,8 @@ ; CHECK-DAG: .zerofill __DATA,__bss,_o5,4,2 -; CHECK-DAG: .zerofill __DATA,__bss,[[SET1]],8,3 -; CHECK-DAG: .zerofill __DATA,__bss,[[SET2]],12,3 -; CHECK-DAG: .zerofill __DATA,__bss,[[SET3]],12,3 +; CHECK-DAG: .zerofill __DATA,__bss,[[SET1]],8,2 +; CHECK-DAG: .zerofill __DATA,__bss,[[SET2]],12,2 +; CHECK-DAG: .zerofill __DATA,__bss,[[SET3]],12,2 attributes #0 = { nounwind } Index: llvm/trunk/test/CodeGen/AArch64/global-merge-ignore-single-use-minsize.ll =================================================================== --- llvm/trunk/test/CodeGen/AArch64/global-merge-ignore-single-use-minsize.ll +++ llvm/trunk/test/CodeGen/AArch64/global-merge-ignore-single-use-minsize.ll @@ -67,7 +67,7 @@ ret void } -; CHECK-DAG: .zerofill __DATA,__bss,[[SET]],16,3 +; CHECK-DAG: .zerofill __DATA,__bss,[[SET]],16,2 ; CHECK-DAG: .zerofill __DATA,__bss,_m2,4,2 ; CHECK-DAG: .zerofill __DATA,__bss,_n2,4,2 ; CHECK-DAG: .zerofill __DATA,__bss,_n4,4,2 Index: llvm/trunk/test/CodeGen/AArch64/global-merge-ignore-single-use.ll =================================================================== --- llvm/trunk/test/CodeGen/AArch64/global-merge-ignore-single-use.ll +++ llvm/trunk/test/CodeGen/AArch64/global-merge-ignore-single-use.ll @@ -58,7 +58,7 @@ ret void } -; CHECK-DAG: .zerofill __DATA,__bss,[[SET]],20,4 +; CHECK-DAG: .zerofill __DATA,__bss,[[SET]],20,2 ; CHECK-DAG: .zerofill __DATA,__bss,_o2,4,2 attributes #0 = { nounwind } Index: llvm/trunk/test/CodeGen/ARM/global-merge-1.ll =================================================================== --- llvm/trunk/test/CodeGen/ARM/global-merge-1.ll +++ llvm/trunk/test/CodeGen/ARM/global-merge-1.ll @@ -11,16 +11,16 @@ ; MERGE-NOT: .zerofill __DATA,__bss,_bar,20,2 ; MERGE-NOT: .zerofill __DATA,__bss,_baz,20,2 ; MERGE-NOT: .zerofill __DATA,__bss,_foo,20,2 -; MERGE: .zerofill __DATA,__bss,__MergedGlobals,60,4 +; MERGE: .zerofill __DATA,__bss,__MergedGlobals,60,2 ; MERGE-NOT: .zerofill __DATA,__bss,_bar,20,2 ; MERGE-NOT: .zerofill __DATA,__bss,_baz,20,2 ; MERGE-NOT: .zerofill __DATA,__bss,_foo,20,2 -; NO-MERGE-NOT: .zerofill __DATA,__bss,__MergedGlobals,60,4 +; NO-MERGE-NOT: .zerofill __DATA,__bss,__MergedGlobals,60,2 ; NO-MERGE: .zerofill __DATA,__bss,_bar,20,2 ; NO-MERGE: .zerofill __DATA,__bss,_baz,20,2 ; NO-MERGE: .zerofill __DATA,__bss,_foo,20,2 -; NO-MERGE-NOT: .zerofill __DATA,__bss,__MergedGlobals,60,4 +; NO-MERGE-NOT: .zerofill __DATA,__bss,__MergedGlobals,60,2 target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:32:64-v128:32:128-a0:0:32-n32-S32" target triple = "thumbv7-apple-ios3.0.0" Index: llvm/trunk/test/CodeGen/ARM/global-merge-alignment.ll =================================================================== --- llvm/trunk/test/CodeGen/ARM/global-merge-alignment.ll +++ llvm/trunk/test/CodeGen/ARM/global-merge-alignment.ll @@ -0,0 +1,24 @@ +; RUN: llc < %s -arm-global-merge -data-sections | FileCheck %s + +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" +target triple = "thumbv7em-arm-none-eabi" + +@f = local_unnamed_addr global [4 x i32*] zeroinitializer, align 4 +@d = local_unnamed_addr global i64 0, align 8 + +;CHECK: .section .bss..L_MergedGlobals,"aw",%nobits +;CHECK-NEXT: .p2align 3 +;CHECK-NEXT: .L_MergedGlobals: +;CHECK-NEXT: .zero 24 +;CHECK-NEXT: .size .L_MergedGlobals, 24 + + +define i32 @func_1() { + %1 = load i64, i64* @d, align 8 + %2 = load i32*, i32** getelementptr inbounds ([4 x i32*], [4 x i32*]* @f, i32 0, i32 0), align 4 + %3 = load i32, i32* %2, align 4 + %4 = trunc i64 %1 to i32 + %5 = add i32 %3, %4 + ret i32 %5 +} + Index: llvm/trunk/test/Transforms/GlobalMerge/debug-info.ll =================================================================== --- llvm/trunk/test/Transforms/GlobalMerge/debug-info.ll +++ llvm/trunk/test/Transforms/GlobalMerge/debug-info.ll @@ -3,7 +3,7 @@ source_filename = "test/Transforms/GlobalMerge/debug-info.ll" target datalayout = "e-p:64:64" target triple = "x86_64-unknown-linux-gnu" -; CHECK: @_MergedGlobals = private global { i32, i32 } { i32 1, i32 2 }, !dbg [[A:![0-9]+]], !dbg [[B:![0-9]+]] +; CHECK: @_MergedGlobals = private global { i32, i32 } { i32 1, i32 2 }, align 4, !dbg [[A:![0-9]+]], !dbg [[B:![0-9]+]] @a = internal global i32 1, !dbg !0 @b = internal global i32 2, !dbg !2