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