1 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2 ; RUN: opt -disable-output "-passes=print<scalar-evolution>" -S -scalar-evolution-classify-expressions=0 < %s 2>&1 | FileCheck %s
5 ; - starting at 0, 1, or %x
7 ; - stopping at %n or %n*2
10 ; Some of these represent missed opportunities.
12 define void @foo(i4 %n) {
14 ; CHECK-NEXT: Determining loop execution counts for: @foo
15 ; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + %n)
16 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 6
17 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + %n)
18 ; CHECK-NEXT: Predicates:
19 ; CHECK: Loop %loop: Trip multiple is 1
22 %s = icmp sgt i4 %n, 0
23 br i1 %s, label %loop, label %exit
25 %i = phi i4 [ 0, %entry ], [ %i.next, %loop ]
26 %i.next = add i4 %i, 1
27 %t = icmp slt i4 %i.next, %n
28 br i1 %t, label %loop, label %exit
33 define void @step2(i4 %n) {
34 ; CHECK-LABEL: 'step2'
35 ; CHECK-NEXT: Determining loop execution counts for: @step2
36 ; CHECK-NEXT: Loop %loop: Unpredictable backedge-taken count.
37 ; CHECK-NEXT: Loop %loop: Unpredictable max backedge-taken count.
38 ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
41 %s = icmp sgt i4 %n, 0
42 br i1 %s, label %loop, label %exit
44 %i = phi i4 [ 0, %entry ], [ %i.next, %loop ]
45 %i.next = add i4 %i, 2
46 %t = icmp slt i4 %i.next, %n
47 br i1 %t, label %loop, label %exit
52 define void @start1(i4 %n) {
53 ; CHECK-LABEL: 'start1'
54 ; CHECK-NEXT: Determining loop execution counts for: @start1
55 ; CHECK-NEXT: Loop %loop: backedge-taken count is (-2 + (2 smax %n))<nsw>
56 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 5
57 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-2 + (2 smax %n))<nsw>
58 ; CHECK-NEXT: Predicates:
59 ; CHECK: Loop %loop: Trip multiple is 1
62 %s = icmp sgt i4 %n, 0
63 br i1 %s, label %loop, label %exit
65 %i = phi i4 [ 1, %entry ], [ %i.next, %loop ]
66 %i.next = add i4 %i, 1
67 %t = icmp slt i4 %i.next, %n
68 br i1 %t, label %loop, label %exit
73 define void @start1_step2(i4 %n) {
74 ; CHECK-LABEL: 'start1_step2'
75 ; CHECK-NEXT: Determining loop execution counts for: @start1_step2
76 ; CHECK-NEXT: Loop %loop: Unpredictable backedge-taken count.
77 ; CHECK-NEXT: Loop %loop: Unpredictable max backedge-taken count.
78 ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
81 %s = icmp sgt i4 %n, 0
82 br i1 %s, label %loop, label %exit
84 %i = phi i4 [ 1, %entry ], [ %i.next, %loop ]
85 %i.next = add i4 %i, 2
86 %t = icmp slt i4 %i.next, %n
87 br i1 %t, label %loop, label %exit
92 define void @startx(i4 %n, i4 %x) {
93 ; CHECK-LABEL: 'startx'
94 ; CHECK-NEXT: Determining loop execution counts for: @startx
95 ; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax %n))
96 ; CHECK-NEXT: Loop %loop: max backedge-taken count is -1
97 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax %n))
98 ; CHECK-NEXT: Predicates:
99 ; CHECK: Loop %loop: Trip multiple is 1
102 %s = icmp sgt i4 %n, 0
103 br i1 %s, label %loop, label %exit
105 %i = phi i4 [ %x, %entry ], [ %i.next, %loop ]
106 %i.next = add i4 %i, 1
107 %t = icmp slt i4 %i.next, %n
108 br i1 %t, label %loop, label %exit
113 define void @startx_step2(i4 %n, i4 %x) {
114 ; CHECK-LABEL: 'startx_step2'
115 ; CHECK-NEXT: Determining loop execution counts for: @startx_step2
116 ; CHECK-NEXT: Loop %loop: Unpredictable backedge-taken count.
117 ; CHECK-NEXT: Loop %loop: Unpredictable max backedge-taken count.
118 ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
121 %s = icmp sgt i4 %n, 0
122 br i1 %s, label %loop, label %exit
124 %i = phi i4 [ %x, %entry ], [ %i.next, %loop ]
125 %i.next = add i4 %i, 2
126 %t = icmp slt i4 %i.next, %n
127 br i1 %t, label %loop, label %exit
132 define void @nsw(i4 %n) {
134 ; CHECK-NEXT: Determining loop execution counts for: @nsw
135 ; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + %n)
136 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 6
137 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + %n)
138 ; CHECK-NEXT: Predicates:
139 ; CHECK: Loop %loop: Trip multiple is 1
142 %s = icmp sgt i4 %n, 0
143 br i1 %s, label %loop, label %exit
145 %i = phi i4 [ 0, %entry ], [ %i.next, %loop ]
146 %i.next = add nsw i4 %i, 1
147 %t = icmp slt i4 %i.next, %n
148 br i1 %t, label %loop, label %exit
153 ; If %n is INT4_MAX, %i.next will wrap. The nsw bit says that the
154 ; result is undefined. Therefore, after the loop's second iteration,
155 ; we are free to assume that the loop exits. This is valid because:
156 ; (a) %i.next is a poison value after the second iteration, which can
157 ; also be considered an undef value.
158 ; (b) the return instruction enacts a side effect that is control
159 ; dependent on the poison value.
161 define void @nsw_step2(i4 %n) {
162 ; CHECK-LABEL: 'nsw_step2'
163 ; CHECK-NEXT: Determining loop execution counts for: @nsw_step2
164 ; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 + %n) /u 2)
165 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 2
166 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is ((-1 + %n) /u 2)
167 ; CHECK-NEXT: Predicates:
168 ; CHECK: Loop %loop: Trip multiple is 1
171 %s = icmp sgt i4 %n, 0
172 br i1 %s, label %loop, label %exit
174 %i = phi i4 [ 0, %entry ], [ %i.next, %loop ]
175 %i.next = add nsw i4 %i, 2
176 %t = icmp slt i4 %i.next, %n
177 br i1 %t, label %loop, label %exit
182 define void @nsw_start1(i4 %n) {
183 ; CHECK-LABEL: 'nsw_start1'
184 ; CHECK-NEXT: Determining loop execution counts for: @nsw_start1
185 ; CHECK-NEXT: Loop %loop: backedge-taken count is (-2 + (2 smax %n))<nsw>
186 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 5
187 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-2 + (2 smax %n))<nsw>
188 ; CHECK-NEXT: Predicates:
189 ; CHECK: Loop %loop: Trip multiple is 1
192 %s = icmp sgt i4 %n, 0
193 br i1 %s, label %loop, label %exit
195 %i = phi i4 [ 1, %entry ], [ %i.next, %loop ]
196 %i.next = add nsw i4 %i, 1
197 %t = icmp slt i4 %i.next, %n
198 br i1 %t, label %loop, label %exit
203 define void @nsw_start1_step2(i4 %n) {
204 ; CHECK-LABEL: 'nsw_start1_step2'
205 ; CHECK-NEXT: Determining loop execution counts for: @nsw_start1_step2
206 ; CHECK-NEXT: Loop %loop: backedge-taken count is ((-2 + (3 smax %n))<nsw> /u 2)
207 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 2
208 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is ((-2 + (3 smax %n))<nsw> /u 2)
209 ; CHECK-NEXT: Predicates:
210 ; CHECK: Loop %loop: Trip multiple is 1
213 %s = icmp sgt i4 %n, 0
214 br i1 %s, label %loop, label %exit
216 %i = phi i4 [ 1, %entry ], [ %i.next, %loop ]
217 %i.next = add nsw i4 %i, 2
218 %t = icmp slt i4 %i.next, %n
219 br i1 %t, label %loop, label %exit
224 define void @nsw_startx(i4 %n, i4 %x) {
225 ; CHECK-LABEL: 'nsw_startx'
226 ; CHECK-NEXT: Determining loop execution counts for: @nsw_startx
227 ; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax %n))
228 ; CHECK-NEXT: Loop %loop: max backedge-taken count is -1
229 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax %n))
230 ; CHECK-NEXT: Predicates:
231 ; CHECK: Loop %loop: Trip multiple is 1
234 %s = icmp sgt i4 %n, 0
235 br i1 %s, label %loop, label %exit
237 %i = phi i4 [ %x, %entry ], [ %i.next, %loop ]
238 %i.next = add nsw i4 %i, 1
239 %t = icmp slt i4 %i.next, %n
240 br i1 %t, label %loop, label %exit
245 define void @nsw_startx_step2(i4 %n, i4 %x) {
246 ; CHECK-LABEL: 'nsw_startx_step2'
247 ; CHECK-NEXT: Determining loop execution counts for: @nsw_startx_step2
248 ; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax %n)) /u 2)
249 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 7
250 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax %n)) /u 2)
251 ; CHECK-NEXT: Predicates:
252 ; CHECK: Loop %loop: Trip multiple is 1
255 %s = icmp sgt i4 %n, 0
256 br i1 %s, label %loop, label %exit
258 %i = phi i4 [ %x, %entry ], [ %i.next, %loop ]
259 %i.next = add nsw i4 %i, 2
260 %t = icmp slt i4 %i.next, %n
261 br i1 %t, label %loop, label %exit
266 define void @even(i4 %n) {
267 ; CHECK-LABEL: 'even'
268 ; CHECK-NEXT: Determining loop execution counts for: @even
269 ; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + (2 * %n))
270 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 5
271 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + (2 * %n))
272 ; CHECK-NEXT: Predicates:
273 ; CHECK: Loop %loop: Trip multiple is 2
277 %s = icmp sgt i4 %m, 0
278 br i1 %s, label %loop, label %exit
280 %i = phi i4 [ 0, %entry ], [ %i.next, %loop ]
281 %i.next = add i4 %i, 1
282 %t = icmp slt i4 %i.next, %m
283 br i1 %t, label %loop, label %exit
288 define void @even_step2(i4 %n) {
289 ; CHECK-LABEL: 'even_step2'
290 ; CHECK-NEXT: Determining loop execution counts for: @even_step2
291 ; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 + (2 * %n)) /u 2)
292 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 2
293 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is ((-1 + (2 * %n)) /u 2)
294 ; CHECK-NEXT: Predicates:
295 ; CHECK: Loop %loop: Trip multiple is 1
299 %s = icmp sgt i4 %m, 0
300 br i1 %s, label %loop, label %exit
302 %i = phi i4 [ 0, %entry ], [ %i.next, %loop ]
303 %i.next = add i4 %i, 2
304 %t = icmp slt i4 %i.next, %m
305 br i1 %t, label %loop, label %exit
310 define void @even_start1(i4 %n) {
311 ; CHECK-LABEL: 'even_start1'
312 ; CHECK-NEXT: Determining loop execution counts for: @even_start1
313 ; CHECK-NEXT: Loop %loop: backedge-taken count is (-2 + (2 * %n))
314 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 4
315 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-2 + (2 * %n))
316 ; CHECK-NEXT: Predicates:
317 ; CHECK: Loop %loop: Trip multiple is 1
321 %s = icmp sgt i4 %m, 0
322 br i1 %s, label %loop, label %exit
324 %i = phi i4 [ 1, %entry ], [ %i.next, %loop ]
325 %i.next = add i4 %i, 1
326 %t = icmp slt i4 %i.next, %m
327 br i1 %t, label %loop, label %exit
332 define void @even_start1_step2(i4 %n) {
333 ; CHECK-LABEL: 'even_start1_step2'
334 ; CHECK-NEXT: Determining loop execution counts for: @even_start1_step2
335 ; CHECK-NEXT: Loop %loop: backedge-taken count is ((-2 + (2 * %n)) /u 2)
336 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 2
337 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is ((-2 + (2 * %n)) /u 2)
338 ; CHECK-NEXT: Predicates:
339 ; CHECK: Loop %loop: Trip multiple is 1
343 %s = icmp sgt i4 %m, 0
344 br i1 %s, label %loop, label %exit
346 %i = phi i4 [ 1, %entry ], [ %i.next, %loop ]
347 %i.next = add i4 %i, 2
348 %t = icmp slt i4 %i.next, %m
349 br i1 %t, label %loop, label %exit
354 define void @even_startx(i4 %n, i4 %x) {
355 ; CHECK-LABEL: 'even_startx'
356 ; CHECK-NEXT: Determining loop execution counts for: @even_startx
357 ; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax (2 * %n)))
358 ; CHECK-NEXT: Loop %loop: max backedge-taken count is -2
359 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax (2 * %n)))
360 ; CHECK-NEXT: Predicates:
361 ; CHECK: Loop %loop: Trip multiple is 1
365 %s = icmp sgt i4 %m, 0
366 br i1 %s, label %loop, label %exit
368 %i = phi i4 [ %x, %entry ], [ %i.next, %loop ]
369 %i.next = add i4 %i, 1
370 %t = icmp slt i4 %i.next, %m
371 br i1 %t, label %loop, label %exit
376 define void @even_startx_step2(i4 %n, i4 %x) {
377 ; CHECK-LABEL: 'even_startx_step2'
378 ; CHECK-NEXT: Determining loop execution counts for: @even_startx_step2
379 ; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax (2 * %n))) /u 2)
380 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 7
381 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax (2 * %n))) /u 2)
382 ; CHECK-NEXT: Predicates:
383 ; CHECK: Loop %loop: Trip multiple is 1
387 %s = icmp sgt i4 %m, 0
388 br i1 %s, label %loop, label %exit
390 %i = phi i4 [ %x, %entry ], [ %i.next, %loop ]
391 %i.next = add i4 %i, 2
392 %t = icmp slt i4 %i.next, %m
393 br i1 %t, label %loop, label %exit
398 define void @even_nsw(i4 %n) {
399 ; CHECK-LABEL: 'even_nsw'
400 ; CHECK-NEXT: Determining loop execution counts for: @even_nsw
401 ; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + (2 * %n))
402 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 5
403 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + (2 * %n))
404 ; CHECK-NEXT: Predicates:
405 ; CHECK: Loop %loop: Trip multiple is 2
409 %s = icmp sgt i4 %m, 0
410 br i1 %s, label %loop, label %exit
412 %i = phi i4 [ 0, %entry ], [ %i.next, %loop ]
413 %i.next = add nsw i4 %i, 1
414 %t = icmp slt i4 %i.next, %m
415 br i1 %t, label %loop, label %exit
420 define void @even_nsw_step2(i4 %n) {
421 ; CHECK-LABEL: 'even_nsw_step2'
422 ; CHECK-NEXT: Determining loop execution counts for: @even_nsw_step2
423 ; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 + (2 * %n)) /u 2)
424 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 2
425 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is ((-1 + (2 * %n)) /u 2)
426 ; CHECK-NEXT: Predicates:
427 ; CHECK: Loop %loop: Trip multiple is 1
431 %s = icmp sgt i4 %m, 0
432 br i1 %s, label %loop, label %exit
434 %i = phi i4 [ 0, %entry ], [ %i.next, %loop ]
435 %i.next = add nsw i4 %i, 2
436 %t = icmp slt i4 %i.next, %m
437 br i1 %t, label %loop, label %exit
442 define void @even_nsw_start1(i4 %n) {
443 ; CHECK-LABEL: 'even_nsw_start1'
444 ; CHECK-NEXT: Determining loop execution counts for: @even_nsw_start1
445 ; CHECK-NEXT: Loop %loop: backedge-taken count is (-2 + (2 * %n))
446 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 4
447 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-2 + (2 * %n))
448 ; CHECK-NEXT: Predicates:
449 ; CHECK: Loop %loop: Trip multiple is 1
453 %s = icmp sgt i4 %m, 0
454 br i1 %s, label %loop, label %exit
456 %i = phi i4 [ 1, %entry ], [ %i.next, %loop ]
457 %i.next = add nsw i4 %i, 1
458 %t = icmp slt i4 %i.next, %m
459 br i1 %t, label %loop, label %exit
464 define void @even_nsw_start1_step2(i4 %n) {
465 ; CHECK-LABEL: 'even_nsw_start1_step2'
466 ; CHECK-NEXT: Determining loop execution counts for: @even_nsw_start1_step2
467 ; CHECK-NEXT: Loop %loop: backedge-taken count is ((-2 + (2 * %n)) /u 2)
468 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 2
469 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is ((-2 + (2 * %n)) /u 2)
470 ; CHECK-NEXT: Predicates:
471 ; CHECK: Loop %loop: Trip multiple is 1
475 %s = icmp sgt i4 %m, 0
476 br i1 %s, label %loop, label %exit
478 %i = phi i4 [ 1, %entry ], [ %i.next, %loop ]
479 %i.next = add nsw i4 %i, 2
480 %t = icmp slt i4 %i.next, %m
481 br i1 %t, label %loop, label %exit
486 define void @even_nsw_startx(i4 %n, i4 %x) {
487 ; CHECK-LABEL: 'even_nsw_startx'
488 ; CHECK-NEXT: Determining loop execution counts for: @even_nsw_startx
489 ; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax (2 * %n)))
490 ; CHECK-NEXT: Loop %loop: max backedge-taken count is -2
491 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax (2 * %n)))
492 ; CHECK-NEXT: Predicates:
493 ; CHECK: Loop %loop: Trip multiple is 1
497 %s = icmp sgt i4 %m, 0
498 br i1 %s, label %loop, label %exit
500 %i = phi i4 [ %x, %entry ], [ %i.next, %loop ]
501 %i.next = add nsw i4 %i, 1
502 %t = icmp slt i4 %i.next, %m
503 br i1 %t, label %loop, label %exit
508 define void @even_nsw_startx_step2(i4 %n, i4 %x) {
509 ; CHECK-LABEL: 'even_nsw_startx_step2'
510 ; CHECK-NEXT: Determining loop execution counts for: @even_nsw_startx_step2
511 ; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax (2 * %n))) /u 2)
512 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 7
513 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax (2 * %n))) /u 2)
514 ; CHECK-NEXT: Predicates:
515 ; CHECK: Loop %loop: Trip multiple is 1
519 %s = icmp sgt i4 %m, 0
520 br i1 %s, label %loop, label %exit
522 %i = phi i4 [ %x, %entry ], [ %i.next, %loop ]
523 %i.next = add nsw i4 %i, 2
524 %t = icmp slt i4 %i.next, %m
525 br i1 %t, label %loop, label %exit