1 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2 ; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" -scalar-evolution-classify-expressions=0 2>&1 | FileCheck %s
4 ; Trip counts with trivial exit conditions.
6 define void @a(i64 %n) nounwind {
8 ; CHECK-NEXT: Determining loop execution counts for: @a
9 ; CHECK-NEXT: Loop %loop: Unpredictable backedge-taken count.
10 ; CHECK-NEXT: Loop %loop: Unpredictable constant max backedge-taken count.
11 ; CHECK-NEXT: Loop %loop: Unpredictable symbolic 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: constant max backedge-taken count is false
32 ; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is false
33 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is false
34 ; CHECK-NEXT: Predicates:
35 ; CHECK: Loop %loop: Trip multiple is 1
38 %t0 = icmp sgt i64 %n, 0
39 br i1 %t0, label %loop, label %return
42 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
43 %i.next = add nsw i64 %i, 1
44 %exitcond = icmp eq i64 %i.next, %n
45 br i1 true, label %return, label %loop
50 define void @c(i64 %n) nounwind {
52 ; CHECK-NEXT: Determining loop execution counts for: @c
53 ; CHECK-NEXT: Loop %loop: backedge-taken count is false
54 ; CHECK-NEXT: Loop %loop: constant max backedge-taken count is false
55 ; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is false
56 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is false
57 ; CHECK-NEXT: Predicates:
58 ; CHECK: Loop %loop: Trip multiple is 1
61 %t0 = icmp sgt i64 %n, 0
62 br i1 %t0, label %loop, label %return
65 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
66 %i.next = add nsw i64 %i, 1
67 %exitcond = icmp eq i64 %i.next, %n
68 br i1 false, label %loop, label %return
73 define void @d(i64 %n) nounwind {
75 ; CHECK-NEXT: Determining loop execution counts for: @d
76 ; CHECK-NEXT: Loop %loop: Unpredictable backedge-taken count.
77 ; CHECK-NEXT: Loop %loop: Unpredictable constant max backedge-taken count.
78 ; CHECK-NEXT: Loop %loop: Unpredictable symbolic max backedge-taken count.
79 ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
82 %t0 = icmp sgt i64 %n, 0
83 br i1 %t0, label %loop, label %return
86 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
87 %i.next = add nsw i64 %i, 1
88 %exitcond = icmp eq i64 %i.next, %n
89 br i1 true, label %loop, label %return
95 ; Trip counts for non-polynomial iterations. It's theoretically possible
96 ; to compute a maximum count for these, but short of that, ScalarEvolution
97 ; should return unknown.
100 declare i1 @g() nounwind
102 define void @nonpolynomial() {
103 ; CHECK-LABEL: 'nonpolynomial'
104 ; CHECK-NEXT: Determining loop execution counts for: @nonpolynomial
105 ; CHECK-NEXT: Loop %loophead: Unpredictable backedge-taken count.
106 ; CHECK-NEXT: Loop %loophead: Unpredictable constant max backedge-taken count.
107 ; CHECK-NEXT: Loop %loophead: Unpredictable symbolic max backedge-taken count.
108 ; CHECK-NEXT: Loop %loophead: Unpredictable predicated backedge-taken count.
113 %x = phi i32 [0, %entry], [%x.1, %bb1], [%x.2, %bb2]
114 %y = icmp slt i32 %x, 100
115 br i1 %y, label %loopbody, label %retbb
118 br i1 %z, label %bb1, label %bb2
129 ; PHI nodes with all constant operands.
131 define void @constant_phi_operands() nounwind {
132 ; CHECK-LABEL: 'constant_phi_operands'
133 ; CHECK-NEXT: Determining loop execution counts for: @constant_phi_operands
134 ; CHECK-NEXT: Loop %loop: backedge-taken count is 1
135 ; CHECK-NEXT: Loop %loop: constant max backedge-taken count is 1
136 ; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is 1
137 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is 1
138 ; CHECK-NEXT: Predicates:
139 ; CHECK: Loop %loop: Trip multiple is 2
145 %i = phi i64 [ 1, %loop ], [ 0, %entry ]
146 %exitcond = icmp eq i64 %i, 1
147 br i1 %exitcond, label %return, label %loop
153 ; PR16130: Loop exit depends on an 'or' expression.
154 ; One side of the expression test against a value that will be skipped.
155 ; We can't assume undefined behavior just because we have an NSW flag.
157 define void @exit_orcond_nsw(ptr %a) nounwind {
158 ; CHECK-LABEL: 'exit_orcond_nsw'
159 ; CHECK-NEXT: Determining loop execution counts for: @exit_orcond_nsw
160 ; CHECK-NEXT: Loop %for.body.i: Unpredictable backedge-taken count.
161 ; CHECK-NEXT: Loop %for.body.i: constant max backedge-taken count is 1
162 ; CHECK-NEXT: Loop %for.body.i: symbolic max backedge-taken count is 1
163 ; CHECK-NEXT: Loop %for.body.i: Unpredictable predicated backedge-taken count.
168 for.body.i: ; preds = %for.body.i, %entry
169 %b.01.i = phi i32 [ 0, %entry ], [ %add.i, %for.body.i ]
170 %tobool.i = icmp ne i32 %b.01.i, 0
171 %add.i = add nsw i32 %b.01.i, 8
172 %cmp.i = icmp eq i32 %add.i, 13
173 %or.cond = or i1 %tobool.i, %cmp.i
174 br i1 %or.cond, label %exit, label %for.body.i
176 exit: ; preds = %for.body.i
177 %b.01.i.lcssa = phi i32 [ %b.01.i, %for.body.i ]
178 store i32 %b.01.i.lcssa, ptr %a, align 4