[llvm] r332813 - [GlobalMerge] Exit early if only one global is to be merged
Haicheng Wu via llvm-commits
llvm-commits at lists.llvm.org
Sat May 19 11:00:03 PDT 2018
Author: haicheng
Date: Sat May 19 11:00:02 2018
New Revision: 332813
URL: http://llvm.org/viewvc/llvm-project?rev=332813&view=rev
Log:
[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
Modified:
llvm/trunk/lib/CodeGen/GlobalMerge.cpp
llvm/trunk/test/CodeGen/AArch64/global-merge-3.ll
llvm/trunk/test/CodeGen/ARM/global-merge.ll
Modified: llvm/trunk/lib/CodeGen/GlobalMerge.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalMerge.cpp?rev=332813&r1=332812&r2=332813&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalMerge.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalMerge.cpp Sat May 19 11:00:02 2018
@@ -445,6 +445,7 @@ bool GlobalMerge::doMerge(const SmallVec
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 SmallVec
}
}
+ // 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 SmallVec
NumMerged++;
}
+ Changed = true;
i = j;
}
- return true;
+ return Changed;
}
void GlobalMerge::collectUsedGlobalVariables(Module &M) {
Modified: llvm/trunk/test/CodeGen/AArch64/global-merge-3.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/global-merge-3.ll?rev=332813&r1=332812&r2=332813&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/global-merge-3.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/global-merge-3.ll Sat May 19 11:00:02 2018
@@ -10,8 +10,8 @@ define void @f1(i32 %a1, i32 %a2, i32 %a
;CHECK-APPLE-IOS: adrp x8, __MergedGlobals_x at PAGE
;CHECK-APPLE-IOS-NOT: adrp
;CHECK-APPLE-IOS: add x8, x8, __MergedGlobals_x at PAGEOFF
-;CHECK-APPLE-IOS: adrp x9, __MergedGlobals_y at PAGE+12
-;CHECK-APPLE-IOS: str w1, [x9, __MergedGlobals_y at PAGEOFF+12]
+;CHECK-APPLE-IOS: adrp x9, _y at 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 %a
;CHECK: .L_MergedGlobals:
;CHECK: .size .L_MergedGlobals, 4004
-;CHECK: .type .L_MergedGlobals.1, at 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
Modified: llvm/trunk/test/CodeGen/ARM/global-merge.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/global-merge.ll?rev=332813&r1=332812&r2=332813&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/global-merge.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/global-merge.ll Sat May 19 11:00:02 2018
@@ -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
More information about the llvm-commits
mailing list