1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -constraint-elimination -S %s | FileCheck %s
4 define void @test.not.uge.ult(i8 %start, i8 %low, i8 %high) {
5 ; CHECK-LABEL: @test.not.uge.ult(
7 ; CHECK-NEXT: [[ADD_PTR_I:%.*]] = add nuw i8 [[START:%.*]], 3
8 ; CHECK-NEXT: [[C_1:%.*]] = icmp uge i8 [[ADD_PTR_I]], [[HIGH:%.*]]
9 ; CHECK-NEXT: br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
11 ; CHECK-NEXT: ret void
13 ; CHECK-NEXT: [[T_0:%.*]] = icmp ult i8 [[START]], [[HIGH]]
14 ; CHECK-NEXT: call void @use(i1 true)
15 ; CHECK-NEXT: [[START_1:%.*]] = add nuw i8 [[START]], 1
16 ; CHECK-NEXT: [[T_1:%.*]] = icmp ult i8 [[START_1]], [[HIGH]]
17 ; CHECK-NEXT: call void @use(i1 true)
18 ; CHECK-NEXT: [[START_2:%.*]] = add nuw i8 [[START]], 2
19 ; CHECK-NEXT: [[T_2:%.*]] = icmp ult i8 [[START_2]], [[HIGH]]
20 ; CHECK-NEXT: call void @use(i1 true)
21 ; CHECK-NEXT: [[START_3:%.*]] = add nuw i8 [[START]], 3
22 ; CHECK-NEXT: [[T_3:%.*]] = icmp ult i8 [[START_3]], [[HIGH]]
23 ; CHECK-NEXT: call void @use(i1 true)
24 ; CHECK-NEXT: [[START_4:%.*]] = add nuw i8 [[START]], 4
25 ; CHECK-NEXT: [[C_4:%.*]] = icmp ult i8 [[START_4]], [[HIGH]]
26 ; CHECK-NEXT: call void @use(i1 [[C_4]])
27 ; CHECK-NEXT: ret void
30 %add.ptr.i = add nuw i8 %start, 3
31 %c.1 = icmp uge i8 %add.ptr.i, %high
32 br i1 %c.1, label %if.then, label %if.end
34 if.then: ; preds = %entry
37 if.end: ; preds = %entry
38 %t.0 = icmp ult i8 %start, %high
39 call void @use(i1 %t.0)
40 %start.1 = add nuw i8 %start, 1
41 %t.1 = icmp ult i8 %start.1, %high
42 call void @use(i1 %t.1)
43 %start.2 = add nuw i8 %start, 2
44 %t.2 = icmp ult i8 %start.2, %high
45 call void @use(i1 %t.2)
46 %start.3 = add nuw i8 %start, 3
47 %t.3 = icmp ult i8 %start.3, %high
48 call void @use(i1 %t.3)
49 %start.4 = add nuw i8 %start, 4
50 %c.4 = icmp ult i8 %start.4, %high
51 call void @use(i1 %c.4)
55 define void @test.not.uge.ule(i8 %start, i8 %low, i8 %high) {
56 ; CHECK-LABEL: @test.not.uge.ule(
58 ; CHECK-NEXT: [[ADD_PTR_I:%.*]] = add nuw i8 [[START:%.*]], 3
59 ; CHECK-NEXT: [[C_1:%.*]] = icmp uge i8 [[ADD_PTR_I]], [[HIGH:%.*]]
60 ; CHECK-NEXT: br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
62 ; CHECK-NEXT: ret void
64 ; CHECK-NEXT: [[T_0:%.*]] = icmp ule i8 [[START]], [[HIGH]]
65 ; CHECK-NEXT: call void @use(i1 true)
66 ; CHECK-NEXT: [[START_1:%.*]] = add nuw i8 [[START]], 1
67 ; CHECK-NEXT: [[T_1:%.*]] = icmp ule i8 [[START_1]], [[HIGH]]
68 ; CHECK-NEXT: call void @use(i1 true)
69 ; CHECK-NEXT: [[START_2:%.*]] = add nuw i8 [[START]], 2
70 ; CHECK-NEXT: [[T_2:%.*]] = icmp ule i8 [[START_2]], [[HIGH]]
71 ; CHECK-NEXT: call void @use(i1 true)
72 ; CHECK-NEXT: [[START_3:%.*]] = add nuw i8 [[START]], 3
73 ; CHECK-NEXT: [[T_3:%.*]] = icmp ule i8 [[START_3]], [[HIGH]]
74 ; CHECK-NEXT: call void @use(i1 true)
75 ; CHECK-NEXT: [[START_4:%.*]] = add nuw i8 [[START]], 4
76 ; CHECK-NEXT: [[T_4:%.*]] = icmp ule i8 [[START_4]], [[HIGH]]
77 ; CHECK-NEXT: call void @use(i1 true)
78 ; CHECK-NEXT: [[START_5:%.*]] = add nuw i8 [[START]], 5
79 ; CHECK-NEXT: [[C_5:%.*]] = icmp ule i8 [[START_5]], [[HIGH]]
80 ; CHECK-NEXT: call void @use(i1 [[C_5]])
81 ; CHECK-NEXT: ret void
84 %add.ptr.i = add nuw i8 %start, 3
85 %c.1 = icmp uge i8 %add.ptr.i, %high
86 br i1 %c.1, label %if.then, label %if.end
88 if.then: ; preds = %entry
91 if.end: ; preds = %entry
92 %t.0 = icmp ule i8 %start, %high
93 call void @use(i1 %t.0)
94 %start.1 = add nuw i8 %start, 1
95 %t.1 = icmp ule i8 %start.1, %high
96 call void @use(i1 %t.1)
97 %start.2 = add nuw i8 %start, 2
98 %t.2 = icmp ule i8 %start.2, %high
99 call void @use(i1 %t.2)
100 %start.3 = add nuw i8 %start, 3
101 %t.3 = icmp ule i8 %start.3, %high
102 call void @use(i1 %t.3)
103 %start.4 = add nuw i8 %start, 4
104 %t.4 = icmp ule i8 %start.4, %high
105 call void @use(i1 %t.4)
107 %start.5 = add nuw i8 %start, 5
108 %c.5 = icmp ule i8 %start.5, %high
109 call void @use(i1 %c.5)
114 define void @test.not.uge.ugt(i8 %start, i8 %low, i8 %high) {
115 ; CHECK-LABEL: @test.not.uge.ugt(
117 ; CHECK-NEXT: [[ADD_PTR_I:%.*]] = add nuw i8 [[START:%.*]], 3
118 ; CHECK-NEXT: [[C_1:%.*]] = icmp uge i8 [[ADD_PTR_I]], [[HIGH:%.*]]
119 ; CHECK-NEXT: br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
121 ; CHECK-NEXT: ret void
123 ; CHECK-NEXT: [[F_0:%.*]] = icmp ugt i8 [[START]], [[HIGH]]
124 ; CHECK-NEXT: call void @use(i1 false)
125 ; CHECK-NEXT: [[START_1:%.*]] = add nuw i8 [[START]], 1
126 ; CHECK-NEXT: [[F_1:%.*]] = icmp ugt i8 [[START_1]], [[HIGH]]
127 ; CHECK-NEXT: call void @use(i1 false)
128 ; CHECK-NEXT: [[START_2:%.*]] = add nuw i8 [[START]], 2
129 ; CHECK-NEXT: [[F_2:%.*]] = icmp ugt i8 [[START_2]], [[HIGH]]
130 ; CHECK-NEXT: call void @use(i1 false)
131 ; CHECK-NEXT: [[START_3:%.*]] = add nuw i8 [[START]], 3
132 ; CHECK-NEXT: [[F_3:%.*]] = icmp ugt i8 [[START_3]], [[HIGH]]
133 ; CHECK-NEXT: call void @use(i1 false)
134 ; CHECK-NEXT: [[START_4:%.*]] = add nuw i8 [[START]], 4
135 ; CHECK-NEXT: [[F_4:%.*]] = icmp ugt i8 [[START_4]], [[HIGH]]
136 ; CHECK-NEXT: call void @use(i1 false)
137 ; CHECK-NEXT: [[START_5:%.*]] = add nuw i8 [[START]], 5
138 ; CHECK-NEXT: [[C_5:%.*]] = icmp ugt i8 [[START_5]], [[HIGH]]
139 ; CHECK-NEXT: call void @use(i1 [[C_5]])
140 ; CHECK-NEXT: ret void
143 %add.ptr.i = add nuw i8 %start, 3
144 %c.1 = icmp uge i8 %add.ptr.i, %high
145 br i1 %c.1, label %if.then, label %if.end
147 if.then: ; preds = %entry
150 if.end: ; preds = %entry
151 %f.0 = icmp ugt i8 %start, %high
152 call void @use(i1 %f.0)
154 %start.1 = add nuw i8 %start, 1
155 %f.1 = icmp ugt i8 %start.1, %high
156 call void @use(i1 %f.1)
158 %start.2 = add nuw i8 %start, 2
159 %f.2 = icmp ugt i8 %start.2, %high
160 call void @use(i1 %f.2)
162 %start.3 = add nuw i8 %start, 3
163 %f.3 = icmp ugt i8 %start.3, %high
164 call void @use(i1 %f.3)
166 %start.4 = add nuw i8 %start, 4
167 %f.4 = icmp ugt i8 %start.4, %high
168 call void @use(i1 %f.4)
170 %start.5 = add nuw i8 %start, 5
171 %c.5 = icmp ugt i8 %start.5, %high
172 call void @use(i1 %c.5)
177 define void @test.not.uge.uge(i8 %start, i8 %low, i8 %high) {
178 ; CHECK-LABEL: @test.not.uge.uge(
180 ; CHECK-NEXT: [[ADD_PTR_I:%.*]] = add nuw i8 [[START:%.*]], 3
181 ; CHECK-NEXT: [[C_1:%.*]] = icmp uge i8 [[ADD_PTR_I]], [[HIGH:%.*]]
182 ; CHECK-NEXT: br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
184 ; CHECK-NEXT: ret void
186 ; CHECK-NEXT: [[F_0:%.*]] = icmp ugt i8 [[START]], [[HIGH]]
187 ; CHECK-NEXT: call void @use(i1 false)
188 ; CHECK-NEXT: [[START_1:%.*]] = add nuw i8 [[START]], 1
189 ; CHECK-NEXT: [[F_1:%.*]] = icmp uge i8 [[START_1]], [[HIGH]]
190 ; CHECK-NEXT: call void @use(i1 false)
191 ; CHECK-NEXT: [[START_2:%.*]] = add nuw i8 [[START]], 2
192 ; CHECK-NEXT: [[F_2:%.*]] = icmp uge i8 [[START_2]], [[HIGH]]
193 ; CHECK-NEXT: call void @use(i1 false)
194 ; CHECK-NEXT: [[START_3:%.*]] = add nuw i8 [[START]], 3
195 ; CHECK-NEXT: [[F_3:%.*]] = icmp uge i8 [[START_3]], [[HIGH]]
196 ; CHECK-NEXT: call void @use(i1 false)
197 ; CHECK-NEXT: [[START_4:%.*]] = add nuw i8 [[START]], 4
198 ; CHECK-NEXT: [[C_4:%.*]] = icmp uge i8 [[START_4]], [[HIGH]]
199 ; CHECK-NEXT: call void @use(i1 [[C_4]])
200 ; CHECK-NEXT: [[START_5:%.*]] = add nuw i8 [[START]], 5
201 ; CHECK-NEXT: [[C_5:%.*]] = icmp uge i8 [[START_5]], [[HIGH]]
202 ; CHECK-NEXT: call void @use(i1 [[C_5]])
203 ; CHECK-NEXT: ret void
206 %add.ptr.i = add nuw i8 %start, 3
207 %c.1 = icmp uge i8 %add.ptr.i, %high
208 br i1 %c.1, label %if.then, label %if.end
210 if.then: ; preds = %entry
213 if.end: ; preds = %entry
214 %f.0 = icmp ugt i8 %start, %high
215 call void @use(i1 %f.0)
217 %start.1 = add nuw i8 %start, 1
218 %f.1 = icmp uge i8 %start.1, %high
219 call void @use(i1 %f.1)
221 %start.2 = add nuw i8 %start, 2
222 %f.2 = icmp uge i8 %start.2, %high
223 call void @use(i1 %f.2)
225 %start.3 = add nuw i8 %start, 3
226 %f.3 = icmp uge i8 %start.3, %high
227 call void @use(i1 %f.3)
229 %start.4 = add nuw i8 %start, 4
230 %c.4 = icmp uge i8 %start.4, %high
231 call void @use(i1 %c.4)
233 %start.5 = add nuw i8 %start, 5
234 %c.5 = icmp uge i8 %start.5, %high
235 call void @use(i1 %c.5)
240 define void @test.decompose.nonconst(i8 %a, i8 %b, i8 %c, i8 %d) {
241 ; CHECK-LABEL: @test.decompose.nonconst(
243 ; CHECK-NEXT: [[C_0:%.*]] = icmp uge i8 [[A:%.*]], [[C:%.*]]
244 ; CHECK-NEXT: [[C_1:%.*]] = icmp uge i8 [[B:%.*]], [[C]]
245 ; CHECK-NEXT: [[AND_0:%.*]] = and i1 [[C_0]], [[C_1]]
246 ; CHECK-NEXT: br i1 [[AND_0]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
248 ; CHECK-NEXT: [[C_2:%.*]] = icmp uge i8 [[A]], 0
249 ; CHECK-NEXT: [[C_3:%.*]] = icmp uge i8 [[B]], 0
250 ; CHECK-NEXT: [[AND_1:%.*]] = and i1 [[C_2]], [[C_3]]
251 ; CHECK-NEXT: br i1 [[AND_1]], label [[IF_THEN_2:%.*]], label [[IF_END]]
253 ; CHECK-NEXT: [[ADD_0:%.*]] = add nuw i8 [[A]], [[B]]
254 ; CHECK-NEXT: [[T_0:%.*]] = icmp uge i8 [[ADD_0]], [[C]]
255 ; CHECK-NEXT: call void @use(i1 true)
256 ; CHECK-NEXT: [[ADD_1:%.*]] = add nuw i8 [[A]], [[A]]
257 ; CHECK-NEXT: [[T_1:%.*]] = icmp uge i8 [[ADD_0]], [[C]]
258 ; CHECK-NEXT: call void @use(i1 true)
259 ; CHECK-NEXT: [[ADD_2:%.*]] = add nuw i8 [[A]], [[D:%.*]]
260 ; CHECK-NEXT: [[C_4:%.*]] = icmp uge i8 [[ADD_2]], [[C]]
261 ; CHECK-NEXT: call void @use(i1 [[C_4]])
262 ; CHECK-NEXT: ret void
264 ; CHECK-NEXT: ret void
267 %c.0 = icmp uge i8 %a, %c
268 %c.1 = icmp uge i8 %b, %c
269 %and.0 = and i1 %c.0, %c.1
270 br i1 %and.0, label %if.then, label %if.end
272 if.then: ; preds = %entry
273 %c.2 = icmp uge i8 %a, 0
274 %c.3 = icmp uge i8 %b, 0
275 %and.1 = and i1 %c.2, %c.3
276 br i1 %and.1, label %if.then.2, label %if.end
279 %add.0 = add nuw i8 %a, %b
280 %t.0 = icmp uge i8 %add.0, %c
281 call void @use(i1 %t.0)
282 %add.1 = add nuw i8 %a, %a
283 %t.1 = icmp uge i8 %add.0, %c
284 call void @use(i1 %t.1)
285 %add.2 = add nuw i8 %a, %d
286 %c.4 = icmp uge i8 %add.2, %c
287 call void @use(i1 %c.4)
290 if.end: ; preds = %entry
294 define void @test.decompose.nonconst.no.null.check(i8 %a, i8 %b, i8 %c, i8 %d) {
295 ; CHECK-LABEL: @test.decompose.nonconst.no.null.check(
297 ; CHECK-NEXT: [[C_0:%.*]] = icmp uge i8 [[A:%.*]], [[C:%.*]]
298 ; CHECK-NEXT: [[C_1:%.*]] = icmp uge i8 [[B:%.*]], [[C]]
299 ; CHECK-NEXT: [[AND_0:%.*]] = and i1 [[C_0]], [[C_1]]
300 ; CHECK-NEXT: br i1 [[AND_0]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
302 ; CHECK-NEXT: [[ADD_0:%.*]] = add nuw i8 [[A]], [[B]]
303 ; CHECK-NEXT: [[T_0:%.*]] = icmp uge i8 [[ADD_0]], [[C]]
304 ; CHECK-NEXT: call void @use(i1 [[T_0]])
305 ; CHECK-NEXT: [[ADD_1:%.*]] = add nuw i8 [[A]], [[A]]
306 ; CHECK-NEXT: [[T_1:%.*]] = icmp uge i8 [[ADD_0]], [[C]]
307 ; CHECK-NEXT: call void @use(i1 [[T_1]])
308 ; CHECK-NEXT: [[ADD_2:%.*]] = add nuw i8 [[A]], [[D:%.*]]
309 ; CHECK-NEXT: [[C_4:%.*]] = icmp uge i8 [[ADD_2]], [[C]]
310 ; CHECK-NEXT: call void @use(i1 [[C_4]])
311 ; CHECK-NEXT: ret void
313 ; CHECK-NEXT: ret void
316 %c.0 = icmp uge i8 %a, %c
317 %c.1 = icmp uge i8 %b, %c
318 %and.0 = and i1 %c.0, %c.1
319 br i1 %and.0, label %if.then, label %if.end
321 if.then: ; preds = %entry
322 %add.0 = add nuw i8 %a, %b
323 %t.0 = icmp uge i8 %add.0, %c
324 call void @use(i1 %t.0)
325 %add.1 = add nuw i8 %a, %a
326 %t.1 = icmp uge i8 %add.0, %c
327 call void @use(i1 %t.1)
328 %add.2 = add nuw i8 %a, %d
329 %c.4 = icmp uge i8 %add.2, %c
330 call void @use(i1 %c.4)
333 if.end: ; preds = %entry
338 define i1 @test_n_must_ule_1_due_to_nuw(i8 %n, i8 %i) {
339 ; CHECK-LABEL: @test_n_must_ule_1_due_to_nuw(
341 ; CHECK-NEXT: [[SUB_N_1:%.*]] = add nuw i8 [[N:%.*]], -1
342 ; CHECK-NEXT: [[ADD:%.*]] = add nuw i8 [[I:%.*]], [[SUB_N_1]]
343 ; CHECK-NEXT: [[C_1:%.*]] = icmp uge i8 [[I]], [[ADD]]
344 ; CHECK-NEXT: br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
346 ; CHECK-NEXT: [[T:%.*]] = icmp ule i8 [[N]], 1
347 ; CHECK-NEXT: ret i1 [[T]]
349 ; CHECK-NEXT: [[F:%.*]] = icmp ule i8 [[N]], 1
350 ; CHECK-NEXT: ret i1 [[F]]
353 %sub.n.1 = add nuw i8 %n, -1
354 %add = add nuw i8 %i, %sub.n.1
355 %c.1 = icmp uge i8 %i, %add
356 br i1 %c.1, label %if.then, label %if.end
358 if.then: ; preds = %entry
359 %t = icmp ule i8 %n, 1
362 if.end: ; preds = %entry
363 %f = icmp ule i8 %n, 1
368 define i1 @test_n_unknown_missing_nuw(i8 %n, i8 %i) {
369 ; CHECK-LABEL: @test_n_unknown_missing_nuw(
371 ; CHECK-NEXT: [[SUB_N_1:%.*]] = add i8 [[N:%.*]], -1
372 ; CHECK-NEXT: [[ADD:%.*]] = add i8 [[I:%.*]], [[SUB_N_1]]
373 ; CHECK-NEXT: [[C_1:%.*]] = icmp uge i8 [[I]], [[ADD]]
374 ; CHECK-NEXT: br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
376 ; CHECK-NEXT: [[T:%.*]] = icmp ule i8 [[N]], 1
377 ; CHECK-NEXT: ret i1 [[T]]
379 ; CHECK-NEXT: [[F:%.*]] = icmp ule i8 [[N]], 1
380 ; CHECK-NEXT: ret i1 [[F]]
383 %sub.n.1 = add i8 %n, -1
384 %add = add i8 %i, %sub.n.1
385 %c.1 = icmp uge i8 %i, %add
386 br i1 %c.1, label %if.then, label %if.end
388 if.then: ; preds = %entry
389 %t = icmp ule i8 %n, 1
392 if.end: ; preds = %entry
393 %f = icmp ule i8 %n, 1
397 define i1 @test_n_must_ule_2_due_to_nuw(i8 %n, i8 %i) {
398 ; CHECK-LABEL: @test_n_must_ule_2_due_to_nuw(
400 ; CHECK-NEXT: [[SUB_N_1:%.*]] = add nuw i8 [[N:%.*]], -2
401 ; CHECK-NEXT: [[ADD:%.*]] = add nuw i8 [[I:%.*]], [[SUB_N_1]]
402 ; CHECK-NEXT: [[C_1:%.*]] = icmp uge i8 [[I]], [[ADD]]
403 ; CHECK-NEXT: br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
405 ; CHECK-NEXT: [[T:%.*]] = icmp ule i8 [[N]], 2
406 ; CHECK-NEXT: ret i1 [[T]]
408 ; CHECK-NEXT: [[F:%.*]] = icmp ule i8 [[N]], 2
409 ; CHECK-NEXT: ret i1 [[F]]
412 %sub.n.1 = add nuw i8 %n, -2
413 %add = add nuw i8 %i, %sub.n.1
414 %c.1 = icmp uge i8 %i, %add
415 br i1 %c.1, label %if.then, label %if.end
417 if.then: ; preds = %entry
418 %t = icmp ule i8 %n, 2
421 if.end: ; preds = %entry
422 %f = icmp ule i8 %n, 2
427 define i1 @test_n_unknown_missing_nuw2(i8 %n, i8 %i) {
428 ; CHECK-LABEL: @test_n_unknown_missing_nuw2(
430 ; CHECK-NEXT: [[SUB_N_1:%.*]] = add i8 [[N:%.*]], -2
431 ; CHECK-NEXT: [[ADD:%.*]] = add i8 [[I:%.*]], [[SUB_N_1]]
432 ; CHECK-NEXT: [[C_1:%.*]] = icmp uge i8 [[I]], [[ADD]]
433 ; CHECK-NEXT: br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
435 ; CHECK-NEXT: [[T:%.*]] = icmp ule i8 [[N]], 1
436 ; CHECK-NEXT: ret i1 [[T]]
438 ; CHECK-NEXT: [[F:%.*]] = icmp ule i8 [[N]], 1
439 ; CHECK-NEXT: ret i1 [[F]]
442 %sub.n.1 = add i8 %n, -2
443 %add = add i8 %i, %sub.n.1
444 %c.1 = icmp uge i8 %i, %add
445 br i1 %c.1, label %if.then, label %if.end
447 if.then: ; preds = %entry
448 %t = icmp ule i8 %n, 1
451 if.end: ; preds = %entry
452 %f = icmp ule i8 %n, 1
456 declare void @use(i1)