llvm.org GIT mirror llvm / 90a4067
Merging r296642: ------------------------------------------------------------------------ r296642 | hans | 2017-03-01 09:15:08 -0800 (Wed, 01 Mar 2017) | 5 lines [GVNHoist] Don't hoist unsafe scalars at -Oz (PR31729) Based on Aditya Kumar's patch: Differential Revision: https://reviews.llvm.org/D29092 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_40@296761 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 2 years ago
2 changed file(s) with 90 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
199199 class GVNHoist {
200200 public:
201201 GVNHoist(DominatorTree *DT, AliasAnalysis *AA, MemoryDependenceResults *MD,
202 MemorySSA *MSSA, bool OptForMinSize)
203 : DT(DT), AA(AA), MD(MD), MSSA(MSSA), OptForMinSize(OptForMinSize),
204 HoistingGeps(OptForMinSize), HoistedCtr(0) {
205 // Hoist as far as possible when optimizing for code-size.
206 if (OptForMinSize)
207 MaxNumberOfBBSInPath = -1;
208 }
202 MemorySSA *MSSA)
203 : DT(DT), AA(AA), MD(MD), MSSA(MSSA),
204 HoistingGeps(false),
205 HoistedCtr(0)
206 { }
209207
210208 bool run(Function &F) {
211209 VN.setDomTree(DT);
250248 AliasAnalysis *AA;
251249 MemoryDependenceResults *MD;
252250 MemorySSA *MSSA;
253 const bool OptForMinSize;
254251 const bool HoistingGeps;
255252 DenseMap DFSNumber;
256253 BBSideEffectsSet BBSideEffects;
504501 bool safeToHoistScalar(const BasicBlock *HoistBB,
505502 SmallPtrSetImpl &WL,
506503 int &NBBsOnAllPaths) {
507 // Enable scalar hoisting at -Oz as it is safe to hoist scalars to a place
508 // where they are partially needed.
509 if (OptForMinSize)
510 return true;
511
512504 // Check that the hoisted expression is needed on all paths.
513505 if (!hoistingFromAllPaths(HoistBB, WL))
514506 return false;
922914 Intr->getIntrinsicID() == Intrinsic::assume)
923915 continue;
924916 }
925 if (Call->mayHaveSideEffects()) {
926 if (!OptForMinSize)
927 break;
928 // We may continue hoisting across calls which write to memory.
929 if (Call->mayThrow())
930 break;
931 }
917 if (Call->mayHaveSideEffects())
918 break;
932919
933920 if (Call->isConvergent())
934921 break;
970957 auto &MD = getAnalysis().getMemDep();
971958 auto &MSSA = getAnalysis().getMSSA();
972959
973 GVNHoist G(&DT, &AA, &MD, &MSSA, F.optForMinSize());
960 GVNHoist G(&DT, &AA, &MD, &MSSA);
974961 return G.run(F);
975962 }
976963
990977 AliasAnalysis &AA = AM.getResult(F);
991978 MemoryDependenceResults &MD = AM.getResult(F);
992979 MemorySSA &MSSA = AM.getResult(F).getMSSA();
993 GVNHoist G(&DT, &AA, &MD, &MSSA, F.optForMinSize());
980 GVNHoist G(&DT, &AA, &MD, &MSSA);
994981 if (!G.run(F))
995982 return PreservedAnalyses::all();
996983
0 ; RUN: opt -gvn-hoist -S < %s | FileCheck %s
1
2 ; Check that urem is not hoisted.
3 ; CHECK-LABEL: @main
4 ; CHECK: urem
5 ; CHECK: urem
6 ; CHECK: urem
7
8 @g_x_s = global i32 -470211272, align 4
9 @g_z_s = global i32 2007237709, align 4
10 @g_x_u = global i32 282475249, align 4
11 @g_z_u = global i32 984943658, align 4
12 @g_m = global i32 16807, align 4
13 @res = common global i32 0, align 4
14
15 ; Function Attrs:
16 define i64 @func() #0 {
17 entry:
18 ret i64 1
19 }
20
21 ; Function Attrs:
22 define i32 @main() {
23 entry:
24 %0 = load volatile i32, i32* @g_x_s, align 4
25 %1 = load volatile i32, i32* @g_z_s, align 4
26 %2 = load volatile i32, i32* @g_x_u, align 4
27 %3 = load volatile i32, i32* @g_z_u, align 4
28 %4 = load volatile i32, i32* @g_m, align 4
29 %call = call i64 @func() #4
30 %conv = sext i32 %1 to i64
31 %cmp = icmp ne i64 %call, %conv
32 br i1 %cmp, label %if.end, label %lor.lhs.false
33
34 lor.lhs.false:
35 %div = udiv i32 %4, %1
36 %rem = urem i32 %0, %div
37 %cmp2 = icmp eq i32 %rem, 0
38 br i1 %cmp2, label %if.end, label %if.then
39
40 if.then:
41 br label %cleanup
42
43 if.end:
44 %call4 = call i64 @func() #4
45 %conv5 = zext i32 %3 to i64
46 %cmp6 = icmp ne i64 %call4, %conv5
47 br i1 %cmp6, label %if.end14, label %lor.lhs.false8
48
49 lor.lhs.false8:
50 %div9 = udiv i32 %4, %3
51 %rem10 = urem i32 %0, %div9
52 %cmp11 = icmp eq i32 %rem10, 0
53 br i1 %cmp11, label %if.end14, label %if.then13
54
55 if.then13:
56 br label %cleanup
57
58 if.end14:
59 %call15 = call i64 @func() #4
60 %cmp17 = icmp ne i64 %call15, %conv
61 br i1 %cmp17, label %if.end25, label %lor.lhs.false19
62
63 lor.lhs.false19:
64 %div20 = udiv i32 %4, %1
65 %rem21 = urem i32 %0, %div20
66 %cmp22 = icmp eq i32 %rem21, 0
67 br i1 %cmp22, label %if.end25, label %if.then24
68
69 if.then24:
70 br label %cleanup
71
72 if.end25:
73 br label %cleanup
74
75 cleanup:
76 %retval.0 = phi i32 [ 0, %if.end25 ], [ 1, %if.then24 ], [ 1, %if.then13 ], [ 1, %if.then ]
77 ret i32 %retval.0
78 }
79
80 attributes #0 = { minsize noinline nounwind optsize uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }