1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes
2 ; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
4 declare void @llvm.assume(i1)
6 define i1 @test_eq_ne_0(i8 %a, i8 %b) {
7 ; CHECK-LABEL: @test_eq_ne_0(
9 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 0
10 ; CHECK-NEXT: br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]]
12 ; CHECK-NEXT: [[C_2:%.*]] = icmp ne i8 [[A]], [[B:%.*]]
13 ; CHECK-NEXT: [[RES_1:%.*]] = xor i1 false, true
14 ; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[RES_1]], [[C_2]]
15 ; CHECK-NEXT: ret i1 [[RES_2]]
17 ; CHECK-NEXT: [[C_3:%.*]] = icmp ne i8 [[A]], 1
18 ; CHECK-NEXT: [[C_4:%.*]] = icmp ne i8 [[A]], [[B]]
19 ; CHECK-NEXT: [[RES_3:%.*]] = xor i1 true, [[C_3]]
20 ; CHECK-NEXT: [[RES_4:%.*]] = xor i1 [[RES_3]], [[C_4]]
21 ; CHECK-NEXT: ret i1 [[RES_4]]
24 %cmp = icmp eq i8 %a, 0
25 br i1 %cmp, label %then, label %else
28 %f.1 = icmp ne i8 %a, 0
29 %c.1 = icmp ne i8 %a, 1
30 %c.2 = icmp ne i8 %a, %b
31 %res.1 = xor i1 %f.1, %c.1
32 %res.2 = xor i1 %res.1, %c.2
36 %t.1 = icmp ne i8 %a, 0
37 %c.3 = icmp ne i8 %a, 1
38 %c.4 = icmp ne i8 %a, %b
39 %res.3 = xor i1 %t.1, %c.3
40 %res.4 = xor i1 %res.3, %c.4
44 define i1 @test_ne_eq_0(i8 %a, i8 %b) {
45 ; CHECK-LABEL: @test_ne_eq_0(
47 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 0
48 ; CHECK-NEXT: br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]]
50 ; CHECK-NEXT: [[C_1:%.*]] = icmp ne i8 [[A]], 1
51 ; CHECK-NEXT: [[RES_1:%.*]] = xor i1 true, [[C_1]]
52 ; CHECK-NEXT: [[C_2:%.*]] = icmp ne i8 [[A]], [[B:%.*]]
53 ; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[RES_1]], [[C_2]]
54 ; CHECK-NEXT: [[C_3:%.*]] = icmp eq i8 [[A]], [[B]]
55 ; CHECK-NEXT: [[RES_3:%.*]] = xor i1 [[RES_2]], [[C_3]]
56 ; CHECK-NEXT: [[RES_4:%.*]] = xor i1 [[RES_3]], false
57 ; CHECK-NEXT: [[RES_5:%.*]] = xor i1 [[RES_4]], true
58 ; CHECK-NEXT: [[RES_6:%.*]] = xor i1 [[RES_5]], true
59 ; CHECK-NEXT: [[C_5:%.*]] = icmp ugt i8 [[A]], 1
60 ; CHECK-NEXT: [[RES_7:%.*]] = xor i1 [[RES_6]], [[C_5]]
61 ; CHECK-NEXT: [[C_6:%.*]] = icmp sgt i8 [[A]], 0
62 ; CHECK-NEXT: [[RES_8:%.*]] = xor i1 [[RES_7]], [[C_6]]
63 ; CHECK-NEXT: ret i1 [[RES_8]]
65 ; CHECK-NEXT: [[RES_9:%.*]] = xor i1 false, true
66 ; CHECK-NEXT: [[C_8:%.*]] = icmp ne i8 [[A]], [[B]]
67 ; CHECK-NEXT: [[RES_10:%.*]] = xor i1 [[RES_9]], [[C_8]]
68 ; CHECK-NEXT: [[C_9:%.*]] = icmp eq i8 [[A]], [[B]]
69 ; CHECK-NEXT: [[RES_11:%.*]] = xor i1 [[RES_10]], [[C_9]]
70 ; CHECK-NEXT: [[RES_12:%.*]] = xor i1 [[RES_11]], true
71 ; CHECK-NEXT: [[RES_13:%.*]] = xor i1 [[RES_12]], false
72 ; CHECK-NEXT: [[RES_14:%.*]] = xor i1 [[RES_13]], false
73 ; CHECK-NEXT: [[RES_15:%.*]] = xor i1 [[RES_14]], false
74 ; CHECK-NEXT: [[C_12:%.*]] = icmp sgt i8 [[A]], 0
75 ; CHECK-NEXT: [[RES_16:%.*]] = xor i1 [[RES_15]], [[C_12]]
76 ; CHECK-NEXT: ret i1 [[RES_16]]
79 %cmp = icmp ne i8 %a, 0
80 br i1 %cmp, label %then, label %else
83 %t.1 = icmp ne i8 %a, 0
84 %c.1 = icmp ne i8 %a, 1
85 %res.1 = xor i1 %t.1, %c.1
87 %c.2 = icmp ne i8 %a, %b
88 %res.2 = xor i1 %res.1, %c.2
90 %c.3 = icmp eq i8 %a, %b
91 %res.3 = xor i1 %res.2, %c.3
93 %c.4 = icmp eq i8 %a, 0
94 %res.4 = xor i1 %res.3, %c.4
96 %t.2 = icmp ugt i8 %a, 0
97 %res.5 = xor i1 %res.4, %t.2
99 %t.3 = icmp uge i8 %a, 1
100 %res.6 = xor i1 %res.5, %t.3
102 %c.5 = icmp ugt i8 %a, 1
103 %res.7 = xor i1 %res.6, %c.5
105 %c.6 = icmp sgt i8 %a, 0
106 %res.8 = xor i1 %res.7, %c.6
111 %f.1 = icmp ne i8 %a, 0
112 %c.7 = icmp ne i8 %a, 1
113 %res.9 = xor i1 %f.1, %c.7
115 %c.8 = icmp ne i8 %a, %b
116 %res.10 = xor i1 %res.9, %c.8
118 %c.9 = icmp eq i8 %a, %b
119 %res.11 = xor i1 %res.10, %c.9
121 %c.10 = icmp eq i8 %a, 0
122 %res.12 = xor i1 %res.11, %c.10
124 %f.2 = icmp ugt i8 %a, 0
125 %res.13 = xor i1 %res.12, %f.2
127 %f.3 = icmp uge i8 %a, 1
128 %res.14 = xor i1 %res.13, %f.3
130 %c.11 = icmp ugt i8 %a, 1
131 %res.15 = xor i1 %res.14, %c.11
133 %c.12 = icmp sgt i8 %a, 0
134 %res.16 = xor i1 %res.15, %c.12
139 define i1 @test_eq_ne_1(i8 %a, i8 %b) {
140 ; CHECK-LABEL: @test_eq_ne_1(
142 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 1
143 ; CHECK-NEXT: br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]]
145 ; CHECK-NEXT: [[C_2:%.*]] = icmp ne i8 [[A]], [[B:%.*]]
146 ; CHECK-NEXT: [[RES_1:%.*]] = xor i1 true, false
147 ; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[RES_1]], [[C_2]]
148 ; CHECK-NEXT: ret i1 [[RES_2]]
150 ; CHECK-NEXT: [[T_1:%.*]] = icmp ne i8 [[A]], 0
151 ; CHECK-NEXT: [[C_3:%.*]] = icmp ne i8 [[A]], 1
152 ; CHECK-NEXT: [[C_4:%.*]] = icmp ne i8 [[A]], [[B]]
153 ; CHECK-NEXT: [[RES_3:%.*]] = xor i1 [[T_1]], [[C_3]]
154 ; CHECK-NEXT: [[RES_4:%.*]] = xor i1 [[RES_3]], [[C_4]]
155 ; CHECK-NEXT: ret i1 [[RES_4]]
158 %cmp = icmp eq i8 %a, 1
159 br i1 %cmp, label %then, label %else
162 %f.1 = icmp ne i8 %a, 0
163 %c.1 = icmp ne i8 %a, 1
164 %c.2 = icmp ne i8 %a, %b
165 %res.1 = xor i1 %f.1, %c.1
166 %res.2 = xor i1 %res.1, %c.2
170 %t.1 = icmp ne i8 %a, 0
171 %c.3 = icmp ne i8 %a, 1
172 %c.4 = icmp ne i8 %a, %b
173 %res.3 = xor i1 %t.1, %c.3
174 %res.4 = xor i1 %res.3, %c.4
178 define i1 @test_ne_eq_1(i8 %a, i8 %b) {
179 ; CHECK-LABEL: @test_ne_eq_1(
181 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 1
182 ; CHECK-NEXT: br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]]
184 ; CHECK-NEXT: [[T_1:%.*]] = icmp ne i8 [[A]], 1
185 ; CHECK-NEXT: [[C_1:%.*]] = icmp ne i8 [[A]], 0
186 ; CHECK-NEXT: [[RES_1:%.*]] = xor i1 [[T_1]], [[C_1]]
187 ; CHECK-NEXT: [[C_2:%.*]] = icmp ne i8 [[A]], [[B:%.*]]
188 ; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[RES_1]], [[C_2]]
189 ; CHECK-NEXT: [[C_3:%.*]] = icmp eq i8 [[A]], [[B]]
190 ; CHECK-NEXT: [[RES_3:%.*]] = xor i1 [[RES_2]], [[C_3]]
191 ; CHECK-NEXT: [[C_4:%.*]] = icmp eq i8 [[A]], 0
192 ; CHECK-NEXT: [[RES_4:%.*]] = xor i1 [[RES_3]], [[C_4]]
193 ; CHECK-NEXT: [[C_5:%.*]] = icmp ugt i8 [[A]], 0
194 ; CHECK-NEXT: [[RES_5:%.*]] = xor i1 [[RES_4]], [[C_5]]
195 ; CHECK-NEXT: [[C_6:%.*]] = icmp uge i8 [[A]], 1
196 ; CHECK-NEXT: [[RES_6:%.*]] = xor i1 [[RES_5]], [[C_6]]
197 ; CHECK-NEXT: [[C_7:%.*]] = icmp ugt i8 [[A]], 1
198 ; CHECK-NEXT: [[RES_7:%.*]] = xor i1 [[RES_6]], [[C_5]]
199 ; CHECK-NEXT: [[C_8:%.*]] = icmp sgt i8 [[A]], 0
200 ; CHECK-NEXT: [[RES_8:%.*]] = xor i1 [[RES_7]], [[C_6]]
201 ; CHECK-NEXT: ret i1 [[RES_8]]
203 ; CHECK-NEXT: [[RES_9:%.*]] = xor i1 true, false
204 ; CHECK-NEXT: [[C_10:%.*]] = icmp ne i8 [[A]], [[B]]
205 ; CHECK-NEXT: [[RES_10:%.*]] = xor i1 [[RES_9]], [[C_10]]
206 ; CHECK-NEXT: [[C_11:%.*]] = icmp eq i8 [[A]], [[B]]
207 ; CHECK-NEXT: [[RES_11:%.*]] = xor i1 [[RES_10]], [[C_11]]
208 ; CHECK-NEXT: [[RES_12:%.*]] = xor i1 [[RES_11]], false
209 ; CHECK-NEXT: [[RES_13:%.*]] = xor i1 [[RES_12]], true
210 ; CHECK-NEXT: [[RES_14:%.*]] = xor i1 [[RES_13]], true
211 ; CHECK-NEXT: [[RES_15:%.*]] = xor i1 [[RES_14]], false
212 ; CHECK-NEXT: [[C_12:%.*]] = icmp sgt i8 [[A]], 0
213 ; CHECK-NEXT: [[RES_16:%.*]] = xor i1 [[RES_15]], [[C_12]]
214 ; CHECK-NEXT: ret i1 [[RES_16]]
217 %cmp = icmp ne i8 %a, 1
218 br i1 %cmp, label %then, label %else
221 %t.1 = icmp ne i8 %a, 1
222 %c.1 = icmp ne i8 %a, 0
223 %res.1 = xor i1 %t.1, %c.1
225 %c.2 = icmp ne i8 %a, %b
226 %res.2 = xor i1 %res.1, %c.2
228 %c.3 = icmp eq i8 %a, %b
229 %res.3 = xor i1 %res.2, %c.3
231 %c.4 = icmp eq i8 %a, 0
232 %res.4 = xor i1 %res.3, %c.4
234 %c.5 = icmp ugt i8 %a, 0
235 %res.5 = xor i1 %res.4, %c.5
237 %c.6 = icmp uge i8 %a, 1
238 %res.6 = xor i1 %res.5, %c.6
240 %c.7 = icmp ugt i8 %a, 1
241 %res.7 = xor i1 %res.6, %c.5
243 %c.8 = icmp sgt i8 %a, 0
244 %res.8 = xor i1 %res.7, %c.6
249 %t.2 = icmp ne i8 %a, 0
250 %c.9 = icmp ne i8 %a, 1
251 %res.9 = xor i1 %t.2, %c.9
253 %c.10 = icmp ne i8 %a, %b
254 %res.10 = xor i1 %res.9, %c.10
256 %c.11 = icmp eq i8 %a, %b
257 %res.11 = xor i1 %res.10, %c.11
259 %f.1 = icmp eq i8 %a, 0
260 %res.12 = xor i1 %res.11, %f.1
262 %t.3 = icmp ugt i8 %a, 0
263 %res.13 = xor i1 %res.12, %t.3
265 %t.4 = icmp uge i8 %a, 1
266 %res.14 = xor i1 %res.13, %t.4
268 %f.2 = icmp ugt i8 %a, 1
269 %res.15 = xor i1 %res.14, %f.2
271 %c.12 = icmp sgt i8 %a, 0
272 %res.16 = xor i1 %res.15, %c.12
277 define i1 @assume_b_plus_1_ult_a(i64 %a, i64 %b) {
278 ; CHECK-LABEL: @assume_b_plus_1_ult_a(
279 ; CHECK-NEXT: [[TMP1:%.*]] = add nuw i64 [[B:%.*]], 1
280 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i64 [[TMP1]], [[A:%.*]]
281 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP2]])
282 ; CHECK-NEXT: ret i1 true
284 %1 = add nuw i64 %b, 1
285 %2 = icmp ult i64 %1, %a
286 tail call void @llvm.assume(i1 %2)
287 %3 = icmp ne i64 %a, %b
291 define i1 @assume_a_gt_b_and_b_ge_c(i64 %a, i64 %b, i64 %c) {
292 ; CHECK-LABEL: @assume_a_gt_b_and_b_ge_c(
293 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i64 [[A:%.*]], [[B:%.*]]
294 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP1]])
295 ; CHECK-NEXT: [[TMP2:%.*]] = icmp uge i64 [[B]], [[C:%.*]]
296 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP2]])
297 ; CHECK-NEXT: ret i1 true
299 %1 = icmp ugt i64 %a, %b
300 tail call void @llvm.assume(i1 %1)
301 %2 = icmp uge i64 %b, %c
302 tail call void @llvm.assume(i1 %2)
303 %3 = icmp ne i64 %a, %c
307 define i1 @assume_a_ne_b_and_b_ne_c(i64 %a, i64 %b, i64 %c) {
308 ; CHECK-LABEL: @assume_a_ne_b_and_b_ne_c(
309 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i64 [[A:%.*]], [[B:%.*]]
310 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP1]])
311 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i64 [[B]], [[C:%.*]]
312 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP2]])
313 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne i64 [[A]], [[C]]
314 ; CHECK-NEXT: ret i1 [[TMP3]]
316 %1 = icmp ne i64 %a, %b
317 tail call void @llvm.assume(i1 %1)
318 %2 = icmp ne i64 %b, %c
319 tail call void @llvm.assume(i1 %2)
320 %3 = icmp ne i64 %a, %c
324 define i1 @assume_1a(i64 %a, i64 %b) {
325 ; CHECK-LABEL: @assume_1a(
326 ; CHECK-NEXT: [[NE:%.*]] = icmp ne i64 [[A:%.*]], [[B:%.*]]
327 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[NE]])
328 ; CHECK-NEXT: [[RET:%.*]] = icmp ugt i64 [[A]], [[B]]
329 ; CHECK-NEXT: ret i1 [[RET]]
331 %ne = icmp ne i64 %a, %b
332 tail call void @llvm.assume(i1 %ne)
333 %ret = icmp ugt i64 %a, %b
337 define i1 @assume_1b(i64 %a, i64 %b) {
338 ; CHECK-LABEL: @assume_1b(
339 ; CHECK-NEXT: [[NE:%.*]] = icmp ne i64 [[A:%.*]], [[B:%.*]]
340 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[NE]])
341 ; CHECK-NEXT: [[RET:%.*]] = icmp uge i64 [[A]], [[B]]
342 ; CHECK-NEXT: ret i1 [[RET]]
344 %ne = icmp ne i64 %a, %b
345 tail call void @llvm.assume(i1 %ne)
346 %ret = icmp uge i64 %a, %b
350 define i1 @assume_2a(i64 %a, i64 %b) {
351 ; CHECK-LABEL: @assume_2a(
352 ; CHECK-NEXT: [[NE:%.*]] = icmp ne i64 [[A:%.*]], [[B:%.*]]
353 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[NE]])
354 ; CHECK-NEXT: [[RET:%.*]] = icmp ult i64 [[A]], [[B]]
355 ; CHECK-NEXT: ret i1 [[RET]]
357 %ne = icmp ne i64 %a, %b
358 tail call void @llvm.assume(i1 %ne)
359 %ret = icmp ult i64 %a, %b
363 define i1 @assume_2b(i64 %a, i64 %b) {
364 ; CHECK-LABEL: @assume_2b(
365 ; CHECK-NEXT: [[NE:%.*]] = icmp ne i64 [[A:%.*]], [[B:%.*]]
366 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[NE]])
367 ; CHECK-NEXT: [[RET:%.*]] = icmp ule i64 [[A]], [[B]]
368 ; CHECK-NEXT: ret i1 [[RET]]
370 %ne = icmp ne i64 %a, %b
371 tail call void @llvm.assume(i1 %ne)
372 %ret = icmp ule i64 %a, %b
376 ; TODO: extend to support signed comparisons
377 define i1 @assume_3a(i64 %a, i64 %b) {
378 ; CHECK-LABEL: @assume_3a(
379 ; CHECK-NEXT: [[NE:%.*]] = icmp ne i64 [[A:%.*]], [[B:%.*]]
380 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[NE]])
381 ; CHECK-NEXT: [[RET:%.*]] = icmp sgt i64 [[A]], [[B]]
382 ; CHECK-NEXT: ret i1 [[RET]]
384 %ne = icmp ne i64 %a, %b
385 tail call void @llvm.assume(i1 %ne)
386 %ret = icmp sgt i64 %a, %b
390 define i1 @assume_3b(i64 %a, i64 %b) {
391 ; CHECK-LABEL: @assume_3b(
392 ; CHECK-NEXT: [[NE:%.*]] = icmp ne i64 [[A:%.*]], [[B:%.*]]
393 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[NE]])
394 ; CHECK-NEXT: [[RET:%.*]] = icmp sge i64 [[A]], [[B]]
395 ; CHECK-NEXT: ret i1 [[RET]]
397 %ne = icmp ne i64 %a, %b
398 tail call void @llvm.assume(i1 %ne)
399 %ret = icmp sge i64 %a, %b
403 define i1 @assume_4a(i64 %a, i64 %b) {
404 ; CHECK-LABEL: @assume_4a(
405 ; CHECK-NEXT: [[NE:%.*]] = icmp ne i64 [[A:%.*]], [[B:%.*]]
406 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[NE]])
407 ; CHECK-NEXT: [[RET:%.*]] = icmp slt i64 [[A]], [[B]]
408 ; CHECK-NEXT: ret i1 [[RET]]
410 %ne = icmp ne i64 %a, %b
411 tail call void @llvm.assume(i1 %ne)
412 %ret = icmp slt i64 %a, %b
416 define i1 @assume_4b(i64 %a, i64 %b) {
417 ; CHECK-LABEL: @assume_4b(
418 ; CHECK-NEXT: [[NE:%.*]] = icmp ne i64 [[A:%.*]], [[B:%.*]]
419 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[NE]])
420 ; CHECK-NEXT: [[RET:%.*]] = icmp sle i64 [[A]], [[B]]
421 ; CHECK-NEXT: ret i1 [[RET]]
423 %ne = icmp ne i64 %a, %b
424 tail call void @llvm.assume(i1 %ne)
425 %ret = icmp sle i64 %a, %b