diff options
author | Haicheng Wu <haicheng@codeaurora.org> | 2018-05-19 18:00:02 +0000 |
---|---|---|
committer | Haicheng Wu <haicheng@codeaurora.org> | 2018-05-19 18:00:02 +0000 |
commit | 69ba0613f2b9ae20fc00fc547fd125d52629d5a6 (patch) | |
tree | a12a88faf0947c93cc6ce5f2d3b6c9ee2ff367a4 | |
parent | 9968e0dd4975d3939e7810ac9e6c52cea7f1aeb1 (diff) | |
download | bcm5719-llvm-69ba0613f2b9ae20fc00fc547fd125d52629d5a6.tar.gz bcm5719-llvm-69ba0613f2b9ae20fc00fc547fd125d52629d5a6.zip |
[GlobalMerge] Exit early if only one global is to be merged
To save some compilation time and prevent some unnecessary changes.
Differential Revision: https://reviews.llvm.org/D46640
llvm-svn: 332813
-rw-r--r-- | llvm/lib/CodeGen/GlobalMerge.cpp | 10 | ||||
-rw-r--r-- | llvm/test/CodeGen/AArch64/global-merge-3.ll | 14 | ||||
-rw-r--r-- | llvm/test/CodeGen/ARM/global-merge.ll | 8 |
3 files changed, 16 insertions, 16 deletions
diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp index cda5861f676..fbf94d2bb7f 100644 --- a/llvm/lib/CodeGen/GlobalMerge.cpp +++ b/llvm/lib/CodeGen/GlobalMerge.cpp @@ -445,6 +445,7 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals, LLVM_DEBUG(dbgs() << " Trying to merge set, starts with #" << GlobalSet.find_first() << "\n"); + bool Changed = false; ssize_t i = GlobalSet.find_first(); while (i != -1) { ssize_t j = 0; @@ -469,6 +470,12 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals, } } + // Exit early if there is only one global to merge. + if (Tys.size() < 2) { + i = j; + continue; + } + // If merged variables doesn't have external linkage, we needn't to expose // the symbol after merging. GlobalValue::LinkageTypes Linkage = HasExternal @@ -526,10 +533,11 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals, NumMerged++; } + Changed = true; i = j; } - return true; + return Changed; } void GlobalMerge::collectUsedGlobalVariables(Module &M) { diff --git a/llvm/test/CodeGen/AArch64/global-merge-3.ll b/llvm/test/CodeGen/AArch64/global-merge-3.ll index 4844d9622fe..d37dd863c79 100644 --- a/llvm/test/CodeGen/AArch64/global-merge-3.ll +++ b/llvm/test/CodeGen/AArch64/global-merge-3.ll @@ -10,8 +10,8 @@ define void @f1(i32 %a1, i32 %a2, i32 %a3) { ;CHECK-APPLE-IOS: adrp x8, __MergedGlobals_x@PAGE ;CHECK-APPLE-IOS-NOT: adrp ;CHECK-APPLE-IOS: add x8, x8, __MergedGlobals_x@PAGEOFF -;CHECK-APPLE-IOS: adrp x9, __MergedGlobals_y@PAGE+12 -;CHECK-APPLE-IOS: str w1, [x9, __MergedGlobals_y@PAGEOFF+12] +;CHECK-APPLE-IOS: adrp x9, _y@PAGE+12 +;CHECK-APPLE-IOS: str w1, [x9] %x3 = getelementptr inbounds [1000 x i32], [1000 x i32]* @x, i32 0, i64 3 %y3 = getelementptr inbounds [1000 x i32], [1000 x i32]* @y, i32 0, i64 3 store i32 %a1, i32* %x3, align 4 @@ -25,27 +25,19 @@ define void @f1(i32 %a1, i32 %a2, i32 %a3) { ;CHECK: .L_MergedGlobals: ;CHECK: .size .L_MergedGlobals, 4004 -;CHECK: .type .L_MergedGlobals.1,@object // @_MergedGlobals.1 -;CHECK: .local .L_MergedGlobals.1 -;CHECK: .comm .L_MergedGlobals.1,4000,16 +;CHECK-APPLE-IOS: .zerofill __DATA,__common,_y,4000,2 ;CHECK-APPLE-IOS: .p2align 4 ;CHECK-APPLE-IOS: __MergedGlobals_x: ;CHECK-APPLE-IOS: .long 1 ;CHECK-APPLE-IOS: .space 4000 -;CHECK-APPLE-IOS: .zerofill __DATA,__common,__MergedGlobals_y,4000,4 ;CHECK: .set z, .L_MergedGlobals ;CHECK: .globl x ;CHECK: .set x, .L_MergedGlobals+4 ;CHECK: .size x, 4000 -;CHECK: .globl y -;CHECK: .set y, .L_MergedGlobals.1 -;CHECK: .size y, 4000 ;CHECK-APPLE-IOS-NOT: .set _z, __MergedGlobals_x ;CHECK-APPLE-IOS:.globl _x ;CHECK-APPLE-IOS:.set _x, __MergedGlobals_x+4 -;CHECK-APPLE-IOS:.globl _y -;CHECK-APPLE-IOS:.set _y, __MergedGlobals_y diff --git a/llvm/test/CodeGen/ARM/global-merge.ll b/llvm/test/CodeGen/ARM/global-merge.ll index 9b41e709f2f..f19be03f302 100644 --- a/llvm/test/CodeGen/ARM/global-merge.ll +++ b/llvm/test/CodeGen/ARM/global-merge.ll @@ -52,23 +52,23 @@ declare i8* @__cxa_begin_catch(i8*) declare void @__cxa_end_catch() +; CHECK: g3: ; CHECK: _MergedGlobals: @g1 = internal global i32 1 @g2 = internal global i32 2 ; Make sure that the complete variable fits within the range of the maximum ; offset. Having the starting offset in range is not sufficient. -; When this works properly, @g3 is placed in a separate chunk of merged globals. -; CHECK: _MergedGlobals.1: +; When this works properly, @g3 is not merged. @g3 = internal global [30 x i32] [ i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10 ], align 4 ; Global variables that can be placed in BSS should be kept together in a ; separate pool of merged globals. -; CHECK: _MergedGlobals.2 +; CHECK: _MergedGlobals.1 @g4 = internal global i32 0 @g5 = internal global i32 0 ; Global variables that are constant can be merged together -; CHECK: _MergedGlobals.3 +; CHECK: _MergedGlobals.2 @g6 = internal constant [12 x i32] zeroinitializer, align 4 @g7 = internal constant [12 x i32] zeroinitializer, align 4 |