1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; This test makes sure that all icmp instructions are eliminated.
3 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
5 @X = external global i32
9 define i1 @test1(i32 %A) {
10 ; CHECK-LABEL: @test1(
11 ; CHECK-NEXT: ret i1 false
13 %B = icmp eq i32 %A, %A
15 %C = icmp eq ptr @X, null
20 define i1 @test1_logical(i32 %A) {
21 ; CHECK-LABEL: @test1_logical(
22 ; CHECK-NEXT: ret i1 false
24 %B = icmp eq i32 %A, %A
26 %C = icmp eq ptr @X, null
27 %D = select i1 %B, i1 %C, i1 false
31 define i1 @test2(i32 %A) {
32 ; CHECK-LABEL: @test2(
33 ; CHECK-NEXT: ret i1 true
35 %B = icmp ne i32 %A, %A
37 %C = icmp ne ptr @X, null
42 define i1 @test2_logical(i32 %A) {
43 ; CHECK-LABEL: @test2_logical(
44 ; CHECK-NEXT: ret i1 true
46 %B = icmp ne i32 %A, %A
48 %C = icmp ne ptr @X, null
49 %D = select i1 %B, i1 true, i1 %C
53 define i1 @test3(i32 %A) {
54 ; CHECK-LABEL: @test3(
55 ; CHECK-NEXT: ret i1 false
57 %B = icmp slt i32 %A, %A
62 define i1 @test4(i32 %A) {
63 ; CHECK-LABEL: @test4(
64 ; CHECK-NEXT: ret i1 false
66 %B = icmp sgt i32 %A, %A
70 define i1 @test5(i32 %A) {
71 ; CHECK-LABEL: @test5(
72 ; CHECK-NEXT: ret i1 true
74 %B = icmp sle i32 %A, %A
78 define i1 @test6(i32 %A) {
79 ; CHECK-LABEL: @test6(
80 ; CHECK-NEXT: ret i1 true
82 %B = icmp sge i32 %A, %A
86 define i1 @test7(i32 %A) {
87 ; CHECK-LABEL: @test7(
88 ; CHECK-NEXT: ret i1 true
90 %B = icmp uge i32 %A, 0
94 define i1 @test8(i32 %A) {
95 ; CHECK-LABEL: @test8(
96 ; CHECK-NEXT: ret i1 false
98 %B = icmp ult i32 %A, 0
102 ;; test operations on boolean values these should all be eliminated$a
103 define i1 @test9(i1 %A) {
104 ; CHECK-LABEL: @test9(
105 ; CHECK-NEXT: ret i1 false
107 %B = icmp ult i1 %A, false
111 define i1 @test10(i1 %A) {
112 ; CHECK-LABEL: @test10(
113 ; CHECK-NEXT: ret i1 false
115 %B = icmp ugt i1 %A, true
119 define i1 @test11(i1 %A) {
120 ; CHECK-LABEL: @test11(
121 ; CHECK-NEXT: ret i1 true
123 %B = icmp ule i1 %A, true
127 define i1 @test12(i1 %A) {
128 ; CHECK-LABEL: @test12(
129 ; CHECK-NEXT: ret i1 true
131 %B = icmp uge i1 %A, false
135 define i1 @test13(i1 %A, i1 %B) {
136 ; CHECK-LABEL: @test13(
137 ; CHECK-NEXT: [[TMP1:%.*]] = xor i1 [[B:%.*]], true
138 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A:%.*]], [[TMP1]]
139 ; CHECK-NEXT: ret i1 [[C]]
141 %C = icmp uge i1 %A, %B
145 define <2 x i1> @test13vec(<2 x i1> %A, <2 x i1> %B) {
146 ; CHECK-LABEL: @test13vec(
147 ; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i1> [[B:%.*]], splat (i1 true)
148 ; CHECK-NEXT: [[C:%.*]] = or <2 x i1> [[A:%.*]], [[TMP1]]
149 ; CHECK-NEXT: ret <2 x i1> [[C]]
151 %C = icmp uge <2 x i1> %A, %B
155 define i1 @test14(i1 %A, i1 %B) {
156 ; CHECK-LABEL: @test14(
157 ; CHECK-NEXT: [[TMP1:%.*]] = xor i1 [[A:%.*]], [[B:%.*]]
158 ; CHECK-NEXT: [[C:%.*]] = xor i1 [[TMP1]], true
159 ; CHECK-NEXT: ret i1 [[C]]
161 %C = icmp eq i1 %A, %B
165 define <3 x i1> @test14vec(<3 x i1> %A, <3 x i1> %B) {
166 ; CHECK-LABEL: @test14vec(
167 ; CHECK-NEXT: [[TMP1:%.*]] = xor <3 x i1> [[A:%.*]], [[B:%.*]]
168 ; CHECK-NEXT: [[C:%.*]] = xor <3 x i1> [[TMP1]], splat (i1 true)
169 ; CHECK-NEXT: ret <3 x i1> [[C]]
171 %C = icmp eq <3 x i1> %A, %B
175 define i1 @bool_eq0(i64 %a) {
176 ; CHECK-LABEL: @bool_eq0(
177 ; CHECK-NEXT: [[AND:%.*]] = icmp sgt i64 [[A:%.*]], 1
178 ; CHECK-NEXT: ret i1 [[AND]]
180 %b = icmp sgt i64 %a, 0
181 %c = icmp eq i64 %a, 1
182 %notc = icmp eq i1 %c, false
183 %and = and i1 %b, %notc
187 define i1 @bool_eq0_logical(i64 %a) {
188 ; CHECK-LABEL: @bool_eq0_logical(
189 ; CHECK-NEXT: [[AND:%.*]] = icmp sgt i64 [[A:%.*]], 1
190 ; CHECK-NEXT: ret i1 [[AND]]
192 %b = icmp sgt i64 %a, 0
193 %c = icmp eq i64 %a, 1
194 %notc = icmp eq i1 %c, false
195 %and = select i1 %b, i1 %notc, i1 false
199 ; This is equivalent to the previous test.
201 define i1 @xor_of_icmps(i64 %a) {
202 ; CHECK-LABEL: @xor_of_icmps(
203 ; CHECK-NEXT: [[XOR:%.*]] = icmp sgt i64 [[A:%.*]], 1
204 ; CHECK-NEXT: ret i1 [[XOR]]
206 %b = icmp sgt i64 %a, 0
207 %c = icmp eq i64 %a, 1
212 ; This is also equivalent to the previous test.
214 define i1 @xor_of_icmps_commute(i64 %a) {
215 ; CHECK-LABEL: @xor_of_icmps_commute(
216 ; CHECK-NEXT: [[XOR:%.*]] = icmp sgt i64 [[A:%.*]], 1
217 ; CHECK-NEXT: ret i1 [[XOR]]
219 %b = icmp sgt i64 %a, 0
220 %c = icmp eq i64 %a, 1
225 define i1 @xor_of_icmps_to_ne(i64 %a) {
226 ; CHECK-LABEL: @xor_of_icmps_to_ne(
227 ; CHECK-NEXT: [[XOR:%.*]] = icmp ne i64 [[A:%.*]], 5
228 ; CHECK-NEXT: ret i1 [[XOR]]
230 %b = icmp sgt i64 %a, 4
231 %c = icmp slt i64 %a, 6
236 define i1 @xor_of_icmps_to_ne_commute(i64 %a) {
237 ; CHECK-LABEL: @xor_of_icmps_to_ne_commute(
238 ; CHECK-NEXT: [[XOR:%.*]] = icmp ne i64 [[A:%.*]], 5
239 ; CHECK-NEXT: ret i1 [[XOR]]
241 %c = icmp sgt i64 %a, 4
242 %b = icmp slt i64 %a, 6
247 define i1 @xor_of_icmps_neg_to_ne(i64 %a) {
248 ; CHECK-LABEL: @xor_of_icmps_neg_to_ne(
249 ; CHECK-NEXT: [[XOR:%.*]] = icmp ne i64 [[A:%.*]], -5
250 ; CHECK-NEXT: ret i1 [[XOR]]
252 %b = icmp sgt i64 %a, -6
253 %c = icmp slt i64 %a, -4
258 define <2 x i1> @xor_of_icmps_to_ne_vector(<2 x i64> %a) {
259 ; CHECK-LABEL: @xor_of_icmps_to_ne_vector(
260 ; CHECK-NEXT: [[XOR:%.*]] = icmp ne <2 x i64> [[A:%.*]], splat (i64 5)
261 ; CHECK-NEXT: ret <2 x i1> [[XOR]]
263 %b = icmp sgt <2 x i64> %a, <i64 4, i64 4>
264 %c = icmp slt <2 x i64> %a, <i64 6, i64 6>
265 %xor = xor <2 x i1> %b, %c
269 define i1 @xor_of_icmps_to_ne_no_common_operand(i64 %a, i64 %z) {
270 ; CHECK-LABEL: @xor_of_icmps_to_ne_no_common_operand(
271 ; CHECK-NEXT: [[B:%.*]] = icmp sgt i64 [[Z:%.*]], 4
272 ; CHECK-NEXT: [[C:%.*]] = icmp slt i64 [[A:%.*]], 6
273 ; CHECK-NEXT: [[XOR:%.*]] = xor i1 [[B]], [[C]]
274 ; CHECK-NEXT: ret i1 [[XOR]]
276 %b = icmp sgt i64 %z, 4
277 %c = icmp slt i64 %a, 6
282 define i1 @xor_of_icmps_to_ne_extra_use_one(i64 %a) {
283 ; CHECK-LABEL: @xor_of_icmps_to_ne_extra_use_one(
284 ; CHECK-NEXT: [[B:%.*]] = icmp sgt i64 [[A:%.*]], 4
285 ; CHECK-NEXT: call void @use(i1 [[B]])
286 ; CHECK-NEXT: [[XOR:%.*]] = icmp ne i64 [[A]], 5
287 ; CHECK-NEXT: ret i1 [[XOR]]
289 %b = icmp sgt i64 %a, 4
290 %c = icmp slt i64 %a, 6
291 call void @use(i1 %b)
296 define i1 @xor_of_icmps_to_ne_extra_use_two(i64 %a) {
297 ; CHECK-LABEL: @xor_of_icmps_to_ne_extra_use_two(
298 ; CHECK-NEXT: [[B:%.*]] = icmp sgt i64 [[A:%.*]], 4
299 ; CHECK-NEXT: [[C:%.*]] = icmp slt i64 [[A]], 6
300 ; CHECK-NEXT: call void @use(i1 [[B]])
301 ; CHECK-NEXT: call void @use(i1 [[C]])
302 ; CHECK-NEXT: [[XOR:%.*]] = xor i1 [[B]], [[C]]
303 ; CHECK-NEXT: ret i1 [[XOR]]
305 %b = icmp sgt i64 %a, 4
306 %c = icmp slt i64 %a, 6
307 call void @use(i1 %b)
308 call void @use(i1 %c)
313 define i1 @xor_of_icmps_to_eq(i8 %a) {
314 ; CHECK-LABEL: @xor_of_icmps_to_eq(
315 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[A:%.*]], 127
316 ; CHECK-NEXT: ret i1 [[C]]
318 %c = icmp sgt i8 %a, 126
319 %b = icmp slt i8 %a, 128
324 ; https://bugs.llvm.org/show_bug.cgi?id=2844
326 define i32 @PR2844(i32 %x) {
327 ; CHECK-LABEL: @PR2844(
328 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], 0
329 ; CHECK-NEXT: [[B:%.*]] = icmp sgt i32 [[X]], -638208502
330 ; CHECK-NEXT: [[OR_NOT:%.*]] = and i1 [[A]], [[B]]
331 ; CHECK-NEXT: [[SEL:%.*]] = zext i1 [[OR_NOT]] to i32
332 ; CHECK-NEXT: ret i32 [[SEL]]
334 %A = icmp eq i32 %x, 0
335 %B = icmp slt i32 %x, -638208501
337 %sel = select i1 %or, i32 0, i32 1
341 define i32 @PR2844_logical(i32 %x) {
342 ; CHECK-LABEL: @PR2844_logical(
343 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], 0
344 ; CHECK-NEXT: [[B:%.*]] = icmp sgt i32 [[X]], -638208502
345 ; CHECK-NEXT: [[OR_NOT:%.*]] = and i1 [[A]], [[B]]
346 ; CHECK-NEXT: [[SEL:%.*]] = zext i1 [[OR_NOT]] to i32
347 ; CHECK-NEXT: ret i32 [[SEL]]
349 %A = icmp eq i32 %x, 0
350 %B = icmp slt i32 %x, -638208501
351 %or = select i1 %A, i1 true, i1 %B
352 %sel = select i1 %or, i32 0, i32 1
356 define i1 @test16(i32 %A) {
357 ; CHECK-LABEL: @test16(
358 ; CHECK-NEXT: ret i1 false
362 %C = icmp eq i32 %B, 8
366 define i1 @test17(i8 %A) {
367 ; CHECK-LABEL: @test17(
368 ; CHECK-NEXT: ret i1 false
372 %C = icmp eq i8 %B, 2
376 define i1 @test18(i1 %C, i32 %a) {
377 ; CHECK-LABEL: @test18(
379 ; CHECK-NEXT: br i1 [[C:%.*]], label [[ENDIF:%.*]], label [[ELSE:%.*]]
381 ; CHECK-NEXT: br label [[ENDIF]]
383 ; CHECK-NEXT: ret i1 true
386 br i1 %C, label %endif, label %else
392 %b.0 = phi i32 [ 0, %entry ], [ 1, %else ]
393 %tmp.4 = icmp slt i32 %b.0, 123
397 define i1 @test19(i1 %A, i1 %B) {
398 ; CHECK-LABEL: @test19(
399 ; CHECK-NEXT: [[TMP1:%.*]] = xor i1 [[A:%.*]], [[B:%.*]]
400 ; CHECK-NEXT: [[C:%.*]] = xor i1 [[TMP1]], true
401 ; CHECK-NEXT: ret i1 [[C]]
403 %a = zext i1 %A to i32
404 %b = zext i1 %B to i32
405 %C = icmp eq i32 %a, %b
409 define i32 @test20(i32 %A) {
410 ; CHECK-LABEL: @test20(
411 ; CHECK-NEXT: [[B:%.*]] = and i32 [[A:%.*]], 1
412 ; CHECK-NEXT: ret i32 [[B]]
415 %C = icmp ne i32 %B, 0
416 %D = zext i1 %C to i32
420 define <2 x i32> @test20vec(<2 x i32> %A) {
421 ; CHECK-LABEL: @test20vec(
422 ; CHECK-NEXT: [[D:%.*]] = and <2 x i32> [[A:%.*]], splat (i32 1)
423 ; CHECK-NEXT: ret <2 x i32> [[D]]
425 %B = and <2 x i32> %A, <i32 1, i32 1>
426 %C = icmp ne <2 x i32> %B, zeroinitializer
427 %D = zext <2 x i1> %C to <2 x i32>
431 define i32 @test21(i32 %a) {
432 ; CHECK-LABEL: @test21(
433 ; CHECK-NEXT: [[TMP_6:%.*]] = lshr i32 [[A:%.*]], 2
434 ; CHECK-NEXT: [[TMP_6_LOBIT:%.*]] = and i32 [[TMP_6]], 1
435 ; CHECK-NEXT: ret i32 [[TMP_6_LOBIT]]
437 %tmp.6 = and i32 %a, 4
438 %not.tmp.7 = icmp ne i32 %tmp.6, 0
439 %retval = zext i1 %not.tmp.7 to i32
443 define <2 x i32> @test21vec(<2 x i32> %a) {
444 ; CHECK-LABEL: @test21vec(
445 ; CHECK-NEXT: [[TMP_6:%.*]] = lshr <2 x i32> [[A:%.*]], splat (i32 2)
446 ; CHECK-NEXT: [[TMP_6_LOBIT:%.*]] = and <2 x i32> [[TMP_6]], splat (i32 1)
447 ; CHECK-NEXT: ret <2 x i32> [[TMP_6_LOBIT]]
449 %tmp.6 = and <2 x i32> %a, <i32 4, i32 4>
450 %not.tmp.7 = icmp ne <2 x i32> %tmp.6, zeroinitializer
451 %retval = zext <2 x i1> %not.tmp.7 to <2 x i32>
452 ret <2 x i32> %retval
455 define i1 @test22(i32 %A, i32 %X) {
456 ; CHECK-LABEL: @test22(
457 ; CHECK-NEXT: ret i1 true
459 %B = and i32 %A, 100663295
460 %C = icmp ult i32 %B, 268435456
462 %Z = icmp sgt i32 %Y, -1
467 define i1 @test22_logical(i32 %A, i32 %X) {
468 ; CHECK-LABEL: @test22_logical(
469 ; CHECK-NEXT: ret i1 true
471 %B = and i32 %A, 100663295
472 %C = icmp ult i32 %B, 268435456
474 %Z = icmp sgt i32 %Y, -1
475 %R = select i1 %C, i1 true, i1 %Z
479 define i32 @test23(i32 %a) {
480 ; CHECK-LABEL: @test23(
481 ; CHECK-NEXT: [[TMP_1:%.*]] = and i32 [[A:%.*]], 1
482 ; CHECK-NEXT: [[TMP_3:%.*]] = xor i32 [[TMP_1]], 1
483 ; CHECK-NEXT: ret i32 [[TMP_3]]
485 %tmp.1 = and i32 %a, 1
486 %tmp.2 = icmp eq i32 %tmp.1, 0
487 %tmp.3 = zext i1 %tmp.2 to i32
491 define <2 x i32> @test23vec(<2 x i32> %a) {
492 ; CHECK-LABEL: @test23vec(
493 ; CHECK-NEXT: [[TMP_1:%.*]] = and <2 x i32> [[A:%.*]], splat (i32 1)
494 ; CHECK-NEXT: [[TMP_3:%.*]] = xor <2 x i32> [[TMP_1]], splat (i32 1)
495 ; CHECK-NEXT: ret <2 x i32> [[TMP_3]]
497 %tmp.1 = and <2 x i32> %a, <i32 1, i32 1>
498 %tmp.2 = icmp eq <2 x i32> %tmp.1, zeroinitializer
499 %tmp.3 = zext <2 x i1> %tmp.2 to <2 x i32>
503 define i32 @test24(i32 %a) {
504 ; CHECK-LABEL: @test24(
505 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[A:%.*]], 2
506 ; CHECK-NEXT: [[DOTLOBIT:%.*]] = and i32 [[TMP1]], 1
507 ; CHECK-NEXT: [[TMP_3:%.*]] = xor i32 [[DOTLOBIT]], 1
508 ; CHECK-NEXT: ret i32 [[TMP_3]]
510 %tmp1 = and i32 %a, 4
511 %tmp.1 = lshr i32 %tmp1, 2
512 %tmp.2 = icmp eq i32 %tmp.1, 0
513 %tmp.3 = zext i1 %tmp.2 to i32
517 define <2 x i32> @test24vec(<2 x i32> %a) {
518 ; CHECK-LABEL: @test24vec(
519 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> [[A:%.*]], splat (i32 2)
520 ; CHECK-NEXT: [[DOTLOBIT:%.*]] = and <2 x i32> [[TMP1]], splat (i32 1)
521 ; CHECK-NEXT: [[TMP_3:%.*]] = xor <2 x i32> [[DOTLOBIT]], splat (i32 1)
522 ; CHECK-NEXT: ret <2 x i32> [[TMP_3]]
524 %tmp1 = and <2 x i32> %a, <i32 4, i32 4>
525 %tmp.1 = lshr <2 x i32> %tmp1, <i32 2, i32 2>
526 %tmp.2 = icmp eq <2 x i32> %tmp.1, zeroinitializer
527 %tmp.3 = zext <2 x i1> %tmp.2 to <2 x i32>
531 define i1 @test25(i32 %A) {
532 ; CHECK-LABEL: @test25(
533 ; CHECK-NEXT: ret i1 false
536 %C = icmp ugt i32 %B, 2