llvm.org GIT mirror llvm / 838b97e
Do not add PHIs with no users when creating LCSSA form. Patch by Andrew Clinton. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127674 91177308-0d34-0410-b5e6-96231b3b80d8 Cameron Zwarich 8 years ago
3 changed file(s) with 48 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
206206
207207 DomTreeNode *DomNode = DT->getNode(DomBB);
208208
209 SmallVector AddedPHIs;
210
209211 SSAUpdater SSAUpdate;
210212 SSAUpdate.Initialize(Inst->getType(), Inst->getName());
211213
235237 &PN->getOperandUse(
236238 PN->getOperandNumForIncomingValue(PN->getNumIncomingValues()-1)));
237239 }
240
241 AddedPHIs.push_back(PN);
238242
239243 // Remember that this phi makes the value alive in this block.
240244 SSAUpdate.AddAvailableValue(ExitBB, PN);
261265 // Otherwise, do full PHI insertion.
262266 SSAUpdate.RewriteUse(*UsesToRewrite[i]);
263267 }
268
269 // Remove PHI nodes that did not have any uses rewritten.
270 for (unsigned i = 0, e = AddedPHIs.size(); i != e; ++i) {
271 if (!AddedPHIs[i]->hasNUsesOrMore(1))
272 AddedPHIs[i]->eraseFromParent();
273 }
264274
265275 return true;
266276 }
0 ; RUN: opt < %s -loop-simplify -lcssa -S | \
11 ; RUN: grep {%%SJE.0.0.lcssa = phi .struct.SetJmpMapEntry}
2 ; RUN: opt < %s -loop-simplify -lcssa -S | \
3 ; RUN: grep {%%SJE.0.0.lcssa1 = phi .struct.SetJmpMapEntry}
42
53 %struct.SetJmpMapEntry = type { i8*, i32, %struct.SetJmpMapEntry* }
64
0 ; RUN: opt < %s -lcssa -S | FileCheck %s
1 ; CHECK: exit1:
2 ; CHECK: .lcssa =
3 ; CHECK: exit2:
4 ; CHECK: .lcssa2 =
5 ; CHECK: exit3:
6 ; CHECK-NOT: .lcssa1 =
7
8 ; Test to ensure that when there are multiple exit blocks, PHI nodes are
9 ; only inserted by LCSSA when there is a use dominated by a given exit
10 ; block.
11
12 declare void @printf(i32 %i)
13
14 define i32 @unused_phis() nounwind {
15 entry:
16 br label %loop
17
18 loop:
19 %i = phi i32 [0, %entry], [1, %then2]
20 br i1 undef, label %exit1, label %then1
21
22 then1:
23 br i1 undef, label %exit2, label %then2
24
25 then2:
26 br i1 undef, label %exit3, label %loop
27
28 exit1:
29 call void @printf(i32 %i)
30 ret i32 %i
31
32 exit2:
33 ret i32 %i
34
35 exit3:
36 ret i32 0
37 }