llvm.org GIT mirror llvm / 00cb5b7
Teach ScalarEvolution how to compute a tripcount for a loop with true or false as its exit condition. These are usually eliminated by SimplifyCFG, but the may be left around during a pass which wishes to preserve the CFG. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96683 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
10 changed file(s) with 101 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
37023702 if (ICmpInst *ExitCondICmp = dyn_cast(ExitCond))
37033703 return ComputeBackedgeTakenCountFromExitCondICmp(L, ExitCondICmp, TBB, FBB);
37043704
3705 // Check for a constant condition. These are normally stripped out by
3706 // SimplifyCFG, but ScalarEvolution may be used by a pass which wishes to
3707 // preserve the CFG and is temporarily leaving constant conditions
3708 // in place.
3709 if (ConstantInt *CI = dyn_cast(ExitCond)) {
3710 if (L->contains(FBB) == !CI->getZExtValue())
3711 // The backedge is always taken.
3712 return getCouldNotCompute();
3713 else
3714 // The backedge is never taken.
3715 return getIntegerSCEV(0, CI->getType());
3716 }
3717
37053718 // If it's not an integer or pointer comparison then compute it the hard way.
37063719 return ComputeBackedgeTakenCountExhaustively(L, ExitCond, !L->contains(TBB));
37073720 }
0 ; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s
1
2 ; Trip counts with trivial exit conditions.
3
4 ; CHECK: Determining loop execution counts for: @a
5 ; CHECK: Loop %loop: Unpredictable backedge-taken count.
6 ; CHECK: Loop %loop: Unpredictable max backedge-taken count.
7
8 ; CHECK: Determining loop execution counts for: @b
9 ; CHECK: Loop %loop: backedge-taken count is false
10 ; CHECK: Loop %loop: max backedge-taken count is false
11
12 ; CHECK: Determining loop execution counts for: @c
13 ; CHECK: Loop %loop: backedge-taken count is false
14 ; CHECK: Loop %loop: max backedge-taken count is false
15
16 ; CHECK: Determining loop execution counts for: @d
17 ; CHECK: Loop %loop: Unpredictable backedge-taken count.
18 ; CHECK: Loop %loop: Unpredictable max backedge-taken count.
19
20 define void @a(i64 %n) nounwind {
21 entry:
22 %t0 = icmp sgt i64 %n, 0
23 br i1 %t0, label %loop, label %return
24
25 loop:
26 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
27 %i.next = add nsw i64 %i, 1
28 %exitcond = icmp eq i64 %i.next, %n
29 br i1 false, label %return, label %loop
30
31 return:
32 ret void
33 }
34 define void @b(i64 %n) nounwind {
35 entry:
36 %t0 = icmp sgt i64 %n, 0
37 br i1 %t0, label %loop, label %return
38
39 loop:
40 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
41 %i.next = add nsw i64 %i, 1
42 %exitcond = icmp eq i64 %i.next, %n
43 br i1 true, label %return, label %loop
44
45 return:
46 ret void
47 }
48 define void @c(i64 %n) nounwind {
49 entry:
50 %t0 = icmp sgt i64 %n, 0
51 br i1 %t0, label %loop, label %return
52
53 loop:
54 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
55 %i.next = add nsw i64 %i, 1
56 %exitcond = icmp eq i64 %i.next, %n
57 br i1 false, label %loop, label %return
58
59 return:
60 ret void
61 }
62 define void @d(i64 %n) nounwind {
63 entry:
64 %t0 = icmp sgt i64 %n, 0
65 br i1 %t0, label %loop, label %return
66
67 loop:
68 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
69 %i.next = add nsw i64 %i, 1
70 %exitcond = icmp eq i64 %i.next, %n
71 br i1 true, label %loop, label %return
72
73 return:
74 ret void
75 }
66 LoopHead: ; preds = %LoopHead, %0, %0
77 %A = phi i32 [ 7, %0 ], [ 7, %0 ], [ %B, %LoopHead ] ; [#uses=1]
88 %B = add i32 %A, 1 ; [#uses=2]
9 br i1 false, label %LoopHead, label %Out
9 br i1 undef, label %LoopHead, label %Out
1010
1111 Out: ; preds = %LoopHead
1212 ret i32 %B
99 %k.0.pn = phi i32 [ %inc.4, %no_exit ], [ 1, %entry ] ; [#uses=1]
1010 %inc.3 = add i32 %j.0.pn, 1 ; [#uses=1]
1111 %inc.4 = add i32 %k.0.pn, 1 ; [#uses=1]
12 br i1 false, label %no_exit, label %loopexit
12 br i1 undef, label %no_exit, label %loopexit
1313
1414 loopexit: ; preds = %no_exit, %entry
1515 ret void
77
88 loopexit.14: ; preds = %entry
99 %tmp.738 = sub i32 0, 0 ; [#uses=1]
10 br i1 false, label %no_exit.15.preheader, label %loopexit.15
10 br i1 undef, label %no_exit.15.preheader, label %loopexit.15
1111
1212 no_exit.15.preheader: ; preds = %loopexit.14
1313 br label %no_exit.15
1515 no_exit.15: ; preds = %no_exit.15, %no_exit.15.preheader
1616 %highC.0 = phi i32 [ %tmp.738, %no_exit.15.preheader ], [ %dec.0, %no_exit.15 ] ; [#uses=1]
1717 %dec.0 = add i32 %highC.0, -1 ; [#uses=1]
18 br i1 false, label %no_exit.15, label %loopexit.15
18 br i1 undef, label %no_exit.15, label %loopexit.15
1919
2020 loopexit.15: ; preds = %no_exit.15, %loopexit.14
2121 ret void
88 no_exit.0: ; preds = %no_exit.0, %entry
99 %p.0.0 = phi i32* [ getelementptr ([29 x [29 x [2 x i32]]]* @fixtab, i32 0, i32 0, i32 0, i32 0), %entry ], [ %inc.0, %no_exit.0 ] ; [#uses=1]
1010 %inc.0 = getelementptr i32* %p.0.0, i32 1 ; [#uses=1]
11 br i1 false, label %no_exit.0, label %no_exit.1
11 br i1 undef, label %no_exit.0, label %no_exit.1
1212
1313 no_exit.1: ; preds = %no_exit.0
1414 ret void
1919 %tmp194.i53 = bitcast i32 %decay.i.0 to float ; [#uses=1]
2020 %tmp195.i = fsub float %tmp194.i53, 8.000000e+00 ; [#uses=1]
2121 %tmp195.i.upgrd.1 = bitcast float %tmp195.i to i32 ; [#uses=1]
22 br i1 false, label %cond_next182.i, label %bb418.i.preheader
22 br i1 undef, label %cond_next182.i, label %bb418.i.preheader
2323
2424 bb418.i.preheader: ; preds = %cond_next182.i
2525 ret void
1111 br label %bb.nph1
1212
1313 bb.nph1: ; preds = %.outer, %bb.nph1.preheader
14 br i1 false, label %bb.nph3.preheader, label %.outer
14 br i1 undef, label %bb.nph3.preheader, label %.outer
1515
1616 bb.nph3.preheader: ; preds = %bb.nph1
1717 br label %bb.nph3
3030 br label %.outer
3131
3232 .outer: ; preds = %.outer.loopexit, %bb.nph1
33 br i1 false, label %bb.nph1, label %.outer._crit_edge.loopexit
33 br i1 undef, label %bb.nph1, label %.outer._crit_edge.loopexit
3434
3535 .outer._crit_edge.loopexit: ; preds = %.outer
3636 br label %.outer._crit_edge
99
1010 bb: ; preds = %bb6, %entry
1111 %p_71_addr.0 = phi i8 [ %p_71, %entry ], [ %0, %bb6 ] ; [#uses=0]
12 br i1 false, label %bb4, label %bb1
12 br i1 undef, label %bb4, label %bb1
1313
1414 bb1: ; preds = %bb
1515 ret i32 0
1616
1717 bb4: ; preds = %bb4, %bb
18 br i1 false, label %bb6, label %bb4
18 br i1 undef, label %bb6, label %bb4
1919
2020 bb6: ; preds = %bb4
2121 %0 = and i8 0, 0 ; [#uses=1]
1515 %str2Ptr_addr.1 = phi i8* [ %str2Ptr_addr.0, %entry ], [ %1, %bb2 ] ; [#uses=1]
1616 %1 = getelementptr i8* %str2Ptr_addr.1, i64 1 ; [#uses=2]
1717 %2 = icmp ult i8* %1, %inLastBytePtr ; [#uses=0]
18 br i1 false, label %bb2, label %return
18 br i1 undef, label %bb2, label %return
1919
2020 return: ; preds = %bb2
2121 ret void
3131 %str2Ptr_addr.1 = phi i8* [ %str2Ptr_addr.0, %entry ], [ %1, %bb2 ] ; [#uses=1]
3232 %1 = getelementptr i8* %str2Ptr_addr.1, i64 1 ; [#uses=2]
3333 %2 = icmp slt i8* %1, %inLastBytePtr ; [#uses=0]
34 br i1 false, label %bb2, label %return
34 br i1 undef, label %bb2, label %return
3535
3636 return: ; preds = %bb2
3737 ret void