llvm.org GIT mirror llvm / f143b79
LSR should avoid redundant edge splitting. This handles the case in which LSR rewrites an IV user that is a phi and splits critical edges originating from a switch. Fixes <rdar://problem/6453893> LSR is not splitting edges "nicely" git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141059 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Trick 8 years ago
4 changed file(s) with 55 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
108108 /// to.
109109 ///
110110 BasicBlock *SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
111 Pass *P = 0, bool MergeIdenticalEdges = false);
111 Pass *P = 0, bool MergeIdenticalEdges = false,
112 bool DontDeleteUselessPHIs = false);
112113
113114 inline BasicBlock *SplitCriticalEdge(BasicBlock *BB, succ_iterator SI,
114115 Pass *P = 0) {
135136 /// described above.
136137 inline BasicBlock *SplitCriticalEdge(BasicBlock *Src, BasicBlock *Dst,
137138 Pass *P = 0,
138 bool MergeIdenticalEdges = false) {
139 bool MergeIdenticalEdges = false,
140 bool DontDeleteUselessPHIs = false) {
139141 TerminatorInst *TI = Src->getTerminator();
140142 unsigned i = 0;
141143 while (1) {
142144 assert(i != TI->getNumSuccessors() && "Edge doesn't exist!");
143145 if (TI->getSuccessor(i) == Dst)
144 return SplitCriticalEdge(TI, i, P, MergeIdenticalEdges);
146 return SplitCriticalEdge(TI, i, P, MergeIdenticalEdges,
147 DontDeleteUselessPHIs);
145148 ++i;
146149 }
147150 }
36763676 // Split the critical edge.
36773677 BasicBlock *NewBB = 0;
36783678 if (!Parent->isLandingPad()) {
3679 NewBB = SplitCriticalEdge(BB, Parent, P);
3679 NewBB = SplitCriticalEdge(BB, Parent, P,
3680 /*MergeIdenticalEdges=*/true,
3681 /*DontDeleteUselessPhis=*/true);
36803682 } else {
36813683 SmallVector NewBBs;
36823684 SplitLandingPadPredecessors(Parent, BB, "", "", P, NewBBs);
166166 /// to.
167167 ///
168168 BasicBlock *llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
169 Pass *P, bool MergeIdenticalEdges) {
169 Pass *P, bool MergeIdenticalEdges,
170 bool DontDeleteUselessPhis) {
170171 if (!isCriticalEdge(TI, SuccNum, MergeIdenticalEdges)) return 0;
171172
172173 assert(!isa(TI) &&
223224 if (TI->getSuccessor(i) != DestBB) continue;
224225
225226 // Remove an entry for TIBB from DestBB phi nodes.
226 DestBB->removePredecessor(TIBB);
227 DestBB->removePredecessor(TIBB, DontDeleteUselessPhis);
227228
228229 // We found another edge to DestBB, go to NewBB instead.
229230 TI->setSuccessor(i, NewBB);
0 ; RUN: opt -loop-reduce -S < %s | FileCheck %s
1 ;
2 ; Test LSR's use of SplitCriticalEdge during phi rewriting.
3 ; Verify that identical edges are merged. rdar://problem/6453893
4
5 target triple = "x86-apple-darwin"
6
7 ; CHECK: @test
8 ; CHECK: bb89:
9 ; CHECK: phi i8* [ %lsr.iv.next1, %bbA.bb89_crit_edge ], [ %lsr.iv.next1, %bbB.bb89_crit_edge ]{{$}}
10
11 define i8* @test() {
12 entry:
13 br label %loop
14
15 loop:
16 %rec = phi i32 [ %next, %loop ], [ 0, %entry ]
17 %next = add i32 %rec, 1
18 %tmp75 = getelementptr i8* null, i32 %next
19 br i1 false, label %loop, label %loopexit
20
21 loopexit:
22 br i1 false, label %bbA, label %bbB
23
24 bbA:
25 switch i32 0, label %bb89 [
26 i32 47, label %bb89
27 i32 58, label %bb89
28 ]
29
30 bbB:
31 switch i8 0, label %bb89 [
32 i8 47, label %bb89
33 i8 58, label %bb89
34 ]
35
36 bb89:
37 %tmp75phi = phi i8* [ %tmp75, %bbA ], [ %tmp75, %bbA ], [ %tmp75, %bbA ], [ %tmp75, %bbB ], [ %tmp75, %bbB ], [ %tmp75, %bbB ]
38 br label %exit
39
40 exit:
41 ret i8* %tmp75phi
42 }