llvm.org GIT mirror llvm / b92654d
Fix ScalarEvolution's "exhaustive" trip count evaluation code to avoid assuming that loops are in canonical form, as ScalarEvolution doesn't depend on LoopSimplify itself. Also, with indirectbr not all loops can be simplified. This fixes PR7416. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@106389 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 9 years ago
2 changed file(s) with 36 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
42374237 PHINode *PN = getConstantEvolvingPHI(Cond, L);
42384238 if (PN == 0) return getCouldNotCompute();
42394239
4240 // Since the loop is canonicalized, the PHI node must have two entries. One
4241 // entry must be a constant (coming in from outside of the loop), and the
4240 // If the loop is canonicalized, the PHI will have exactly two entries.
4241 // That's the only form we support here.
4242 if (PN->getNumIncomingValues() != 2) return getCouldNotCompute();
4243
4244 // One entry must be a constant (coming in from outside of the loop), and the
42424245 // second must be derived from the same PHI.
42434246 bool SecondIsBackedge = L->contains(PN->getIncomingBlock(1));
42444247 Constant *StartCST =
7373 return:
7474 ret void
7575 }
76
77 ; Trip counts for non-polynomial iterations. It's theoretically possible
78 ; to compute a maximum count for these, but short of that, ScalarEvolution
79 ; should return unknown.
80
81 ; PR7416
82 ; CHECK: Determining loop execution counts for: @nonpolynomial
83 ; CHECK-NEXT: Loop %loophead: Unpredictable backedge-taken count
84 ; CHECK-NEXT: Loop %loophead: Unpredictable max backedge-taken count
85
86 declare i1 @g() nounwind
87
88 define void @nonpolynomial() {
89 entry:
90 br label %loophead
91 loophead:
92 %x = phi i32 [0, %entry], [%x.1, %bb1], [%x.2, %bb2]
93 %y = icmp slt i32 %x, 100
94 br i1 %y, label %loopbody, label %retbb
95 loopbody:
96 %z = call i1 @g()
97 br i1 %z, label %bb1, label %bb2
98 bb1:
99 %x.1 = add i32 %x, 2
100 br label %loophead
101 bb2:
102 %x.2 = add i32 %x, 3
103 br label %loophead
104 retbb:
105 ret void
106 }