diff options
author | Ahmed Bougacha <ahmed.bougacha@gmail.com> | 2015-04-18 01:21:58 +0000 |
---|---|---|
committer | Ahmed Bougacha <ahmed.bougacha@gmail.com> | 2015-04-18 01:21:58 +0000 |
commit | 279e3ee954fd41164fd78e4f20ea54a3c53cc5c8 (patch) | |
tree | ec1973be7ffd124e68efe912e301c3f3f4f66772 /llvm/test | |
parent | 7c60f20e497c10e506a44317aa98ba23f8b04b54 (diff) | |
download | bcm5719-llvm-279e3ee954fd41164fd78e4f20ea54a3c53cc5c8.tar.gz bcm5719-llvm-279e3ee954fd41164fd78e4f20ea54a3c53cc5c8.zip |
[GlobalMerge] Look at uses to create smaller global sets.
Instead of merging everything together, look at the users of
GlobalVariables, and try to group them by function, to create
sets of globals used "together".
Using that information, a less-aggressive alternative is to keep merging
everything together *except* globals that are only ever used alone, that
is, those for which it's clearly non-profitable to merge with others.
In my testing, grouping by Function is too aggressive, but grouping by
BasicBlock is too conservative. Anything in-between isn't trivially
available, so stick with Function grouping for now.
cl::opts are added for testing; both enabled by default.
A few of the testcases aren't testing the merging proper, but just
various edge cases when merging does occur. Update them to use the
previous grouping behavior. Also, one of the tests is unrelated to
GlobalMerge; change it accordingly.
While there, switch to r234666' flags rather than the brutal -O3.
Differential Revision: http://reviews.llvm.org/D8070
llvm-svn: 235249
Diffstat (limited to 'llvm/test')
8 files changed, 165 insertions, 8 deletions
diff --git a/llvm/test/CodeGen/AArch64/global-merge-group-by-use.ll b/llvm/test/CodeGen/AArch64/global-merge-group-by-use.ll new file mode 100644 index 00000000000..60a04cbf35d --- /dev/null +++ b/llvm/test/CodeGen/AArch64/global-merge-group-by-use.ll @@ -0,0 +1,94 @@ +; RUN: llc -mtriple=aarch64-apple-ios -asm-verbose=false -aarch64-collect-loh=false \ +; RUN: -aarch64-global-merge -global-merge-group-by-use -global-merge-ignore-single-use=false \ +; RUN: %s -o - | FileCheck %s + +; We assume that globals of the same size aren't reordered inside a set. + +; Check that we create two MergedGlobal instances for two functions using +; disjoint sets of globals + +@m1 = internal global i32 0, align 4 +@n1 = internal global i32 0, align 4 + +; CHECK-LABEL: f1: +define void @f1(i32 %a1, i32 %a2) #0 { +; CHECK-NEXT: adrp x8, [[SET1:__MergedGlobals[0-9]*]]@PAGE +; CHECK-NEXT: add x8, x8, [[SET1]]@PAGEOFF +; CHECK-NEXT: stp w0, w1, [x8] +; CHECK-NEXT: ret + store i32 %a1, i32* @m1, align 4 + store i32 %a2, i32* @n1, align 4 + ret void +} + +@m2 = internal global i32 0, align 4 +@n2 = internal global i32 0, align 4 +@o2 = internal global i32 0, align 4 + +; CHECK-LABEL: f2: +define void @f2(i32 %a1, i32 %a2, i32 %a3) #0 { +; CHECK-NEXT: adrp x8, [[SET2:__MergedGlobals[0-9]*]]@PAGE +; CHECK-NEXT: add x8, x8, [[SET2]]@PAGEOFF +; CHECK-NEXT: stp w0, w1, [x8] +; CHECK-NEXT: str w2, [x8, #8] +; CHECK-NEXT: ret + store i32 %a1, i32* @m2, align 4 + store i32 %a2, i32* @n2, align 4 + store i32 %a3, i32* @o2, align 4 + ret void +} + +; Sanity-check (don't worry about cost models) that we pick the biggest subset +; of all global used "together" directly or indirectly. Here, that means +; merging n3, m4, and n4 together, but ignoring m3. + +@m3 = internal global i32 0, align 4 +@n3 = internal global i32 0, align 4 + +; CHECK-LABEL: f3: +define void @f3(i32 %a1, i32 %a2) #0 { +; CHECK-NEXT: adrp x8, _m3@PAGE +; CHECK-NEXT: adrp x9, [[SET3:__MergedGlobals[0-9]*]]@PAGE +; CHECK-NEXT: str w0, [x8, _m3@PAGEOFF] +; CHECK-NEXT: str w1, [x9, [[SET3]]@PAGEOFF] +; CHECK-NEXT: ret + store i32 %a1, i32* @m3, align 4 + store i32 %a2, i32* @n3, align 4 + ret void +} + +@m4 = internal global i32 0, align 4 +@n4 = internal global i32 0, align 4 + +; CHECK-LABEL: f4: +define void @f4(i32 %a1, i32 %a2, i32 %a3) #0 { +; CHECK-NEXT: adrp x8, [[SET3]]@PAGE +; CHECK-NEXT: add x8, x8, [[SET3]]@PAGEOFF +; CHECK-NEXT: stp w0, w1, [x8, #4] +; CHECK-NEXT: str w2, [x8] +; CHECK-NEXT: ret + store i32 %a1, i32* @m4, align 4 + store i32 %a2, i32* @n4, align 4 + store i32 %a3, i32* @n3, align 4 + ret void +} + +; Finally, check that we don't do anything with one-element global sets. +@o5 = internal global i32 0, align 4 + +; CHECK-LABEL: f5: +define void @f5(i32 %a1) #0 { +; CHECK-NEXT: adrp x8, _o5@PAGE +; CHECK-NEXT: str w0, [x8, _o5@PAGEOFF] +; CHECK-NEXT: ret + store i32 %a1, i32* @o5, align 4 + ret void +} + +; 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 + +attributes #0 = { nounwind } diff --git a/llvm/test/CodeGen/AArch64/global-merge-ignore-single-use.ll b/llvm/test/CodeGen/AArch64/global-merge-ignore-single-use.ll new file mode 100644 index 00000000000..e6de4699132 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/global-merge-ignore-single-use.ll @@ -0,0 +1,63 @@ +; RUN: llc -mtriple=aarch64-apple-ios -asm-verbose=false -aarch64-collect-loh=false \ +; RUN: -aarch64-global-merge -global-merge-group-by-use -global-merge-ignore-single-use \ +; RUN: %s -o - | FileCheck %s + +; We assume that globals of the same size aren't reordered inside a set. + +@m1 = internal global i32 0, align 4 +@n1 = internal global i32 0, align 4 +@o1 = internal global i32 0, align 4 + +; CHECK-LABEL: f1: +define void @f1(i32 %a1, i32 %a2) #0 { +; CHECK-NEXT: adrp x8, [[SET:__MergedGlobals]]@PAGE +; CHECK-NEXT: add x8, x8, [[SET]]@PAGEOFF +; CHECK-NEXT: stp w0, w1, [x8] +; CHECK-NEXT: ret + store i32 %a1, i32* @m1, align 4 + store i32 %a2, i32* @n1, align 4 + ret void +} + +@m2 = internal global i32 0, align 4 +@n2 = internal global i32 0, align 4 + +; CHECK-LABEL: f2: +define void @f2(i32 %a1, i32 %a2, i32 %a3) #0 { +; CHECK-NEXT: adrp x8, [[SET]]@PAGE +; CHECK-NEXT: add x8, x8, [[SET]]@PAGEOFF +; CHECK-NEXT: stp w0, w1, [x8] +; CHECK-NEXT: str w2, [x8, #8] +; CHECK-NEXT: ret + store i32 %a1, i32* @m1, align 4 + store i32 %a2, i32* @n1, align 4 + store i32 %a3, i32* @o1, align 4 + ret void +} + +; CHECK-LABEL: f3: +define void @f3(i32 %a1, i32 %a2) #0 { +; CHECK-NEXT: adrp x8, [[SET]]@PAGE +; CHECK-NEXT: add x8, x8, [[SET]]@PAGEOFF +; CHECK-NEXT: stp w0, w1, [x8, #12] +; CHECK-NEXT: ret + store i32 %a1, i32* @m2, align 4 + store i32 %a2, i32* @n2, align 4 + ret void +} + +@o2 = internal global i32 0, align 4 + +; CHECK-LABEL: f4: +define void @f4(i32 %a1) #0 { +; CHECK-NEXT: adrp x8, _o2@PAGE +; CHECK-NEXT: str w0, [x8, _o2@PAGEOFF] +; CHECK-NEXT: ret + store i32 %a1, i32* @o2, align 4 + ret void +} + +; CHECK-DAG: .zerofill __DATA,__bss,[[SET]],20,4 +; CHECK-DAG: .zerofill __DATA,__bss,_o2,4,2 + +attributes #0 = { nounwind } diff --git a/llvm/test/CodeGen/ARM/2010-12-15-elf-lcomm.ll b/llvm/test/CodeGen/ARM/2010-12-15-elf-lcomm.ll index cb91890a9fd..f04e053b2e0 100644 --- a/llvm/test/CodeGen/ARM/2010-12-15-elf-lcomm.ll +++ b/llvm/test/CodeGen/ARM/2010-12-15-elf-lcomm.ll @@ -1,6 +1,6 @@ -; RUN: llc %s -mtriple=armv7-linux-gnueabi -O3 -filetype=obj -o - | \ +; RUN: llc %s -mtriple=armv7-linux-gnueabi -filetype=obj -o - | \ ; RUN: llvm-readobj -s -t | FileCheck -check-prefix=OBJ %s -; RUN: llc %s -mtriple=armv7-linux-gnueabi -O3 -o - | \ +; RUN: llc %s -mtriple=armv7-linux-gnueabi -o - | \ ; RUN: FileCheck -check-prefix=ASM %s @@ -12,7 +12,7 @@ ; ASM: .type array00,%object @ @array00 ; ASM-NEXT: .local array00 ; ASM-NEXT: .comm array00,80,1 -; ASM-NEXT: .type _MergedGlobals,%object @ @_MergedGlobals +; ASM-NEXT: .type sum,%object @ @sum ; OBJ: Symbols [ diff --git a/llvm/test/CodeGen/ARM/2011-01-19-MergedGlobalDbg.ll b/llvm/test/CodeGen/ARM/2011-01-19-MergedGlobalDbg.ll index 7196d2d37bd..b490d329a44 100644 --- a/llvm/test/CodeGen/ARM/2011-01-19-MergedGlobalDbg.ll +++ b/llvm/test/CodeGen/ARM/2011-01-19-MergedGlobalDbg.ll @@ -1,4 +1,4 @@ -; RUN: llc -O3 -filetype=obj < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s +; RUN: llc -arm-global-merge -global-merge-group-by-use=false -filetype=obj < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s 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" target triple = "thumbv7-apple-darwin10" diff --git a/llvm/test/CodeGen/ARM/2011-06-29-MergeGlobalsAlign.ll b/llvm/test/CodeGen/ARM/2011-06-29-MergeGlobalsAlign.ll index 236dc1c0dbc..aac8f7b3a02 100644 --- a/llvm/test/CodeGen/ARM/2011-06-29-MergeGlobalsAlign.ll +++ b/llvm/test/CodeGen/ARM/2011-06-29-MergeGlobalsAlign.ll @@ -1,4 +1,4 @@ -; RUN: llc < %s -mtriple=thumbv7-apple-darwin10 -O3 | FileCheck %s +; RUN: llc < %s -mtriple=thumbv7-apple-darwin10 -arm-global-merge -global-merge-group-by-use=false | FileCheck %s ; CHECK: .zerofill __DATA,__bss,__MergedGlobals,16,2 @prev = external global [0 x i16] diff --git a/llvm/test/CodeGen/ARM/2011-08-02-MergedGlobalDbg.ll b/llvm/test/CodeGen/ARM/2011-08-02-MergedGlobalDbg.ll index 1614e8d0c67..37f6b69e762 100644 --- a/llvm/test/CodeGen/ARM/2011-08-02-MergedGlobalDbg.ll +++ b/llvm/test/CodeGen/ARM/2011-08-02-MergedGlobalDbg.ll @@ -1,4 +1,4 @@ -; RUN: llc -O3 -filetype=obj < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s +; RUN: llc -arm-global-merge -global-merge-group-by-use=false -filetype=obj < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s ; Check debug info output for merged global. ; DW_AT_location diff --git a/llvm/test/CodeGen/ARM/global-merge-addrspace.ll b/llvm/test/CodeGen/ARM/global-merge-addrspace.ll index 7b71e89bbe7..73a3afb7e4e 100644 --- a/llvm/test/CodeGen/ARM/global-merge-addrspace.ll +++ b/llvm/test/CodeGen/ARM/global-merge-addrspace.ll @@ -1,4 +1,4 @@ -; RUN: llc < %s -mtriple=thumb-apple-darwin -O3 | FileCheck %s +; RUN: llc < %s -mtriple=thumb-apple-darwin -arm-global-merge -global-merge-group-by-use=false | FileCheck %s ; Test the GlobalMerge pass. Check that the pass does not crash when using ; multiple address spaces. diff --git a/llvm/test/CodeGen/ARM/global-merge.ll b/llvm/test/CodeGen/ARM/global-merge.ll index d535ea7c0ce..22bbe87784e 100644 --- a/llvm/test/CodeGen/ARM/global-merge.ll +++ b/llvm/test/CodeGen/ARM/global-merge.ll @@ -1,4 +1,4 @@ -; RUN: llc < %s -mtriple=thumb-apple-darwin -O3 -global-merge-on-const=true | FileCheck %s +; RUN: llc < %s -mtriple=thumb-apple-darwin -arm-global-merge -global-merge-group-by-use=false -global-merge-on-const=true | FileCheck %s ; Test the ARMGlobalMerge pass. Use -march=thumb because it has a small ; value for the maximum offset (127). |