xref: /llvm-project/llvm/test/Analysis/ScalarEvolution/trip-count-unknown-stride.ll (revision 04cd06906288dcb148de37d7c3e6c009c3e3b726)
1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 4
2; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" -scalar-evolution-classify-expressions=0 2>&1 | FileCheck %s
3
4; ScalarEvolution should be able to compute trip count of the loop by proving
5; that this is not an infinite loop with side effects.
6
7
8; We should have a conservative estimate for the max backedge taken count for
9; loops with unknown stride.
10
11target datalayout = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
12
13define void @foo1(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
14;
15; CHECK-LABEL: 'foo1'
16; CHECK-NEXT:  Determining loop execution counts for: @foo1
17; CHECK-NEXT:  Loop %for.body: backedge-taken count is ((-1 + (%n smax %s)) /u %s)
18; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -1
19; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is ((-1 + (%n smax %s)) /u %s)
20; CHECK-NEXT:  Loop %for.body: Trip multiple is 1
21;
22entry:
23  %cmp4 = icmp sgt i32 %n, 0
24  br i1 %cmp4, label %for.body, label %for.end
25
26for.body:                                         ; preds = %entry, %for.body
27  %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
28  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
29  %0 = load i32, ptr %arrayidx, align 4
30  %inc = add nsw i32 %0, 1
31  store i32 %inc, ptr %arrayidx, align 4
32  %add = add nsw i32 %i.05, %s
33  %cmp = icmp slt i32 %add, %n
34  br i1 %cmp, label %for.body, label %for.end
35
36for.end:                                          ; preds = %for.body, %entry
37  ret void
38}
39
40
41; Check that we are able to compute trip count of a loop without an entry guard.
42
43; We should have a conservative estimate for the max backedge taken count for
44; loops with unknown stride.
45
46define void @foo2(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
47;
48; CHECK-LABEL: 'foo2'
49; CHECK-NEXT:  Determining loop execution counts for: @foo2
50; CHECK-NEXT:  Loop %for.body: backedge-taken count is ((((-1 * (1 umin ((-1 * %s) + (%n smax %s))))<nuw><nsw> + (-1 * %s) + (%n smax %s)) /u (1 umax %s)) + (1 umin ((-1 * %s) + (%n smax %s))))
51; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -1
52; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is ((((-1 * (1 umin ((-1 * %s) + (%n smax %s))))<nuw><nsw> + (-1 * %s) + (%n smax %s)) /u (1 umax %s)) + (1 umin ((-1 * %s) + (%n smax %s))))
53; CHECK-NEXT:  Loop %for.body: Trip multiple is 1
54;
55entry:
56  br label %for.body
57
58for.body:                                         ; preds = %entry, %for.body
59  %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
60  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
61  %0 = load i32, ptr %arrayidx, align 4
62  %inc = add nsw i32 %0, 1
63  store i32 %inc, ptr %arrayidx, align 4
64  %add = add nsw i32 %i.05, %s
65  %cmp = icmp slt i32 %add, %n
66  br i1 %cmp, label %for.body, label %for.end
67
68for.end:                                          ; preds = %for.body, %entry
69  ret void
70}
71
72; Check that without mustprogress we don't make assumptions about infinite
73; loops being UB.
74
75define void @foo3(ptr nocapture %A, i32 %n, i32 %s) {
76;
77; CHECK-LABEL: 'foo3'
78; CHECK-NEXT:  Determining loop execution counts for: @foo3
79; CHECK-NEXT:  Loop %for.body: Unpredictable backedge-taken count.
80; CHECK-NEXT:  Loop %for.body: Unpredictable constant max backedge-taken count.
81; CHECK-NEXT:  Loop %for.body: Unpredictable symbolic max backedge-taken count.
82;
83entry:
84  br label %for.body
85
86for.body:                                         ; preds = %entry, %for.body
87  %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
88  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
89  %0 = load i32, ptr %arrayidx, align 4
90  %inc = add nsw i32 %0, 1
91  store i32 %inc, ptr %arrayidx, align 4
92  %add = add nsw i32 %i.05, %s
93  %cmp = icmp slt i32 %add, %n
94  br i1 %cmp, label %for.body, label %for.end
95
96for.end:                                          ; preds = %for.body, %entry
97  ret void
98}
99
100; Same as foo2, but with mustprogress on loop, not function
101
102define void @foo4(ptr nocapture %A, i32 %n, i32 %s) {
103;
104; CHECK-LABEL: 'foo4'
105; CHECK-NEXT:  Determining loop execution counts for: @foo4
106; CHECK-NEXT:  Loop %for.body: backedge-taken count is ((((-1 * (1 umin ((-1 * %s) + (%n smax %s))))<nuw><nsw> + (-1 * %s) + (%n smax %s)) /u (1 umax %s)) + (1 umin ((-1 * %s) + (%n smax %s))))
107; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -1
108; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is ((((-1 * (1 umin ((-1 * %s) + (%n smax %s))))<nuw><nsw> + (-1 * %s) + (%n smax %s)) /u (1 umax %s)) + (1 umin ((-1 * %s) + (%n smax %s))))
109; CHECK-NEXT:  Loop %for.body: Trip multiple is 1
110;
111entry:
112  br label %for.body
113
114for.body:                                         ; preds = %entry, %for.body
115  %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
116  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
117  %0 = load i32, ptr %arrayidx, align 4
118  %inc = add nsw i32 %0, 1
119  store i32 %inc, ptr %arrayidx, align 4
120  %add = add nsw i32 %i.05, %s
121  %cmp = icmp slt i32 %add, %n
122  br i1 %cmp, label %for.body, label %for.end, !llvm.loop !8
123
124for.end:                                          ; preds = %for.body, %entry
125  ret void
126}
127
128; A more complex case with pre-increment compare instead of post-increment.
129
130; We should have a conservative estimate for the max backedge taken count for
131; loops with unknown stride.
132
133define void @foo5(ptr nocapture %A, i32 %n, i32 %s, i32 %start) mustprogress {
134;
135; CHECK-LABEL: 'foo5'
136; CHECK-NEXT:  Determining loop execution counts for: @foo5
137; CHECK-NEXT:  Loop %for.body: backedge-taken count is ((((-1 * (1 umin ((-1 * %start) + (%n smax %start))))<nuw><nsw> + (-1 * %start) + (%n smax %start)) /u (1 umax %s)) + (1 umin ((-1 * %start) + (%n smax %start))))
138; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -1
139; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is ((((-1 * (1 umin ((-1 * %start) + (%n smax %start))))<nuw><nsw> + (-1 * %start) + (%n smax %start)) /u (1 umax %s)) + (1 umin ((-1 * %start) + (%n smax %start))))
140; CHECK-NEXT:  Loop %for.body: Trip multiple is 1
141;
142entry:
143  br label %for.body
144
145for.body:                                         ; preds = %entry, %for.body
146  %i.05 = phi i32 [ %add, %for.body ], [ %start, %entry ]
147  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
148  %0 = load i32, ptr %arrayidx, align 4
149  %inc = add nsw i32 %0, 1
150  store i32 %inc, ptr %arrayidx, align 4
151  %add = add nsw i32 %i.05, %s
152  %cmp = icmp slt i32 %i.05, %n
153  br i1 %cmp, label %for.body, label %for.end
154
155for.end:                                          ; preds = %for.body, %entry
156  ret void
157}
158
159; FIXME: Currently we are more conservative for known zero stride than
160; for unknown but potentially zero stride.
161; Note that this function is well defined only when %n <=s 0
162define void @zero_stride(ptr nocapture %A, i32 %n) {
163;
164; CHECK-LABEL: 'zero_stride'
165; CHECK-NEXT:  Determining loop execution counts for: @zero_stride
166; CHECK-NEXT:  Loop %for.body: Unpredictable backedge-taken count.
167; CHECK-NEXT:  Loop %for.body: Unpredictable constant max backedge-taken count.
168; CHECK-NEXT:  Loop %for.body: Unpredictable symbolic max backedge-taken count.
169;
170entry:
171  br label %for.body
172
173for.body:                                         ; preds = %entry, %for.body
174  %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
175  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
176  %0 = load i32, ptr %arrayidx, align 4
177  %inc = add nsw i32 %0, 1
178  store i32 %inc, ptr %arrayidx, align 4
179  %add = add nsw i32 %i.05, 0
180  %cmp = icmp slt i32 %add, %n
181  br i1 %cmp, label %for.body, label %for.end, !llvm.loop !8
182
183for.end:                                          ; preds = %for.body, %entry
184  ret void
185}
186
187; Note that this function will always execute undefined behavior and thus
188; any value is valid for a backedge taken count.
189define void @zero_stride_ub(ptr nocapture %A) {
190;
191; CHECK-LABEL: 'zero_stride_ub'
192; CHECK-NEXT:  Determining loop execution counts for: @zero_stride_ub
193; CHECK-NEXT:  Loop %for.body: Unpredictable backedge-taken count.
194; CHECK-NEXT:  Loop %for.body: Unpredictable constant max backedge-taken count.
195; CHECK-NEXT:  Loop %for.body: Unpredictable symbolic max backedge-taken count.
196;
197entry:
198  br label %for.body
199
200for.body:                                         ; preds = %entry, %for.body
201  %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
202  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
203  %0 = load i32, ptr %arrayidx, align 4
204  %inc = add nsw i32 %0, 1
205  store i32 %inc, ptr %arrayidx, align 4
206  %add = add nsw i32 %i.05, 0
207  %cmp = icmp slt i32 %add, 2
208  br i1 %cmp, label %for.body, label %for.end, !llvm.loop !8
209
210for.end:                                          ; preds = %for.body, %entry
211  ret void
212}
213
214; When %zero = 0, this loop is only well defined if %n < 0 and thus BTC = 0.
215
216define void @zero_stride_symbolic(ptr nocapture %A, i32 %n, i32 %zero) {
217;
218; CHECK-LABEL: 'zero_stride_symbolic'
219; CHECK-NEXT:  Determining loop execution counts for: @zero_stride_symbolic
220; CHECK-NEXT:  Loop %for.body: backedge-taken count is ((((-1 * (1 umin ((-1 * %zero) + (%n smax %zero))))<nuw><nsw> + (-1 * %zero) + (%n smax %zero)) /u (1 umax %zero)) + (1 umin ((-1 * %zero) + (%n smax %zero))))
221; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -1
222; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is ((((-1 * (1 umin ((-1 * %zero) + (%n smax %zero))))<nuw><nsw> + (-1 * %zero) + (%n smax %zero)) /u (1 umax %zero)) + (1 umin ((-1 * %zero) + (%n smax %zero))))
223; CHECK-NEXT:  Loop %for.body: Trip multiple is 1
224;
225entry:
226  br label %for.body
227
228for.body:                                         ; preds = %entry, %for.body
229  %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
230  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
231  %0 = load i32, ptr %arrayidx, align 4
232  %inc = add nsw i32 %0, 1
233  store i32 %inc, ptr %arrayidx, align 4
234  %add = add nsw i32 %i.05, %zero
235  %cmp = icmp slt i32 %add, %n
236  br i1 %cmp, label %for.body, label %for.end, !llvm.loop !8
237
238for.end:                                          ; preds = %for.body, %entry
239  ret void
240}
241
242
243
244define void @zero_stride_varying_rhs(ptr nocapture %A, ptr %n_p, i32 %zero) {
245;
246; CHECK-LABEL: 'zero_stride_varying_rhs'
247; CHECK-NEXT:  Determining loop execution counts for: @zero_stride_varying_rhs
248; CHECK-NEXT:  Loop %for.body: Unpredictable backedge-taken count.
249; CHECK-NEXT:  Loop %for.body: Unpredictable constant max backedge-taken count.
250; CHECK-NEXT:  Loop %for.body: Unpredictable symbolic max backedge-taken count.
251;
252entry:
253  br label %for.body
254
255for.body:                                         ; preds = %entry, %for.body
256  %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
257  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
258  %0 = load i32, ptr %arrayidx, align 4
259  %inc = add nsw i32 %0, 1
260  store i32 %inc, ptr %arrayidx, align 4
261  %add = add nsw i32 %i.05, %zero
262  %n = load i32, ptr %n_p
263  %cmp = icmp slt i32 %add, %n
264  br i1 %cmp, label %for.body, label %for.end, !llvm.loop !8
265
266for.end:                                          ; preds = %for.body, %entry
267  ret void
268}
269
270define void @ne_nsw_pos_step(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
271;
272; CHECK-LABEL: 'ne_nsw_pos_step'
273; CHECK-NEXT:  Determining loop execution counts for: @ne_nsw_pos_step
274; CHECK-NEXT:  Loop %for.body: backedge-taken count is (((-1 * %s) + %n) /u %s)
275; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -1
276; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (((-1 * %s) + %n) /u %s)
277; CHECK-NEXT:  Loop %for.body: Trip multiple is 1
278;
279entry:
280  %pos_step = icmp sgt i32 %s, 0
281  call void @llvm.assume(i1 %pos_step)
282  %cmp4 = icmp sgt i32 %n, 0
283  br i1 %cmp4, label %for.body, label %for.end
284
285for.body:                                         ; preds = %entry, %for.body
286  %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
287  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
288  %0 = load i32, ptr %arrayidx, align 4
289  %inc = add nsw i32 %0, 1
290  store i32 %inc, ptr %arrayidx, align 4
291  %add = add nsw i32 %i.05, %s
292  %cmp = icmp ne i32 %add, %n
293  br i1 %cmp, label %for.body, label %for.end
294
295for.end:                                          ; preds = %for.body, %entry
296  ret void
297}
298
299define void @ne_nsw_neg_step(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
300;
301; CHECK-LABEL: 'ne_nsw_neg_step'
302; CHECK-NEXT:  Determining loop execution counts for: @ne_nsw_neg_step
303; CHECK-NEXT:  Loop %for.body: backedge-taken count is (((-1 * %n) + %s) /u (-1 * %s))
304; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -2
305; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (((-1 * %n) + %s) /u (-1 * %s))
306; CHECK-NEXT:  Loop %for.body: Trip multiple is 1
307;
308entry:
309  %neg_step = icmp slt i32 %s, 0
310  call void @llvm.assume(i1 %neg_step)
311  %cmp4 = icmp sgt i32 %n, 0
312  br i1 %cmp4, label %for.body, label %for.end
313
314for.body:                                         ; preds = %entry, %for.body
315  %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
316  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
317  %0 = load i32, ptr %arrayidx, align 4
318  %inc = add nsw i32 %0, 1
319  store i32 %inc, ptr %arrayidx, align 4
320  %add = add nsw i32 %i.05, %s
321  %cmp = icmp ne i32 %add, %n
322  br i1 %cmp, label %for.body, label %for.end
323
324for.end:                                          ; preds = %for.body, %entry
325  ret void
326}
327
328define void @ne_nsw_nonneg_step(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
329;
330; CHECK-LABEL: 'ne_nsw_nonneg_step'
331; CHECK-NEXT:  Determining loop execution counts for: @ne_nsw_nonneg_step
332; CHECK-NEXT:  Loop %for.body: backedge-taken count is (((-1 * %s) + %n) /u %s)
333; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -1
334; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (((-1 * %s) + %n) /u %s)
335; CHECK-NEXT:  Loop %for.body: Trip multiple is 1
336;
337entry:
338  %nonneg_step = icmp sge i32 %s, 0
339  call void @llvm.assume(i1 %nonneg_step)
340  %cmp4 = icmp sgt i32 %n, 0
341  br i1 %cmp4, label %for.body, label %for.end
342
343for.body:                                         ; preds = %entry, %for.body
344  %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
345  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
346  %0 = load i32, ptr %arrayidx, align 4
347  %inc = add nsw i32 %0, 1
348  store i32 %inc, ptr %arrayidx, align 4
349  %add = add nsw i32 %i.05, %s
350  %cmp = icmp ne i32 %add, %n
351  br i1 %cmp, label %for.body, label %for.end
352
353for.end:                                          ; preds = %for.body, %entry
354  ret void
355}
356
357define void @ne_nsw_unknown_step(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
358;
359; CHECK-LABEL: 'ne_nsw_unknown_step'
360; CHECK-NEXT:  Determining loop execution counts for: @ne_nsw_unknown_step
361; CHECK-NEXT:  Loop %for.body: Unpredictable backedge-taken count.
362; CHECK-NEXT:  Loop %for.body: Unpredictable constant max backedge-taken count.
363; CHECK-NEXT:  Loop %for.body: Unpredictable symbolic max backedge-taken count.
364;
365entry:
366  %cmp4 = icmp sgt i32 %n, 0
367  br i1 %cmp4, label %for.body, label %for.end
368
369for.body:                                         ; preds = %entry, %for.body
370  %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
371  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
372  %0 = load i32, ptr %arrayidx, align 4
373  %inc = add nsw i32 %0, 1
374  store i32 %inc, ptr %arrayidx, align 4
375  %add = add nsw i32 %i.05, %s
376  %cmp = icmp ne i32 %add, %n
377  br i1 %cmp, label %for.body, label %for.end
378
379for.end:                                          ; preds = %for.body, %entry
380  ret void
381}
382
383define void @ne_nuw_pos_step(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
384;
385; CHECK-LABEL: 'ne_nuw_pos_step'
386; CHECK-NEXT:  Determining loop execution counts for: @ne_nuw_pos_step
387; CHECK-NEXT:  Loop %for.body: backedge-taken count is (((-1 * %s) + %n) /u %s)
388; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -1
389; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (((-1 * %s) + %n) /u %s)
390; CHECK-NEXT:  Loop %for.body: Trip multiple is 1
391;
392entry:
393  %pos_step = icmp sgt i32 %s, 0
394  call void @llvm.assume(i1 %pos_step)
395  %cmp4 = icmp sgt i32 %n, 0
396  br i1 %cmp4, label %for.body, label %for.end
397
398for.body:                                         ; preds = %entry, %for.body
399  %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
400  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
401  %0 = load i32, ptr %arrayidx, align 4
402  %inc = add nuw i32 %0, 1
403  store i32 %inc, ptr %arrayidx, align 4
404  %add = add nuw i32 %i.05, %s
405  %cmp = icmp ne i32 %add, %n
406  br i1 %cmp, label %for.body, label %for.end
407
408for.end:                                          ; preds = %for.body, %entry
409  ret void
410}
411
412define void @ne_nuw_neg_step(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
413;
414; CHECK-LABEL: 'ne_nuw_neg_step'
415; CHECK-NEXT:  Determining loop execution counts for: @ne_nuw_neg_step
416; CHECK-NEXT:  Loop %for.body: backedge-taken count is (((-1 * %n) + %s) /u (-1 * %s))
417; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -2
418; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (((-1 * %n) + %s) /u (-1 * %s))
419; CHECK-NEXT:  Loop %for.body: Trip multiple is 1
420;
421entry:
422  %neg_step = icmp slt i32 %s, 0
423  call void @llvm.assume(i1 %neg_step)
424  %cmp4 = icmp sgt i32 %n, 0
425  br i1 %cmp4, label %for.body, label %for.end
426
427for.body:                                         ; preds = %entry, %for.body
428  %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
429  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
430  %0 = load i32, ptr %arrayidx, align 4
431  %inc = add nuw i32 %0, 1
432  store i32 %inc, ptr %arrayidx, align 4
433  %add = add nuw i32 %i.05, %s
434  %cmp = icmp ne i32 %add, %n
435  br i1 %cmp, label %for.body, label %for.end
436
437for.end:                                          ; preds = %for.body, %entry
438  ret void
439}
440
441define void @ne_nuw_nonneg_step(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
442;
443; CHECK-LABEL: 'ne_nuw_nonneg_step'
444; CHECK-NEXT:  Determining loop execution counts for: @ne_nuw_nonneg_step
445; CHECK-NEXT:  Loop %for.body: backedge-taken count is (((-1 * %s) + %n) /u %s)
446; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -1
447; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (((-1 * %s) + %n) /u %s)
448; CHECK-NEXT:  Loop %for.body: Trip multiple is 1
449;
450entry:
451  %nonneg_step = icmp sge i32 %s, 0
452  call void @llvm.assume(i1 %nonneg_step)
453  %cmp4 = icmp sgt i32 %n, 0
454  br i1 %cmp4, label %for.body, label %for.end
455
456for.body:                                         ; preds = %entry, %for.body
457  %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
458  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
459  %0 = load i32, ptr %arrayidx, align 4
460  %inc = add nuw i32 %0, 1
461  store i32 %inc, ptr %arrayidx, align 4
462  %add = add nuw i32 %i.05, %s
463  %cmp = icmp ne i32 %add, %n
464  br i1 %cmp, label %for.body, label %for.end
465
466for.end:                                          ; preds = %for.body, %entry
467  ret void
468}
469
470define void @ne_nuw_unknown_step(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
471;
472; CHECK-LABEL: 'ne_nuw_unknown_step'
473; CHECK-NEXT:  Determining loop execution counts for: @ne_nuw_unknown_step
474; CHECK-NEXT:  Loop %for.body: Unpredictable backedge-taken count.
475; CHECK-NEXT:  Loop %for.body: Unpredictable constant max backedge-taken count.
476; CHECK-NEXT:  Loop %for.body: Unpredictable symbolic max backedge-taken count.
477;
478entry:
479  %cmp4 = icmp sgt i32 %n, 0
480  br i1 %cmp4, label %for.body, label %for.end
481
482for.body:                                         ; preds = %entry, %for.body
483  %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
484  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
485  %0 = load i32, ptr %arrayidx, align 4
486  %inc = add nuw i32 %0, 1
487  store i32 %inc, ptr %arrayidx, align 4
488  %add = add nuw i32 %i.05, %s
489  %cmp = icmp ne i32 %add, %n
490  br i1 %cmp, label %for.body, label %for.end
491
492for.end:                                          ; preds = %for.body, %entry
493  ret void
494}
495
496
497declare void @llvm.assume(i1)
498
499!8 = distinct !{!8, !9}
500!9 = !{!"llvm.loop.mustprogress"}
501