1 ; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s
3 ; Trip counts with trivial exit conditions.
5 ; CHECK: Determining loop execution counts for: @a
6 ; CHECK: Loop %loop: Unpredictable backedge-taken count.
7 ; CHECK: Loop %loop: Unpredictable max backedge-taken count.
9 ; CHECK: Determining loop execution counts for: @b
10 ; CHECK: Loop %loop: backedge-taken count is false
11 ; CHECK: Loop %loop: max backedge-taken count is false
13 ; CHECK: Determining loop execution counts for: @c
14 ; CHECK: Loop %loop: backedge-taken count is false
15 ; CHECK: Loop %loop: max backedge-taken count is false
17 ; CHECK: Determining loop execution counts for: @d
18 ; CHECK: Loop %loop: Unpredictable backedge-taken count.
19 ; CHECK: Loop %loop: Unpredictable max backedge-taken count.
21 define void @a(i64 %n) nounwind {
23 %t0 = icmp sgt i64 %n, 0
24 br i1 %t0, label %loop, label %return
27 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
28 %i.next = add nsw i64 %i, 1
29 %exitcond = icmp eq i64 %i.next, %n
30 br i1 false, label %return, label %loop
35 define void @b(i64 %n) nounwind {
37 %t0 = icmp sgt i64 %n, 0
38 br i1 %t0, label %loop, label %return
41 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
42 %i.next = add nsw i64 %i, 1
43 %exitcond = icmp eq i64 %i.next, %n
44 br i1 true, label %return, label %loop
49 define void @c(i64 %n) nounwind {
51 %t0 = icmp sgt i64 %n, 0
52 br i1 %t0, label %loop, label %return
55 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
56 %i.next = add nsw i64 %i, 1
57 %exitcond = icmp eq i64 %i.next, %n
58 br i1 false, label %loop, label %return
63 define void @d(i64 %n) nounwind {
65 %t0 = icmp sgt i64 %n, 0
66 br i1 %t0, label %loop, label %return
69 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
70 %i.next = add nsw i64 %i, 1
71 %exitcond = icmp eq i64 %i.next, %n
72 br i1 true, label %loop, label %return
78 ; Trip counts for non-polynomial iterations. It's theoretically possible
79 ; to compute a maximum count for these, but short of that, ScalarEvolution
80 ; should return unknown.
83 ; CHECK: Determining loop execution counts for: @nonpolynomial
84 ; CHECK-NEXT: Loop %loophead: Unpredictable backedge-taken count
85 ; CHECK-NEXT: Loop %loophead: Unpredictable max backedge-taken count
87 declare i1 @g() nounwind
89 define void @nonpolynomial() {
93 %x = phi i32 [0, %entry], [%x.1, %bb1], [%x.2, %bb2]
94 %y = icmp slt i32 %x, 100
95 br i1 %y, label %loopbody, label %retbb
98 br i1 %z, label %bb1, label %bb2
109 ; PHI nodes with all constant operands.
111 ; CHECK: Determining loop execution counts for: @constant_phi_operands
112 ; CHECK: Loop %loop: backedge-taken count is 1
113 ; CHECK: Loop %loop: max backedge-taken count is 1
115 define void @constant_phi_operands() nounwind {
120 %i = phi i64 [ 1, %loop ], [ 0, %entry ]
121 %exitcond = icmp eq i64 %i, 1
122 br i1 %exitcond, label %return, label %loop
128 ; PR16130: Loop exit depends on an 'or' expression.
129 ; One side of the expression test against a value that will be skipped.
130 ; We can't assume undefined behavior just because we have an NSW flag.
132 ; CHECK: Determining loop execution counts for: @exit_orcond_nsw
133 ; CHECK: Loop %for.body.i: Unpredictable backedge-taken count.
134 ; CHECK: Loop %for.body.i: max backedge-taken count is 1
135 define void @exit_orcond_nsw(i32 *%a) nounwind {
139 for.body.i: ; preds = %for.body.i, %entry
140 %b.01.i = phi i32 [ 0, %entry ], [ %add.i, %for.body.i ]
141 %tobool.i = icmp ne i32 %b.01.i, 0
142 %add.i = add nsw i32 %b.01.i, 8
143 %cmp.i = icmp eq i32 %add.i, 13
144 %or.cond = or i1 %tobool.i, %cmp.i
145 br i1 %or.cond, label %exit, label %for.body.i
147 exit: ; preds = %for.body.i
148 %b.01.i.lcssa = phi i32 [ %b.01.i, %for.body.i ]
149 store i32 %b.01.i.lcssa, i32* %a, align 4