llvm.org GIT mirror llvm / 458cf3e
Merging r155817: ------------------------------------------------------------------------ r155817 | void | 2012-04-30 03:44:54 -0700 (Mon, 30 Apr 2012) | 9 lines Second attempt at PR12573: Allow the "SplitCriticalEdge" function to split the edge to a landing pad. If the pass is *sure* that it thinks it knows what it's doing, then it may go ahead and specify that the landing pad can have its critical edge split. The loop unswitch pass is one of these passes. It will split the critical edges of all edges coming from a loop to a landing pad not within the loop. Doing so will retain important loop analysis information, such as loop simplify. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_31@155833 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 7 years ago
4 changed file(s) with 132 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
109109 ///
110110 BasicBlock *SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
111111 Pass *P = 0, bool MergeIdenticalEdges = false,
112 bool DontDeleteUselessPHIs = false);
112 bool DontDeleteUselessPHIs = false,
113 bool SplitLandingPads = false);
113114
114115 inline BasicBlock *SplitCriticalEdge(BasicBlock *BB, succ_iterator SI,
115116 Pass *P = 0) {
686686
687687 // If either edge is critical, split it. This helps preserve LoopSimplify
688688 // form for enclosing loops.
689 SplitCriticalEdge(BI, 0, this);
690 SplitCriticalEdge(BI, 1, this);
689 SplitCriticalEdge(BI, 0, this, false, false, true);
690 SplitCriticalEdge(BI, 1, this, false, false, true);
691691 }
692692
693693 /// UnswitchTrivialCondition - Given a loop that has a trivial unswitchable
118118
119119 /// CreatePHIsForSplitLoopExit - When a loop exit edge is split, LCSSA form
120120 /// may require new PHIs in the new exit block. This function inserts the
121 /// new PHIs, as needed. Preds is a list of preds inside the loop, SplitBB
121 /// new PHIs, as needed. Preds is a list of preds inside the loop, SplitBB
122122 /// is the new loop exit block, and DestBB is the old loop exit, now the
123123 /// successor of SplitBB.
124124 static void CreatePHIsForSplitLoopExit(SmallVectorImpl &Preds,
125125 BasicBlock *SplitBB,
126126 BasicBlock *DestBB) {
127127 // SplitBB shouldn't have anything non-trivial in it yet.
128 assert(SplitBB->getFirstNonPHI() == SplitBB->getTerminator() &&
129 "SplitBB has non-PHI nodes!");
130
131 // For each PHI in the destination block...
128 assert((SplitBB->getFirstNonPHI() == SplitBB->getTerminator() ||
129 SplitBB->isLandingPad()) && "SplitBB has non-PHI nodes!");
130
131 // For each PHI in the destination block.
132132 for (BasicBlock::iterator I = DestBB->begin();
133133 PHINode *PN = dyn_cast(I); ++I) {
134134 unsigned Idx = PN->getBasicBlockIndex(SplitBB);
135135 Value *V = PN->getIncomingValue(Idx);
136
136137 // If the input is a PHI which already satisfies LCSSA, don't create
137138 // a new one.
138139 if (const PHINode *VP = dyn_cast(V))
139140 if (VP->getParent() == SplitBB)
140141 continue;
142
141143 // Otherwise a new PHI is needed. Create one and populate it.
142 PHINode *NewPN = PHINode::Create(PN->getType(), Preds.size(), "split",
143 SplitBB->getTerminator());
144 PHINode *NewPN =
145 PHINode::Create(PN->getType(), Preds.size(), "split",
146 SplitBB->isLandingPad() ?
147 SplitBB->begin() : SplitBB->getTerminator());
144148 for (unsigned i = 0, e = Preds.size(); i != e; ++i)
145149 NewPN->addIncoming(V, Preds[i]);
150
146151 // Update the original PHI.
147152 PN->setIncomingValue(Idx, NewPN);
148153 }
167172 ///
168173 BasicBlock *llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
169174 Pass *P, bool MergeIdenticalEdges,
170 bool DontDeleteUselessPhis) {
175 bool DontDeleteUselessPhis,
176 bool SplitLandingPads) {
171177 if (!isCriticalEdge(TI, SuccNum, MergeIdenticalEdges)) return 0;
172178
173179 assert(!isa(TI) &&
370376 // getUniqueExitBlocks above because that depends on LoopSimplify
371377 // form, which we're in the process of restoring!
372378 if (!Preds.empty() && HasPredOutsideOfLoop) {
373 BasicBlock *NewExitBB =
374 SplitBlockPredecessors(Exit, Preds, "split", P);
375 if (P->mustPreserveAnalysisID(LCSSAID))
376 CreatePHIsForSplitLoopExit(Preds, NewExitBB, Exit);
379 if (!Exit->isLandingPad()) {
380 BasicBlock *NewExitBB =
381 SplitBlockPredecessors(Exit, Preds, "split", P);
382 if (P->mustPreserveAnalysisID(LCSSAID))
383 createPHIsForSplitLoopExit(Preds, NewExitBB, Exit);
384 } else if (SplitLandingPads) {
385 SmallVector NewBBs;
386 SplitLandingPadPredecessors(Exit, Preds,
387 ".split1", ".split2",
388 P, NewBBs);
389 if (P->mustPreserveAnalysisID(LCSSAID))
390 createPHIsForSplitLoopExit(Preds, NewBBs[0], Exit);
391 }
377392 }
378393 }
379394 }
0 ; RUN: opt < %s -basicaa -instcombine -inline -functionattrs -licm -loop-unswitch -gvn -verify
1 ; PR12573
2 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
3 target triple = "x86_64-apple-macosx10.7.0"
4
5 %class.D.22.42.66.102.138.158.178.198.238.242.246.250.262.294.302.338.346.379 = type { %class.C.23.43.67.103.139.159.179.199.239.243.247.251.263.295.303.339.347.376*, %class.B.21.41.65.101.137.157.177.197.237.241.245.249.261.293.301.337.345.378 }
6 %class.C.23.43.67.103.139.159.179.199.239.243.247.251.263.295.303.339.347.376 = type { %class.D.22.42.66.102.138.158.178.198.238.242.246.250.262.294.302.338.346.379* }
7 %class.B.21.41.65.101.137.157.177.197.237.241.245.249.261.293.301.337.345.378 = type { %class.A.20.40.64.100.136.156.176.196.236.240.244.248.260.292.300.336.344.377* }
8 %class.A.20.40.64.100.136.156.176.196.236.240.244.248.260.292.300.336.344.377 = type { i8 }
9
10 define void @_Z23get_reconstruction_pathv() uwtable ssp {
11 entry:
12 %c = alloca %class.D.22.42.66.102.138.158.178.198.238.242.246.250.262.294.302.338.346.379, align 8
13 br label %for.cond
14
15 for.cond: ; preds = %for.end, %entry
16 invoke void @_ZN1DptEv(%class.D.22.42.66.102.138.158.178.198.238.242.246.250.262.294.302.338.346.379* %c)
17 to label %invoke.cont unwind label %lpad
18
19 invoke.cont: ; preds = %for.cond
20 invoke void @_ZN1C3endEv()
21 to label %for.cond3 unwind label %lpad
22
23 for.cond3: ; preds = %invoke.cont6, %invoke.cont
24 invoke void @_ZN1DptEv(%class.D.22.42.66.102.138.158.178.198.238.242.246.250.262.294.302.338.346.379* %c)
25 to label %invoke.cont4 unwind label %lpad
26
27 invoke.cont4: ; preds = %for.cond3
28 invoke void @_ZN1C3endEv()
29 to label %invoke.cont6 unwind label %lpad
30
31 invoke.cont6: ; preds = %invoke.cont4
32 br i1 undef, label %for.cond3, label %for.end
33
34 lpad: ; preds = %for.end, %invoke.cont4, %for.cond3, %invoke.cont, %for.cond
35 %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
36 cleanup
37 resume { i8*, i32 } undef
38
39 for.end: ; preds = %invoke.cont6
40 invoke void @_ZN1C13_M_insert_auxER1D()
41 to label %for.cond unwind label %lpad
42 }
43
44 define void @_ZN1DptEv(%class.D.22.42.66.102.138.158.178.198.238.242.246.250.262.294.302.338.346.379* %this) uwtable ssp align 2 {
45 entry:
46 %this.addr = alloca %class.D.22.42.66.102.138.158.178.198.238.242.246.250.262.294.302.338.346.379*, align 8
47 store %class.D.22.42.66.102.138.158.178.198.238.242.246.250.262.294.302.338.346.379* %this, %class.D.22.42.66.102.138.158.178.198.238.242.246.250.262.294.302.338.346.379** %this.addr, align 8, !tbaa !0
48 %this1 = load %class.D.22.42.66.102.138.158.178.198.238.242.246.250.262.294.302.338.346.379** %this.addr
49 %px = getelementptr inbounds %class.D.22.42.66.102.138.158.178.198.238.242.246.250.262.294.302.338.346.379* %this1, i32 0, i32 0
50 %0 = load %class.C.23.43.67.103.139.159.179.199.239.243.247.251.263.295.303.339.347.376** %px, align 8, !tbaa !0
51 %tobool = icmp ne %class.C.23.43.67.103.139.159.179.199.239.243.247.251.263.295.303.339.347.376* %0, null
52 br i1 %tobool, label %cond.end, label %cond.false
53
54 cond.false: ; preds = %entry
55 call void @_Z10__assert13v() noreturn
56 unreachable
57
58 cond.end: ; preds = %entry
59 ret void
60 }
61
62 declare i32 @__gxx_personality_v0(...)
63
64 declare void @_ZN1C3endEv()
65
66 define void @_ZN1C13_M_insert_auxER1D() uwtable ssp align 2 {
67 entry:
68 ret void
69 }
70
71 define void @_ZN1DD1Ev() unnamed_addr uwtable inlinehint ssp align 2 {
72 entry:
73 ret void
74 }
75
76 define void @_ZN1DD2Ev() unnamed_addr uwtable inlinehint ssp align 2 {
77 entry:
78 ret void
79 }
80
81 define void @_ZN1BD1Ev() unnamed_addr uwtable ssp align 2 {
82 entry:
83 ret void
84 }
85
86 define void @_ZN1BD2Ev() unnamed_addr uwtable ssp align 2 {
87 entry:
88 ret void
89 }
90
91 define void @_ZN1BaSERS_() uwtable ssp align 2 {
92 entry:
93 unreachable
94 }
95
96 declare void @_Z10__assert13v() noreturn
97
98 !0 = metadata !{metadata !"any pointer", metadata !1}
99 !1 = metadata !{metadata !"omnipotent char", metadata !2}
100 !2 = metadata !{metadata !"Simple C/C++ TBAA", null}