Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 6f7036e

Browse files
author
Huihui Zhang
committed
[GlobalMerge] Fix GlobalMerge on bss external global variables.
Summary: Global variables that are external and zero initialized are supposed to be merged with global variables in the bss section rather than the data section. Reviewers: efriedma, rengolin, t.p.northover, javed.absar, asl, john.brawn, pcc Reviewed By: efriedma Subscribers: dmgreen, llvm-commits Differential Revision: https://reviews.llvm.org/D51379 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@341008 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a166c35 commit 6f7036e

File tree

3 files changed

+95
-30
lines changed

3 files changed

+95
-30
lines changed

lib/CodeGen/GlobalMerge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ bool GlobalMerge::doInitialization(Module &M) {
639639
Type *Ty = GV.getValueType();
640640
if (DL.getTypeAllocSize(Ty) < MaxOffset) {
641641
if (TM &&
642-
TargetLoweringObjectFile::getKindForGlobal(&GV, *TM).isBSSLocal())
642+
TargetLoweringObjectFile::getKindForGlobal(&GV, *TM).isBSS())
643643
BSSGlobals[{AddressSpace, Section}].push_back(&GV);
644644
else if (GV.isConstant())
645645
ConstGlobals[{AddressSpace, Section}].push_back(&GV);

test/CodeGen/AArch64/global-merge-3.ll

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,42 @@
22
; RUN: llc %s -mtriple=aarch64-linux-gnuabi -aarch64-enable-global-merge -global-merge-on-external -disable-post-ra -o - | FileCheck %s
33
; RUN: llc %s -mtriple=aarch64-apple-ios -aarch64-enable-global-merge -global-merge-on-external -disable-post-ra -o - | FileCheck %s --check-prefix=CHECK-APPLE-IOS
44

5-
@x = global [1000 x i32] zeroinitializer, align 1
6-
@y = global [1000 x i32] zeroinitializer, align 1
5+
@x = global [100 x i32] zeroinitializer, align 1
6+
@y = global [100 x i32] zeroinitializer, align 1
77
@z = internal global i32 1, align 4
88

99
define void @f1(i32 %a1, i32 %a2, i32 %a3) {
10-
;CHECK-APPLE-IOS: adrp x8, __MergedGlobals_x@PAGE
10+
;CHECK-APPLE-IOS: adrp x8, __MergedGlobals_x@PAGE+12
1111
;CHECK-APPLE-IOS-NOT: adrp
12-
;CHECK-APPLE-IOS: add x8, x8, __MergedGlobals_x@PAGEOFF
13-
;CHECK-APPLE-IOS: adrp x9, _y@PAGE+12
14-
;CHECK-APPLE-IOS: str w1, [x9]
15-
%x3 = getelementptr inbounds [1000 x i32], [1000 x i32]* @x, i32 0, i64 3
16-
%y3 = getelementptr inbounds [1000 x i32], [1000 x i32]* @y, i32 0, i64 3
12+
;CHECK-APPLE-IOS: add x8, x8, __MergedGlobals_x@PAGEOFF+12
13+
;CHECK-APPLE-IOS: adrp x9, _z@PAGE
14+
;CHECK-APPLE-IOS: str w0, [x8]
15+
;CHECK-APPLE-IOS: str w1, [x8, #400]
16+
;CHECK-APPLE-IOS: str w2, [x9, _z@PAGEOFF]
17+
;CHECK: adrp x8, .L_MergedGlobals+12
18+
;CHECK: add x8, x8, :lo12:.L_MergedGlobals+12
19+
;CHECK: adrp x9, z
20+
;CHECK: str w0, [x8]
21+
;CHECK: str w1, [x8, #400]
22+
;CHECK: str w2, [x9, :lo12:z]
23+
%x3 = getelementptr inbounds [100 x i32], [100 x i32]* @x, i32 0, i64 3
24+
%y3 = getelementptr inbounds [100 x i32], [100 x i32]* @y, i32 0, i64 3
1725
store i32 %a1, i32* %x3, align 4
1826
store i32 %a2, i32* %y3, align 4
1927
store i32 %a3, i32* @z, align 4
2028
ret void
2129
}
2230

23-
;CHECK: .type .L_MergedGlobals,@object // @_MergedGlobals
24-
;CHECK: .p2align 2
25-
;CHECK: .L_MergedGlobals:
26-
;CHECK: .size .L_MergedGlobals, 4004
27-
28-
;CHECK-APPLE-IOS: .zerofill __DATA,__common,_y,4000,2
29-
30-
;CHECK-APPLE-IOS: .p2align 2
31-
;CHECK-APPLE-IOS: __MergedGlobals_x:
32-
;CHECK-APPLE-IOS: .long 1
33-
;CHECK-APPLE-IOS: .space 4000
34-
35-
36-
;CHECK: .set z, .L_MergedGlobals
37-
;CHECK: .globl x
38-
;CHECK: .set x, .L_MergedGlobals+4
39-
;CHECK: .size x, 4000
40-
41-
;CHECK-APPLE-IOS-NOT: .set _z, __MergedGlobals_x
42-
;CHECK-APPLE-IOS:.globl _x
43-
;CHECK-APPLE-IOS:.set _x, __MergedGlobals_x+4
31+
;CHECK-APPLE-IOS: .globl __MergedGlobals_x
32+
;CHECK-APPLE-IOS: .zerofill __DATA,__common,__MergedGlobals_x,800,2
33+
;CHECK-APPLE-IOS: .set _x, __MergedGlobals_x
34+
;CHECK-APPLE-IOS: .set _y, __MergedGlobals_x+400
35+
36+
;CHECK: .type .L_MergedGlobals,@object // @_MergedGlobals
37+
;CHECK: .local .L_MergedGlobals
38+
;CHECK: .comm .L_MergedGlobals,800,4
39+
;CHECK: globl x
40+
;CHECK: .set x, .L_MergedGlobals
41+
;CHECK: globl y
42+
;CHECK: .set y, .L_MergedGlobals+400
43+
;CHECK-NOT: .set z, .L_MergedGlobals
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
; RUN: llc < %s -mtriple=arm-eabi -arm-global-merge | FileCheck %s --check-prefixes=CHECK,CHECK-MERGE
2+
; RUN: llc < %s -mtriple=arm-eabi -arm-global-merge -global-merge-on-external=true | FileCheck %s --check-prefixes=CHECK,CHECK-MERGE
3+
; RUN: llc < %s -mtriple=arm-eabi -arm-global-merge -global-merge-on-external=false | FileCheck %s --check-prefixes=CHECK,CHECK-NO-MERGE
4+
; RUN: llc < %s -mtriple=arm-macho -arm-global-merge | FileCheck %s --check-prefixes=CHECK,CHECK-NO-MERGE
5+
; RUN: llc < %s -mtriple=arm-eabi -arm-global-merge -relocation-model=pic | FileCheck %s --check-prefixes=CHECK,CHECK-NO-MERGE
6+
; RUN: llc < %s -mtriple=thumbv7-win32 -arm-global-merge | FileCheck %s --check-prefixes=CHECK-WIN32
7+
8+
@x = global i32 0, align 4
9+
@y = global i32 0, align 4
10+
@z = internal global i32 1, align 4
11+
12+
define void @f1(i32 %a1, i32 %a2) {
13+
;CHECK: f1:
14+
;CHECK: ldr {{r[0-9]+}}, [[LABEL1:\.?LCPI[0-9]+_[0-9]]]
15+
;CHECK: [[LABEL1]]:
16+
;CHECK-MERGE: .long .L_MergedGlobals
17+
;CHECK-NO-MERGE: .long {{_?x}}
18+
;CHECK-WIN32: f1:
19+
;CHECK-WIN32: movw [[REG1:r[0-9]+]], :lower16:.L_MergedGlobals
20+
;CHECK-WIN32: movt [[REG1]], :upper16:.L_MergedGlobals
21+
store i32 %a1, i32* @x, align 4
22+
store i32 %a2, i32* @y, align 4
23+
ret void
24+
}
25+
26+
define void @g1(i32 %a1, i32 %a2) {
27+
;CHECK: g1:
28+
;CHECK: ldr {{r[0-9]+}}, [[LABEL2:\.?LCPI[0-9]+_[0-9]]]
29+
;CHECK: ldr {{r[0-9]+}}, [[LABEL3:\.?LCPI[0-9]+_[0-9]]]
30+
;CHECK: [[LABEL2]]:
31+
;CHECK-MERGE: .long {{_?z}}
32+
;CHECK: [[LABEL3]]:
33+
;CHECK-MERGE: .long .L_MergedGlobals
34+
;CHECK-NO-MERGE: .long {{_?y}}
35+
;CHECK-WIN32: g1:
36+
;CHECK-WIN32: movw [[REG2:r[0-9]+]], :lower16:z
37+
;CHECK-WIN32: movt [[REG2]], :upper16:z
38+
;CHECK-WIN32: movw [[REG3:r[0-9]+]], :lower16:.L_MergedGlobals
39+
;CHECK-WIN32: movt [[REG3]], :upper16:.L_MergedGlobals
40+
store i32 %a1, i32* @y, align 4
41+
store i32 %a2, i32* @z, align 4
42+
ret void
43+
}
44+
45+
;CHECK-NO-MERGE-NOT: .globl .L_MergedGlobals
46+
47+
;CHECK-MERGE: .type .L_MergedGlobals,%object
48+
;CHECK-MERGE: .local .L_MergedGlobals
49+
;CHECK-MERGE: .comm .L_MergedGlobals,8,4
50+
;CHECK-WIN32: .lcomm .L_MergedGlobals,8,4
51+
52+
;CHECK-MERGE: .globl x
53+
;CHECK-MERGE: .set x, .L_MergedGlobals
54+
;CHECK-MERGE: .size x, 4
55+
;CHECK-MERGE: .globl y
56+
;CHECK-MERGE: .set y, .L_MergedGlobals+4
57+
;CHECK-MERGE: .size y, 4
58+
;CHECK-MERGE-NOT: .set z, .L_MergedGlobals+8
59+
60+
61+
;CHECK-WIN32: .globl x
62+
;CHECK-WIN32: .set x, .L_MergedGlobals
63+
;CHECK-WIN32: .globl y
64+
;CHECK-WIN32: .set y, .L_MergedGlobals+4
65+
;CHECK-WIN32-NOT: .set z, .L_MergedGlobals+8

0 commit comments

Comments
 (0)