1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
6 define void @iv_known_non_negative_constant_trip_count() {
7 ; CHECK-LABEL: @iv_known_non_negative_constant_trip_count(
9 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
11 ; CHECK-NEXT: [[IV:%.*]] = phi i8 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
12 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[IV]], 2
13 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP_LATCH]], label [[EXIT_1:%.*]]
15 ; CHECK-NEXT: call void @use(i1 true)
16 ; CHECK-NEXT: call void @use(i1 true)
17 ; CHECK-NEXT: call void @use(i1 false)
18 ; CHECK-NEXT: call void @use(i1 false)
19 ; CHECK-NEXT: call void @use(i1 false)
20 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i8 [[IV]], 1
21 ; CHECK-NEXT: br label [[LOOP_HEADER]]
23 ; CHECK-NEXT: ret void
29 %iv = phi i8 [ 0, %entry ], [ %iv.next, %loop.latch ]
30 %cmp = icmp slt i8 %iv, 2
31 br i1 %cmp, label %loop.latch, label %exit.1
34 %t.1 = icmp ugt i8 2, %iv
35 call void @use(i1 %t.1)
36 %t.2 = icmp sgt i8 2, %iv
37 call void @use(i1 %t.2)
38 %f.1 = icmp ule i8 2, %iv
39 call void @use(i1 %f.1)
40 %f.2 = icmp sle i8 2, %iv
41 call void @use(i1 %f.2)
42 %c.0 = icmp ugt i8 %iv, 2
43 call void @use(i1 %c.0)
44 %iv.next = add nuw nsw i8 %iv, 1
51 define void @iv_known_non_negative_constant_trip_count_no_nsw_flag(i8 %N) {
52 ; CHECK-LABEL: @iv_known_non_negative_constant_trip_count_no_nsw_flag(
54 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
56 ; CHECK-NEXT: [[IV:%.*]] = phi i8 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
57 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[IV]], 2
58 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP_LATCH]], label [[EXIT_1:%.*]]
60 ; CHECK-NEXT: [[T_1:%.*]] = icmp ugt i8 [[N:%.*]], [[IV]]
61 ; CHECK-NEXT: call void @use(i1 [[T_1]])
62 ; CHECK-NEXT: [[T_2:%.*]] = icmp sgt i8 [[N]], [[IV]]
63 ; CHECK-NEXT: call void @use(i1 [[T_2]])
64 ; CHECK-NEXT: [[F_1:%.*]] = icmp ule i8 [[N]], [[IV]]
65 ; CHECK-NEXT: call void @use(i1 [[F_1]])
66 ; CHECK-NEXT: [[F_2:%.*]] = icmp sle i8 [[N]], [[IV]]
67 ; CHECK-NEXT: call void @use(i1 [[F_2]])
68 ; CHECK-NEXT: [[C_0:%.*]] = icmp ugt i8 [[IV]], 2
69 ; CHECK-NEXT: call void @use(i1 [[C_0]])
70 ; CHECK-NEXT: [[IV_NEXT]] = add nuw i8 [[IV]], 1
71 ; CHECK-NEXT: br label [[LOOP_HEADER]]
73 ; CHECK-NEXT: ret void
79 %iv = phi i8 [ 0, %entry ], [ %iv.next, %loop.latch ]
80 %cmp = icmp slt i8 %iv, 2
81 br i1 %cmp, label %loop.latch, label %exit.1
84 %t.1 = icmp ugt i8 %N, %iv
85 call void @use(i1 %t.1)
86 %t.2 = icmp sgt i8 %N, %iv
87 call void @use(i1 %t.2)
88 %f.1 = icmp ule i8 %N, %iv
89 call void @use(i1 %f.1)
90 %f.2 = icmp sle i8 %N, %iv
91 call void @use(i1 %f.2)
92 %c.0 = icmp ugt i8 %iv, 2
93 call void @use(i1 %c.0)
94 %iv.next = add nuw i8 %iv, 1
101 define void @iv_known_non_negative_variable_trip_count(i8 %N) {
102 ; CHECK-LABEL: @iv_known_non_negative_variable_trip_count(
104 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
105 ; CHECK: loop.header:
106 ; CHECK-NEXT: [[IV:%.*]] = phi i8 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
107 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[IV]], [[N:%.*]]
108 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP_LATCH]], label [[EXIT_1:%.*]]
110 ; CHECK-NEXT: call void @use(i1 true)
111 ; CHECK-NEXT: call void @use(i1 true)
112 ; CHECK-NEXT: call void @use(i1 false)
113 ; CHECK-NEXT: call void @use(i1 false)
114 ; CHECK-NEXT: [[C_0:%.*]] = icmp ugt i8 [[IV]], 2
115 ; CHECK-NEXT: call void @use(i1 [[C_0]])
116 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i8 [[IV]], 1
117 ; CHECK-NEXT: br label [[LOOP_HEADER]]
119 ; CHECK-NEXT: ret void
122 br label %loop.header
125 %iv = phi i8 [ 0, %entry ], [ %iv.next, %loop.latch ]
126 %cmp = icmp slt i8 %iv, %N
127 br i1 %cmp, label %loop.latch, label %exit.1
130 %t.1 = icmp ugt i8 %N, %iv
131 call void @use(i1 %t.1)
132 %t.2 = icmp sgt i8 %N, %iv
133 call void @use(i1 %t.2)
134 %f.1 = icmp ule i8 %N, %iv
135 call void @use(i1 %f.1)
136 %f.2 = icmp sle i8 %N, %iv
137 call void @use(i1 %f.2)
138 %c.0 = icmp ugt i8 %iv, 2
139 call void @use(i1 %c.0)
140 %iv.next = add nuw nsw i8 %iv, 1
141 br label %loop.header
147 define void @iv_may_signed_wrap_variable_trip_count(i8 %N) {
148 ; CHECK-LABEL: @iv_may_signed_wrap_variable_trip_count(
150 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
151 ; CHECK: loop.header:
152 ; CHECK-NEXT: [[IV:%.*]] = phi i8 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
153 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[IV]], [[N:%.*]]
154 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP_LATCH]], label [[EXIT_1:%.*]]
156 ; CHECK-NEXT: [[T_1:%.*]] = icmp ugt i8 [[N]], [[IV]]
157 ; CHECK-NEXT: call void @use(i1 [[T_1]])
158 ; CHECK-NEXT: call void @use(i1 true)
159 ; CHECK-NEXT: [[F_1:%.*]] = icmp ule i8 [[N]], [[IV]]
160 ; CHECK-NEXT: call void @use(i1 [[F_1]])
161 ; CHECK-NEXT: call void @use(i1 false)
162 ; CHECK-NEXT: [[C_0:%.*]] = icmp ugt i8 [[IV]], 2
163 ; CHECK-NEXT: call void @use(i1 [[C_0]])
164 ; CHECK-NEXT: [[IV_NEXT]] = add nuw i8 [[IV]], 1
165 ; CHECK-NEXT: br label [[LOOP_HEADER]]
167 ; CHECK-NEXT: ret void
170 br label %loop.header
173 %iv = phi i8 [ 0, %entry ], [ %iv.next, %loop.latch ]
174 %cmp = icmp slt i8 %iv, %N
175 br i1 %cmp, label %loop.latch, label %exit.1
178 %t.1 = icmp ugt i8 %N, %iv
179 call void @use(i1 %t.1)
180 %t.2 = icmp sgt i8 %N, %iv
181 call void @use(i1 %t.2)
182 %f.1 = icmp ule i8 %N, %iv
183 call void @use(i1 %f.1)
184 %f.2 = icmp sle i8 %N, %iv
185 call void @use(i1 %f.2)
186 %c.0 = icmp ugt i8 %iv, 2
187 call void @use(i1 %c.0)
188 %iv.next = add nuw i8 %iv, 1
189 br label %loop.header
195 define void @iv_known_non_negative_iv_constant_trip_count_sgt() {
196 ; CHECK-LABEL: @iv_known_non_negative_iv_constant_trip_count_sgt(
198 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
199 ; CHECK: loop.header:
200 ; CHECK-NEXT: [[IV:%.*]] = phi i8 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
201 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 2, [[IV]]
202 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP_LATCH]], label [[EXIT_1:%.*]]
204 ; CHECK-NEXT: call void @use(i1 false)
205 ; CHECK-NEXT: call void @use(i1 true)
206 ; CHECK-NEXT: call void @use(i1 false)
207 ; CHECK-NEXT: call void @use(i1 false)
208 ; CHECK-NEXT: call void @use(i1 false)
209 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i8 [[IV]], 1
210 ; CHECK-NEXT: br label [[LOOP_HEADER]]
212 ; CHECK-NEXT: ret void
215 br label %loop.header
218 %iv = phi i8 [ 0, %entry ], [ %iv.next, %loop.latch ]
219 %cmp = icmp sgt i8 2, %iv
220 br i1 %cmp, label %loop.latch, label %exit.1
223 %t.1 = icmp ugt i8 %iv, 2
224 call void @use(i1 %t.1)
225 %t.2 = icmp sgt i8 2, %iv
226 call void @use(i1 %t.2)
227 %f.1 = icmp ule i8 2, %iv
228 call void @use(i1 %f.1)
229 %f.2 = icmp sle i8 2, %iv
230 call void @use(i1 %f.2)
231 %c.0 = icmp ugt i8 %iv, 2
232 call void @use(i1 %c.0)
233 %iv.next = add nsw nuw i8 %iv, 1
234 br label %loop.header
240 define void @iv_known_non_negative_iv_variable_trip_count_sgt(i8 %N) {
241 ; CHECK-LABEL: @iv_known_non_negative_iv_variable_trip_count_sgt(
243 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
244 ; CHECK: loop.header:
245 ; CHECK-NEXT: [[IV:%.*]] = phi i8 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
246 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[N:%.*]], [[IV]]
247 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP_LATCH]], label [[EXIT_1:%.*]]
249 ; CHECK-NEXT: call void @use(i1 false)
250 ; CHECK-NEXT: call void @use(i1 true)
251 ; CHECK-NEXT: call void @use(i1 false)
252 ; CHECK-NEXT: call void @use(i1 false)
253 ; CHECK-NEXT: [[C_0:%.*]] = icmp ugt i8 [[IV]], 2
254 ; CHECK-NEXT: call void @use(i1 [[C_0]])
255 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i8 [[IV]], 1
256 ; CHECK-NEXT: br label [[LOOP_HEADER]]
258 ; CHECK-NEXT: ret void
261 br label %loop.header
264 %iv = phi i8 [ 0, %entry ], [ %iv.next, %loop.latch ]
265 %cmp = icmp sgt i8 %N, %iv
266 br i1 %cmp, label %loop.latch, label %exit.1
269 %t.1 = icmp ugt i8 %iv, %N
270 call void @use(i1 %t.1)
271 %t.2 = icmp sgt i8 %N, %iv
272 call void @use(i1 %t.2)
273 %f.1 = icmp ule i8 %N, %iv
274 call void @use(i1 %f.1)
275 %f.2 = icmp sle i8 %N, %iv
276 call void @use(i1 %f.2)
277 %c.0 = icmp ugt i8 %iv, 2
278 call void @use(i1 %c.0)
279 %iv.next = add nsw nuw i8 %iv, 1
280 br label %loop.header
287 define void @iv_known_non_negative_iv_variable_trip_count_sgt_ops_flipped(i8 %N) {
288 ; CHECK-LABEL: @iv_known_non_negative_iv_variable_trip_count_sgt_ops_flipped(
290 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
291 ; CHECK: loop.header:
292 ; CHECK-NEXT: [[IV:%.*]] = phi i8 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
293 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[IV]], [[N:%.*]]
294 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP_LATCH]], label [[EXIT_1:%.*]]
296 ; CHECK-NEXT: [[T_1:%.*]] = icmp ugt i8 [[IV]], [[N]]
297 ; CHECK-NEXT: call void @use(i1 [[T_1]])
298 ; CHECK-NEXT: call void @use(i1 true)
299 ; CHECK-NEXT: [[F_1:%.*]] = icmp ule i8 [[N]], [[IV]]
300 ; CHECK-NEXT: call void @use(i1 [[F_1]])
301 ; CHECK-NEXT: call void @use(i1 true)
302 ; CHECK-NEXT: [[C_0:%.*]] = icmp ugt i8 [[IV]], 2
303 ; CHECK-NEXT: call void @use(i1 [[C_0]])
304 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i8 [[IV]], 1
305 ; CHECK-NEXT: br label [[LOOP_HEADER]]
307 ; CHECK-NEXT: ret void
310 br label %loop.header
313 %iv = phi i8 [ 0, %entry ], [ %iv.next, %loop.latch ]
314 %cmp = icmp sgt i8 %iv, %N
315 br i1 %cmp, label %loop.latch, label %exit.1
318 %t.1 = icmp ugt i8 %iv, %N
319 call void @use(i1 %t.1)
320 %t.2 = icmp sgt i8 %iv, %N
321 call void @use(i1 %t.2)
322 %f.1 = icmp ule i8 %N, %iv
323 call void @use(i1 %f.1)
324 %f.2 = icmp sle i8 %N, %iv
325 call void @use(i1 %f.2)
326 %c.0 = icmp ugt i8 %iv, 2
327 call void @use(i1 %c.0)
328 %iv.next = add nsw nuw i8 %iv, 1
329 br label %loop.header
335 define void @iv_known_non_negative_iv_constant_trip_count_sge() {
336 ; CHECK-LABEL: @iv_known_non_negative_iv_constant_trip_count_sge(
338 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
339 ; CHECK: loop.header:
340 ; CHECK-NEXT: [[IV:%.*]] = phi i8 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
341 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 2, [[IV]]
342 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP_LATCH]], label [[EXIT_1:%.*]]
344 ; CHECK-NEXT: call void @use(i1 true)
345 ; CHECK-NEXT: call void @use(i1 true)
346 ; CHECK-NEXT: call void @use(i1 false)
347 ; CHECK-NEXT: call void @use(i1 false)
348 ; CHECK-NEXT: call void @use(i1 false)
349 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i8 [[IV]], 1
350 ; CHECK-NEXT: br label [[LOOP_HEADER]]
352 ; CHECK-NEXT: ret void
355 br label %loop.header
358 %iv = phi i8 [ 0, %entry ], [ %iv.next, %loop.latch ]
359 %cmp = icmp sge i8 2, %iv
360 br i1 %cmp, label %loop.latch, label %exit.1
363 %t.1 = icmp uge i8 2, %iv
364 call void @use(i1 %t.1)
365 %t.2 = icmp sge i8 2, %iv
366 call void @use(i1 %t.2)
367 %f.1 = icmp ult i8 2, %iv
368 call void @use(i1 %f.1)
369 %f.2 = icmp slt i8 2, %iv
370 call void @use(i1 %f.2)
371 %c.0 = icmp ugt i8 %iv, 2
372 call void @use(i1 %c.0)
373 %iv.next = add nsw nuw i8 %iv, 1
374 br label %loop.header
380 define void @iv_known_non_negative_iv_variable_trip_count_sge(i8 %N) {
381 ; CHECK-LABEL: @iv_known_non_negative_iv_variable_trip_count_sge(
383 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
384 ; CHECK: loop.header:
385 ; CHECK-NEXT: [[IV:%.*]] = phi i8 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
386 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[N:%.*]], [[IV]]
387 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP_LATCH]], label [[EXIT_1:%.*]]
389 ; CHECK-NEXT: call void @use(i1 true)
390 ; CHECK-NEXT: call void @use(i1 true)
391 ; CHECK-NEXT: call void @use(i1 false)
392 ; CHECK-NEXT: call void @use(i1 false)
393 ; CHECK-NEXT: [[C_0:%.*]] = icmp ugt i8 [[IV]], 2
394 ; CHECK-NEXT: call void @use(i1 [[C_0]])
395 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i8 [[IV]], 1
396 ; CHECK-NEXT: br label [[LOOP_HEADER]]
398 ; CHECK-NEXT: ret void
401 br label %loop.header
404 %iv = phi i8 [ 0, %entry ], [ %iv.next, %loop.latch ]
405 %cmp = icmp sge i8 %N, %iv
406 br i1 %cmp, label %loop.latch, label %exit.1
409 %t.1 = icmp uge i8 %N, %iv
410 call void @use(i1 %t.1)
411 %t.2 = icmp sge i8 %N, %iv
412 call void @use(i1 %t.2)
413 %f.1 = icmp ult i8 %N, %iv
414 call void @use(i1 %f.1)
415 %f.2 = icmp slt i8 %N, %iv
416 call void @use(i1 %f.2)
417 %c.0 = icmp ugt i8 %iv, 2
418 call void @use(i1 %c.0)
419 %iv.next = add nsw nuw i8 %iv, 1
420 br label %loop.header
426 define void @iv_known_non_negative_iv_variable_trip_count_sge_operands_swapped(i8 %N) {
427 ; CHECK-LABEL: @iv_known_non_negative_iv_variable_trip_count_sge_operands_swapped(
429 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
430 ; CHECK: loop.header:
431 ; CHECK-NEXT: [[IV:%.*]] = phi i8 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
432 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[IV]], [[N:%.*]]
433 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP_LATCH]], label [[EXIT_1:%.*]]
435 ; CHECK-NEXT: [[T_1:%.*]] = icmp uge i8 [[N]], [[IV]]
436 ; CHECK-NEXT: call void @use(i1 [[T_1]])
437 ; CHECK-NEXT: [[T_2:%.*]] = icmp sge i8 [[N]], [[IV]]
438 ; CHECK-NEXT: call void @use(i1 [[T_2]])
439 ; CHECK-NEXT: [[F_1:%.*]] = icmp ult i8 [[N]], [[IV]]
440 ; CHECK-NEXT: call void @use(i1 [[F_1]])
441 ; CHECK-NEXT: [[F_2:%.*]] = icmp slt i8 [[N]], [[IV]]
442 ; CHECK-NEXT: call void @use(i1 [[F_2]])
443 ; CHECK-NEXT: [[C_0:%.*]] = icmp ugt i8 [[IV]], 2
444 ; CHECK-NEXT: call void @use(i1 [[C_0]])
445 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i8 [[IV]], 1
446 ; CHECK-NEXT: br label [[LOOP_HEADER]]
448 ; CHECK-NEXT: ret void
451 br label %loop.header
454 %iv = phi i8 [ 0, %entry ], [ %iv.next, %loop.latch ]
455 %cmp = icmp sge i8 %iv, %N
456 br i1 %cmp, label %loop.latch, label %exit.1
459 %t.1 = icmp uge i8 %N, %iv
460 call void @use(i1 %t.1)
461 %t.2 = icmp sge i8 %N, %iv
462 call void @use(i1 %t.2)
463 %f.1 = icmp ult i8 %N, %iv
464 call void @use(i1 %f.1)
465 %f.2 = icmp slt i8 %N, %iv
466 call void @use(i1 %f.2)
467 %c.0 = icmp ugt i8 %iv, 2
468 call void @use(i1 %c.0)
469 %iv.next = add nsw nuw i8 %iv, 1
470 br label %loop.header