1 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2 ; RUN: opt < %s -analyze -enable-new-pm=0 -scalar-evolution -scalar-evolution-classify-expressions=0 | FileCheck %s
3 ; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" -scalar-evolution-classify-expressions=0 2>&1 | FileCheck %s
5 ; Trip counts with trivial exit conditions.
7 define void @a(i64 %n) nounwind {
9 ; CHECK-NEXT: Determining loop execution counts for: @a
10 ; CHECK-NEXT: Loop %loop: Unpredictable backedge-taken count.
11 ; CHECK-NEXT: Loop %loop: Unpredictable max backedge-taken count.
12 ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
15 %t0 = icmp sgt i64 %n, 0
16 br i1 %t0, label %loop, label %return
19 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
20 %i.next = add nsw i64 %i, 1
21 %exitcond = icmp eq i64 %i.next, %n
22 br i1 false, label %return, label %loop
27 define void @b(i64 %n) nounwind {
29 ; CHECK-NEXT: Determining loop execution counts for: @b
30 ; CHECK-NEXT: Loop %loop: backedge-taken count is false
31 ; CHECK-NEXT: Loop %loop: max backedge-taken count is false
32 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is false
33 ; CHECK-NEXT: Predicates:
34 ; CHECK: Loop %loop: Trip multiple is 1
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 ; CHECK-NEXT: Determining loop execution counts for: @c
52 ; CHECK-NEXT: Loop %loop: backedge-taken count is false
53 ; CHECK-NEXT: Loop %loop: max backedge-taken count is false
54 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is false
55 ; CHECK-NEXT: Predicates:
56 ; CHECK: Loop %loop: Trip multiple is 1
59 %t0 = icmp sgt i64 %n, 0
60 br i1 %t0, label %loop, label %return
63 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
64 %i.next = add nsw i64 %i, 1
65 %exitcond = icmp eq i64 %i.next, %n
66 br i1 false, label %loop, label %return
71 define void @d(i64 %n) nounwind {
73 ; CHECK-NEXT: Determining loop execution counts for: @d
74 ; CHECK-NEXT: Loop %loop: Unpredictable backedge-taken count.
75 ; CHECK-NEXT: Loop %loop: Unpredictable max backedge-taken count.
76 ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
79 %t0 = icmp sgt i64 %n, 0
80 br i1 %t0, label %loop, label %return
83 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
84 %i.next = add nsw i64 %i, 1
85 %exitcond = icmp eq i64 %i.next, %n
86 br i1 true, label %loop, label %return
92 ; Trip counts for non-polynomial iterations. It's theoretically possible
93 ; to compute a maximum count for these, but short of that, ScalarEvolution
94 ; should return unknown.
97 declare i1 @g() nounwind
99 define void @nonpolynomial() {
100 ; CHECK-LABEL: 'nonpolynomial'
101 ; CHECK-NEXT: Determining loop execution counts for: @nonpolynomial
102 ; CHECK-NEXT: Loop %loophead: Unpredictable backedge-taken count.
103 ; CHECK-NEXT: Loop %loophead: Unpredictable max backedge-taken count.
104 ; CHECK-NEXT: Loop %loophead: Unpredictable predicated backedge-taken count.
109 %x = phi i32 [0, %entry], [%x.1, %bb1], [%x.2, %bb2]
110 %y = icmp slt i32 %x, 100
111 br i1 %y, label %loopbody, label %retbb
114 br i1 %z, label %bb1, label %bb2
125 ; PHI nodes with all constant operands.
127 define void @constant_phi_operands() nounwind {
128 ; CHECK-LABEL: 'constant_phi_operands'
129 ; CHECK-NEXT: Determining loop execution counts for: @constant_phi_operands
130 ; CHECK-NEXT: Loop %loop: backedge-taken count is 1
131 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 1
132 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is 1
133 ; CHECK-NEXT: Predicates:
134 ; CHECK: Loop %loop: Trip multiple is 2
140 %i = phi i64 [ 1, %loop ], [ 0, %entry ]
141 %exitcond = icmp eq i64 %i, 1
142 br i1 %exitcond, label %return, label %loop
148 ; PR16130: Loop exit depends on an 'or' expression.
149 ; One side of the expression test against a value that will be skipped.
150 ; We can't assume undefined behavior just because we have an NSW flag.
152 define void @exit_orcond_nsw(i32 *%a) nounwind {
153 ; CHECK-LABEL: 'exit_orcond_nsw'
154 ; CHECK-NEXT: Determining loop execution counts for: @exit_orcond_nsw
155 ; CHECK-NEXT: Loop %for.body.i: Unpredictable backedge-taken count.
156 ; CHECK-NEXT: Loop %for.body.i: max backedge-taken count is 1
157 ; CHECK-NEXT: Loop %for.body.i: Unpredictable predicated backedge-taken count.
162 for.body.i: ; preds = %for.body.i, %entry
163 %b.01.i = phi i32 [ 0, %entry ], [ %add.i, %for.body.i ]
164 %tobool.i = icmp ne i32 %b.01.i, 0
165 %add.i = add nsw i32 %b.01.i, 8
166 %cmp.i = icmp eq i32 %add.i, 13
167 %or.cond = or i1 %tobool.i, %cmp.i
168 br i1 %or.cond, label %exit, label %for.body.i
170 exit: ; preds = %for.body.i
171 %b.01.i.lcssa = phi i32 [ %b.01.i, %for.body.i ]
172 store i32 %b.01.i.lcssa, i32* %a, align 4