llvm.org GIT mirror llvm / 934af9c
Make LoopDeletion check the maximum backedge taken count, rather than the exact backedge taken count, when checking for infinite loops. This allows it to delete loops with multiple exit conditions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84952 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 9 years ago
2 changed file(s) with 28 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
166166 // Don't remove loops for which we can't solve the trip count.
167167 // They could be infinite, in which case we'd be changing program behavior.
168168 ScalarEvolution& SE = getAnalysis();
169 const SCEV *S = SE.getBackedgeTakenCount(L);
169 const SCEV *S = SE.getMaxBackedgeTakenCount(L);
170170 if (isa(S))
171171 return Changed;
172172
0 ; RUN: opt < %s -loop-deletion -S | FileCheck %s
1
2 ; ScalarEvolution can prove the loop iteration is finite, even though
3 ; it can't represent the exact trip count as an expression. That's
4 ; good enough to let the loop be deleted.
5
6 ; CHECK: entry:
7 ; CHECK-NEXT: br label %return
8
9 ; CHECK: return:
10 ; CHECK-NEXT: ret void
11
12 define void @foo(i64 %n, i64 %m) nounwind {
13 entry:
14 br label %bb
15
16 bb:
17 %x.0 = phi i64 [ 0, %entry ], [ %t0, %bb ]
18 %t0 = add i64 %x.0, 1
19 %t1 = icmp slt i64 %x.0, %n
20 %t3 = icmp sgt i64 %x.0, %m
21 %t4 = and i1 %t1, %t3
22 br i1 %t4, label %bb, label %return
23
24 return:
25 ret void
26 }