llvm.org GIT mirror llvm / 0f3a589
[BasicBlockUtils] Check for unreachable preds before updating LI in UpdateAnalysisInformation Summary: We are incorrectly updating the LI when loop-simplify generates dedicated exit blocks for a loop. The issue is that there's an implicit assumption that the Preds passed into UpdateAnalysisInformation are reachable. However, this is not true and breaks LI by incorrectly updating the header of a loop. One such case is when we generate dedicated exits when the exit block is a landing pad (through SplitLandingPadPredecessors). There maybe other cases as well, since we do not guarantee that Preds passed in are reachable basic blocks. The added test case shows how loop-simplify breaks LI for the outer loop (and DT in turn) after we try to generate the LoopSimplifyForm. Reviewers: davide, chandlerc, sanjoy Reviewed By: davide Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D41519 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321653 91177308-0d34-0410-b5e6-96231b3b80d8 Anna Thomas 1 year, 9 months ago
2 changed file(s) with 55 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
322322 bool IsLoopEntry = !!L;
323323 bool SplitMakesNewLoopHeader = false;
324324 for (BasicBlock *Pred : Preds) {
325 // Preds that are not reachable from entry should not be used to identify if
326 // OldBB is a loop entry or if SplitMakesNewLoopHeader. Unreachable blocks
327 // are not within any loops, so we incorrectly mark SplitMakesNewLoopHeader
328 // as true and make the NewBB the header of some loop. This breaks LI.
329 if (!DT->isReachableFromEntry(Pred))
330 continue;
325331 // If we need to preserve LCSSA, determine if any of the preds is a loop
326332 // exit.
327333 if (PreserveLCSSA)
1717 foo:
1818 br label %while.body115
1919 }
20
21 ; When loopsimplify generates dedicated exit block for blocks that are landing
22 ; pads (i.e. innerLoopExit in this test), we should not get confused with the
23 ; unreachable pred (unreachableB) to innerLoopExit.
24 define align 8 void @baz(i32 %trip) personality i32* ()* @wobble {
25 entry:
26 br label %outerHeader
27
28 outerHeader:
29 invoke void @foo()
30 to label %innerPreheader unwind label %innerLoopExit
31
32 innerPreheader:
33 br label %innerH
34
35 innerH:
36 %tmp50 = invoke i8 * undef()
37 to label %innerLatch unwind label %innerLoopExit
38
39 innerLatch:
40 %cmp = icmp slt i32 %trip, 42
41 br i1 %cmp, label %innerH, label %retblock
42
43 unreachableB: ; No predecessors!
44 %tmp62 = invoke i8 * undef()
45 to label %retblock unwind label %innerLoopExit
46
47 ; undedicated exit block (preds from inner and outer loop)
48 ; Also has unreachableB as pred.
49 innerLoopExit:
50 %tmp65 = landingpad { i8*, i32 }
51 cleanup
52 invoke void @foo()
53 to label %outerHeader unwind label %unwindblock
54
55 unwindblock:
56 %tmp67 = landingpad { i8*, i32 }
57 cleanup
58 ret void
59
60 retblock:
61 ret void
62 }
63
64 ; Function Attrs: nounwind
65 declare i32* @wobble()
66
67 ; Function Attrs: uwtable
68 declare void @foo()