Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 68e99ab

Browse files
committed
[MemorySSA] When applying updates, clean unnecessary Phis.
Summary: After applying a set of insert updates, there may be trivial Phis left over. Clean them up. Reviewers: george.burgess.iv Subscribers: jlebar, Prazek, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63033 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363094 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 80956de commit 68e99ab

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

lib/Analysis/MemorySSAUpdater.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,13 +860,14 @@ void MemorySSAUpdater::applyInsertUpdates(ArrayRef<CFGUpdate> Updates,
860860

861861
SmallVector<BasicBlock *, 8> BlocksToProcess;
862862
SmallVector<BasicBlock *, 16> BlocksWithDefsToReplace;
863+
SmallVector<WeakVH, 8> InsertedPhis;
863864

864865
// First create MemoryPhis in all blocks that don't have one. Create in the
865866
// order found in Updates, not in PredMap, to get deterministic numbering.
866867
for (auto &Edge : Updates) {
867868
BasicBlock *BB = Edge.getTo();
868869
if (PredMap.count(BB) && !MSSA->getMemoryAccess(BB))
869-
MSSA->createMemoryPhi(BB);
870+
InsertedPhis.push_back(MSSA->createMemoryPhi(BB));
870871
}
871872

872873
// Now we'll fill in the MemoryPhis with the right incoming values.
@@ -967,6 +968,7 @@ void MemorySSAUpdater::applyInsertUpdates(ArrayRef<CFGUpdate> Updates,
967968
IDFPhi->setIncomingValue(I, GetLastDef(IDFPhi->getIncomingBlock(I)));
968969
} else {
969970
IDFPhi = MSSA->createMemoryPhi(BBIDF);
971+
InsertedPhis.push_back(IDFPhi);
970972
for (auto &Pair : children<GraphDiffInvBBPair>({GD, BBIDF})) {
971973
BasicBlock *Pi = Pair.second;
972974
IDFPhi->addIncoming(GetLastDef(Pi), Pi);
@@ -1009,6 +1011,7 @@ void MemorySSAUpdater::applyInsertUpdates(ArrayRef<CFGUpdate> Updates,
10091011
}
10101012
}
10111013
}
1014+
tryRemoveTrivialPhis(InsertedPhis);
10121015
}
10131016

10141017
// Move What before Where in the MemorySSA IR.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
; RUN: opt -loop-rotate -print-memoryssa -disable-output -enable-mssa-loop-dependency -verify-memoryssa %s 2>&1 | FileCheck %s
2+
; REQUIRES: asserts
3+
4+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5+
target triple = "x86_64-grtev4-linux-gnu"
6+
7+
declare double @sqrt(double)
8+
9+
; CHECK-LABEL: @f
10+
define internal fastcc double @f(i32* %n_, double* %dx) align 32 {
11+
entry:
12+
; CHECK: entry:
13+
; CHECK: MemoryUse(liveOnEntry)
14+
; CHECK-NOT: 7 = MemoryPhi
15+
; CHECK-NOT: 6 = MemoryPhi
16+
%v0 = load i32, i32* %n_, align 4
17+
br label %for.cond
18+
19+
for.cond: ; preds = %for.body, %entry
20+
%xmax.0 = phi double [ undef, %entry ], [ %xmax.1, %for.body ]
21+
%i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
22+
%cmp = icmp slt i32 %i.0, %v0
23+
br i1 %cmp, label %for.body, label %for.end
24+
25+
for.body: ; preds = %for.cond
26+
%idxprom = zext i32 %i.0 to i64
27+
%arrayidx = getelementptr inbounds double, double* %dx, i64 %idxprom
28+
%v1 = load double, double* %arrayidx, align 8
29+
%cmp1 = fcmp ueq double %v1, 0.000000e+00
30+
%xmax.1 = select i1 %cmp1, double %xmax.0, double %v1
31+
%inc = add nuw nsw i32 %i.0, 1
32+
br label %for.cond
33+
34+
for.end: ; preds = %for.cond
35+
%xmax.0.lcssa = phi double [ %xmax.0, %for.cond ]
36+
%cmp2 = fcmp oeq double %xmax.0.lcssa, 0.000000e+00
37+
br i1 %cmp2, label %cleanup, label %if.end4
38+
39+
if.end4: ; preds = %for.end
40+
%div = fdiv double 1.000000e+00, %xmax.0.lcssa
41+
%cmp61 = icmp slt i32 0, %v0
42+
br i1 %cmp61, label %for.body7.lr.ph, label %for.end15
43+
44+
for.body7.lr.ph: ; preds = %if.end4
45+
br label %for.body7
46+
47+
; CHECK: for.body7:
48+
; CHECK: 3 = MemoryPhi({for.body7.lr.ph,liveOnEntry},{for.body7,1})
49+
for.body7: ; preds = %for.body7.lr.ph, %for.body7
50+
%i.13 = phi i32 [ 0, %for.body7.lr.ph ], [ %inc14, %for.body7 ]
51+
%sum.02 = phi x86_fp80 [ undef, %for.body7.lr.ph ], [ %add, %for.body7 ]
52+
%idxprom9 = zext i32 %i.13 to i64
53+
%arrayidx10 = getelementptr inbounds double, double* %dx, i64 %idxprom9
54+
%v3 = load double, double* %arrayidx10, align 8
55+
%mul11 = fmul double %div, %v3
56+
%v2 = call double @sqrt(double %v3)
57+
%mul12 = fmul double %mul11, %v2
58+
%conv = fpext double %mul12 to x86_fp80
59+
%add = fadd x86_fp80 %sum.02, %conv
60+
%inc14 = add nuw nsw i32 %i.13, 1
61+
%cmp6 = icmp slt i32 %inc14, %v0
62+
br i1 %cmp6, label %for.body7, label %for.cond5.for.end15_crit_edge
63+
64+
for.cond5.for.end15_crit_edge: ; preds = %for.body7
65+
%split = phi x86_fp80 [ %add, %for.body7 ]
66+
br label %for.end15
67+
68+
for.end15: ; preds = %for.cond5.for.end15_crit_edge, %if.end4
69+
%sum.0.lcssa = phi x86_fp80 [ %split, %for.cond5.for.end15_crit_edge ], [ undef, %if.end4 ]
70+
%conv16 = fptrunc x86_fp80 %sum.0.lcssa to double
71+
%call = call double @sqrt(double %conv16)
72+
%mul17 = fmul double %call, 0.000000e+00
73+
br label %cleanup
74+
75+
cleanup: ; preds = %for.end15, %for.end
76+
%retval.0 = phi double [ undef, %for.end ], [ %mul17, %for.end15 ]
77+
ret double %retval.0
78+
}

0 commit comments

Comments
 (0)