1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
5 declare void @use_vec(<2 x i8>)
7 define i1 @test_nuw_and_unsigned_pred(i64 %x) {
8 ; CHECK-LABEL: @test_nuw_and_unsigned_pred(
9 ; CHECK-NEXT: [[Z:%.*]] = icmp ugt i64 [[X:%.*]], 7
10 ; CHECK-NEXT: ret i1 [[Z]]
12 %y = sub nuw i64 10, %x
13 %z = icmp ult i64 %y, 3
17 define i1 @test_nsw_and_signed_pred(i64 %x) {
18 ; CHECK-LABEL: @test_nsw_and_signed_pred(
19 ; CHECK-NEXT: [[Z:%.*]] = icmp slt i64 [[X:%.*]], -7
20 ; CHECK-NEXT: ret i1 [[Z]]
22 %y = sub nsw i64 3, %x
23 %z = icmp sgt i64 %y, 10
27 define i1 @test_nuw_nsw_and_unsigned_pred(i64 %x) {
28 ; CHECK-LABEL: @test_nuw_nsw_and_unsigned_pred(
29 ; CHECK-NEXT: [[Z:%.*]] = icmp ugt i64 [[X:%.*]], 6
30 ; CHECK-NEXT: ret i1 [[Z]]
32 %y = sub nuw nsw i64 10, %x
33 %z = icmp ule i64 %y, 3
37 define i1 @test_nuw_nsw_and_signed_pred(i64 %x) {
38 ; CHECK-LABEL: @test_nuw_nsw_and_signed_pred(
39 ; CHECK-NEXT: [[Z:%.*]] = icmp ugt i64 [[X:%.*]], 7
40 ; CHECK-NEXT: ret i1 [[Z]]
42 %y = sub nuw nsw i64 10, %x
43 %z = icmp slt i64 %y, 3
47 define i1 @test_negative_nuw_and_signed_pred(i64 %x) {
48 ; CHECK-LABEL: @test_negative_nuw_and_signed_pred(
49 ; CHECK-NEXT: [[Z:%.*]] = icmp ugt i64 [[X:%.*]], 7
50 ; CHECK-NEXT: ret i1 [[Z]]
52 %y = sub nuw i64 10, %x
53 %z = icmp slt i64 %y, 3
57 define i1 @test_negative_nsw_and_unsigned_pred(i64 %x) {
58 ; CHECK-LABEL: @test_negative_nsw_and_unsigned_pred(
59 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[X:%.*]], -8
60 ; CHECK-NEXT: [[Z:%.*]] = icmp ult i64 [[TMP1]], 3
61 ; CHECK-NEXT: ret i1 [[Z]]
63 %y = sub nsw i64 10, %x
64 %z = icmp ult i64 %y, 3
68 define i1 @test_negative_combined_sub_unsigned_overflow(i64 %x) {
69 ; CHECK-LABEL: @test_negative_combined_sub_unsigned_overflow(
70 ; CHECK-NEXT: ret i1 true
72 %y = sub nuw i64 10, %x
73 %z = icmp ult i64 %y, 11
77 define i1 @test_negative_combined_sub_signed_overflow(i8 %x) {
78 ; CHECK-LABEL: @test_negative_combined_sub_signed_overflow(
79 ; CHECK-NEXT: ret i1 false
81 %y = sub nsw i8 127, %x
82 %z = icmp slt i8 %y, -1
86 define i1 @test_sub_0_Y_eq_0(i8 %y) {
87 ; CHECK-LABEL: @test_sub_0_Y_eq_0(
88 ; CHECK-NEXT: [[Z:%.*]] = icmp eq i8 [[Y:%.*]], 0
89 ; CHECK-NEXT: ret i1 [[Z]]
96 define i1 @test_sub_0_Y_ne_0(i8 %y) {
97 ; CHECK-LABEL: @test_sub_0_Y_ne_0(
98 ; CHECK-NEXT: [[Z:%.*]] = icmp ne i8 [[Y:%.*]], 0
99 ; CHECK-NEXT: ret i1 [[Z]]
102 %z = icmp ne i8 %s, 0
106 define i1 @test_sub_4_Y_ne_4(i8 %y) {
107 ; CHECK-LABEL: @test_sub_4_Y_ne_4(
108 ; CHECK-NEXT: [[Z:%.*]] = icmp ne i8 [[Y:%.*]], 0
109 ; CHECK-NEXT: ret i1 [[Z]]
112 %z = icmp ne i8 %s, 4
116 define i1 @test_sub_127_Y_eq_127(i8 %y) {
117 ; CHECK-LABEL: @test_sub_127_Y_eq_127(
118 ; CHECK-NEXT: [[Z:%.*]] = icmp eq i8 [[Y:%.*]], 0
119 ; CHECK-NEXT: ret i1 [[Z]]
122 %z = icmp eq i8 %s, 127
126 define i1 @test_sub_255_Y_eq_255(i8 %y) {
127 ; CHECK-LABEL: @test_sub_255_Y_eq_255(
128 ; CHECK-NEXT: [[Z:%.*]] = icmp eq i8 [[Y:%.*]], 0
129 ; CHECK-NEXT: ret i1 [[Z]]
132 %z = icmp eq i8 %s, 255
135 define <2 x i1> @test_sub_255_Y_eq_255_vec(<2 x i8> %y) {
136 ; CHECK-LABEL: @test_sub_255_Y_eq_255_vec(
137 ; CHECK-NEXT: [[Z:%.*]] = icmp eq <2 x i8> [[Y:%.*]], zeroinitializer
138 ; CHECK-NEXT: ret <2 x i1> [[Z]]
140 %s = sub <2 x i8> <i8 255, i8 255>, %y
141 %z = icmp eq <2 x i8> %s, <i8 255, i8 255>
145 define <2 x i1> @icmp_eq_sub_undef(<2 x i32> %a) {
146 ; CHECK-LABEL: @icmp_eq_sub_undef(
147 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[A:%.*]], <i32 5, i32 undef>
148 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
150 %sub = sub <2 x i32> <i32 15, i32 undef>, %a
151 %cmp = icmp eq <2 x i32> %sub, <i32 10, i32 10>
155 define <2 x i1> @icmp_eq_sub_non_splat(<2 x i32> %a) {
156 ; CHECK-LABEL: @icmp_eq_sub_non_splat(
157 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[A:%.*]], <i32 5, i32 6>
158 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
160 %sub = sub <2 x i32> <i32 15, i32 16>, %a
161 %cmp = icmp eq <2 x i32> %sub, <i32 10, i32 10>
165 define <2 x i1> @icmp_eq_sub_undef2(<2 x i32> %a) {
166 ; CHECK-LABEL: @icmp_eq_sub_undef2(
167 ; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i32> splat (i32 15), [[A:%.*]]
168 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[SUB]], <i32 10, i32 undef>
169 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
171 %sub = sub <2 x i32> <i32 15, i32 15>, %a
172 %cmp = icmp eq <2 x i32> %sub, <i32 10, i32 undef>
176 define <2 x i1> @icmp_eq_sub_non_splat2(<2 x i32> %a) {
177 ; CHECK-LABEL: @icmp_eq_sub_non_splat2(
178 ; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i32> splat (i32 15), [[A:%.*]]
179 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[SUB]], <i32 10, i32 11>
180 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
182 %sub = sub <2 x i32> <i32 15, i32 15>, %a
183 %cmp = icmp eq <2 x i32> %sub, <i32 10, i32 11>
187 define i1 @neg_sgt_42(i32 %x) {
188 ; CHECK-LABEL: @neg_sgt_42(
189 ; CHECK-NEXT: [[NOTSUB:%.*]] = add i32 [[X:%.*]], -1
190 ; CHECK-NEXT: [[R:%.*]] = icmp slt i32 [[NOTSUB]], -43
191 ; CHECK-NEXT: ret i1 [[R]]
193 %negx = sub i32 0, %x
194 %r = icmp sgt i32 %negx, 42
198 define i1 @neg_eq_43(i32 %x) {
199 ; CHECK-LABEL: @neg_eq_43(
200 ; CHECK-NEXT: [[NEGX:%.*]] = sub i32 0, [[X:%.*]]
201 ; CHECK-NEXT: call void @use(i32 [[NEGX]])
202 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[X]], -43
203 ; CHECK-NEXT: ret i1 [[R]]
205 %negx = sub i32 0, %x
206 call void @use(i32 %negx)
207 %r = icmp eq i32 %negx, 43
211 define i1 @neg_ne_44(i32 %x) {
212 ; CHECK-LABEL: @neg_ne_44(
213 ; CHECK-NEXT: [[NEGX:%.*]] = sub i32 0, [[X:%.*]]
214 ; CHECK-NEXT: call void @use(i32 [[NEGX]])
215 ; CHECK-NEXT: [[R:%.*]] = icmp ne i32 [[X]], -44
216 ; CHECK-NEXT: ret i1 [[R]]
218 %negx = sub i32 0, %x
219 call void @use(i32 %negx)
220 %r = icmp ne i32 %negx, 44
224 define i1 @neg_nsw_eq_45(i32 %x) {
225 ; CHECK-LABEL: @neg_nsw_eq_45(
226 ; CHECK-NEXT: [[NEGX:%.*]] = sub nsw i32 0, [[X:%.*]]
227 ; CHECK-NEXT: call void @use(i32 [[NEGX]])
228 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[X]], -45
229 ; CHECK-NEXT: ret i1 [[R]]
231 %negx = sub nsw i32 0, %x
232 call void @use(i32 %negx)
233 %r = icmp eq i32 %negx, 45
237 define i1 @neg_nsw_ne_46(i32 %x) {
238 ; CHECK-LABEL: @neg_nsw_ne_46(
239 ; CHECK-NEXT: [[NEGX:%.*]] = sub nsw i32 0, [[X:%.*]]
240 ; CHECK-NEXT: call void @use(i32 [[NEGX]])
241 ; CHECK-NEXT: [[R:%.*]] = icmp ne i32 [[X]], -46
242 ; CHECK-NEXT: ret i1 [[R]]
244 %negx = sub nsw i32 0, %x
245 call void @use(i32 %negx)
246 %r = icmp ne i32 %negx, 46
250 define i1 @subC_eq(i32 %x) {
251 ; CHECK-LABEL: @subC_eq(
252 ; CHECK-NEXT: [[SUBX:%.*]] = sub i32 -2147483648, [[X:%.*]]
253 ; CHECK-NEXT: call void @use(i32 [[SUBX]])
254 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[X]], 2147483605
255 ; CHECK-NEXT: ret i1 [[R]]
257 %subx = sub i32 -2147483648, %x
258 call void @use(i32 %subx)
259 %r = icmp eq i32 %subx, 43
263 define <2 x i1> @subC_ne(<2 x i8> %x) {
264 ; CHECK-LABEL: @subC_ne(
265 ; CHECK-NEXT: [[SUBX:%.*]] = sub <2 x i8> <i8 -6, i8 -128>, [[X:%.*]]
266 ; CHECK-NEXT: call void @use_vec(<2 x i8> [[SUBX]])
267 ; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i8> [[X]], <i8 38, i8 -84>
268 ; CHECK-NEXT: ret <2 x i1> [[R]]
270 %subx = sub <2 x i8> <i8 -6, i8 -128>, %x
271 call void @use_vec(<2 x i8> %subx)
272 %r = icmp ne <2 x i8> %subx, <i8 -44, i8 -44>
276 define i1 @subC_nsw_eq(i32 %x) {
277 ; CHECK-LABEL: @subC_nsw_eq(
278 ; CHECK-NEXT: [[SUBX:%.*]] = sub nsw i32 -100, [[X:%.*]]
279 ; CHECK-NEXT: call void @use(i32 [[SUBX]])
280 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[X]], 2147483548
281 ; CHECK-NEXT: ret i1 [[R]]
283 %subx = sub nsw i32 -100, %x
284 call void @use(i32 %subx)
285 %r = icmp eq i32 %subx, -2147483648
289 define i1 @subC_nsw_ne(i32 %x) {
290 ; CHECK-LABEL: @subC_nsw_ne(
291 ; CHECK-NEXT: [[SUBX:%.*]] = sub nsw i32 -2147483647, [[X:%.*]]
292 ; CHECK-NEXT: call void @use(i32 [[SUBX]])
293 ; CHECK-NEXT: [[R:%.*]] = icmp ne i32 [[X]], 2147483603
294 ; CHECK-NEXT: ret i1 [[R]]
296 %subx = sub nsw i32 -2147483647, %x
297 call void @use(i32 %subx)
298 %r = icmp ne i32 %subx, 46
302 define i1 @neg_slt_42(i128 %x) {
303 ; CHECK-LABEL: @neg_slt_42(
304 ; CHECK-NEXT: [[NOTSUB:%.*]] = add i128 [[X:%.*]], -1
305 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i128 [[NOTSUB]], -43
306 ; CHECK-NEXT: ret i1 [[R]]
308 %negx = sub i128 0, %x
309 %r = icmp slt i128 %negx, 42
313 define <2 x i1> @neg_ugt_42_splat(<2 x i7> %x) {
314 ; CHECK-LABEL: @neg_ugt_42_splat(
315 ; CHECK-NEXT: [[NOTSUB:%.*]] = add <2 x i7> [[X:%.*]], splat (i7 -1)
316 ; CHECK-NEXT: [[R:%.*]] = icmp ult <2 x i7> [[NOTSUB]], splat (i7 -43)
317 ; CHECK-NEXT: ret <2 x i1> [[R]]
319 %negx = sub <2 x i7> zeroinitializer, %x
320 %r = icmp ugt <2 x i7> %negx, <i7 42, i7 42>
324 define i1 @neg_sgt_42_use(i32 %x) {
325 ; CHECK-LABEL: @neg_sgt_42_use(
326 ; CHECK-NEXT: [[NEGX:%.*]] = sub i32 0, [[X:%.*]]
327 ; CHECK-NEXT: call void @use(i32 [[NEGX]])
328 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i32 [[NEGX]], 42
329 ; CHECK-NEXT: ret i1 [[R]]
331 %negx = sub i32 0, %x
332 call void @use(i32 %negx)
333 %r = icmp sgt i32 %negx, 42
337 ; Test common/edge cases with signed pred.
339 define i1 @neg_slt_n1(i8 %x) {
340 ; CHECK-LABEL: @neg_slt_n1(
341 ; CHECK-NEXT: [[NOTSUB:%.*]] = add i8 [[X:%.*]], -1
342 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[NOTSUB]], 0
343 ; CHECK-NEXT: ret i1 [[R]]
346 %r = icmp slt i8 %negx, -1
350 define i1 @neg_slt_0(i8 %x) {
351 ; CHECK-LABEL: @neg_slt_0(
352 ; CHECK-NEXT: [[NOTSUB:%.*]] = add i8 [[X:%.*]], -1
353 ; CHECK-NEXT: [[ISNEGNEG:%.*]] = icmp sgt i8 [[NOTSUB]], -1
354 ; CHECK-NEXT: ret i1 [[ISNEGNEG]]
357 %isnegneg = icmp slt i8 %negx, 0
361 define i1 @neg_slt_1(i8 %x) {
362 ; CHECK-LABEL: @neg_slt_1(
363 ; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[X:%.*]], -127
364 ; CHECK-NEXT: ret i1 [[R]]
367 %r = icmp slt i8 %negx, 1
371 define i1 @neg_sgt_n1(i8 %x) {
372 ; CHECK-LABEL: @neg_sgt_n1(
373 ; CHECK-NEXT: [[NOTSUB:%.*]] = add i8 [[X:%.*]], -1
374 ; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[NOTSUB]], 0
375 ; CHECK-NEXT: ret i1 [[R]]
378 %r = icmp sgt i8 %negx, -1
382 define i1 @neg_sgt_0(i8 %x) {
383 ; CHECK-LABEL: @neg_sgt_0(
384 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[X:%.*]], -128
385 ; CHECK-NEXT: ret i1 [[R]]
388 %r = icmp sgt i8 %negx, 0
392 define i1 @neg_sgt_1(i8 %x) {
393 ; CHECK-LABEL: @neg_sgt_1(
394 ; CHECK-NEXT: [[NOTSUB:%.*]] = add i8 [[X:%.*]], -1
395 ; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[NOTSUB]], -2
396 ; CHECK-NEXT: ret i1 [[R]]
399 %r = icmp sgt i8 %negx, 1
403 ; Test common/edge cases with signed pred and nsw.
405 define i1 @neg_nsw_slt_n1(i8 %x) {
406 ; CHECK-LABEL: @neg_nsw_slt_n1(
407 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[X:%.*]], 1
408 ; CHECK-NEXT: ret i1 [[R]]
410 %negx = sub nsw i8 0, %x
411 %r = icmp slt i8 %negx, -1
415 define i1 @neg_nsw_slt_0(i8 %x) {
416 ; CHECK-LABEL: @neg_nsw_slt_0(
417 ; CHECK-NEXT: [[ISNEGNEG:%.*]] = icmp sgt i8 [[X:%.*]], 0
418 ; CHECK-NEXT: ret i1 [[ISNEGNEG]]
420 %negx = sub nsw i8 0, %x
421 %isnegneg = icmp slt i8 %negx, 0
425 define i1 @neg_nsw_slt_1(i8 %x) {
426 ; CHECK-LABEL: @neg_nsw_slt_1(
427 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[X:%.*]], -1
428 ; CHECK-NEXT: ret i1 [[R]]
430 %negx = sub nsw i8 0, %x
431 %r = icmp slt i8 %negx, 1
435 define i1 @neg_nsw_sgt_n1(i8 %x) {
436 ; CHECK-LABEL: @neg_nsw_sgt_n1(
437 ; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[X:%.*]], 1
438 ; CHECK-NEXT: ret i1 [[R]]
440 %negx = sub nsw i8 0, %x
441 %r = icmp sgt i8 %negx, -1
445 define i1 @neg_nsw_sgt_0(i8 %x) {
446 ; CHECK-LABEL: @neg_nsw_sgt_0(
447 ; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[X:%.*]], 0
448 ; CHECK-NEXT: ret i1 [[R]]
450 %negx = sub nsw i8 0, %x
451 %r = icmp sgt i8 %negx, 0
455 define i1 @neg_nsw_sgt_1(i8 %x) {
456 ; CHECK-LABEL: @neg_nsw_sgt_1(
457 ; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[X:%.*]], -1
458 ; CHECK-NEXT: ret i1 [[R]]
460 %negx = sub nsw i8 0, %x
461 %r = icmp sgt i8 %negx, 1
465 define i1 @sub_eq_zero_use(i32 %x, i32 %y) {
466 ; CHECK-LABEL: @sub_eq_zero_use(
467 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[X:%.*]], [[Y:%.*]]
468 ; CHECK-NEXT: call void @use(i32 [[SUB]])
469 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[X]], [[Y]]
470 ; CHECK-NEXT: ret i1 [[R]]
472 %sub = sub i32 %x, %y
473 call void @use(i32 %sub)
474 %r = icmp eq i32 %sub, 0
478 define <2 x i1> @sub_ne_zero_use(<2 x i8> %x, <2 x i8> %y) {
479 ; CHECK-LABEL: @sub_ne_zero_use(
480 ; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i8> [[X:%.*]], [[Y:%.*]]
481 ; CHECK-NEXT: call void @use_vec(<2 x i8> [[SUB]])
482 ; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i8> [[X]], [[Y]]
483 ; CHECK-NEXT: ret <2 x i1> [[R]]
485 %sub = sub <2 x i8> %x, %y
486 call void @use_vec(<2 x i8> %sub)
487 %r = icmp eq <2 x i8> %sub, zeroinitializer
491 define i32 @sub_eq_zero_select(i32 %a, i32 %b, ptr %p) {
492 ; CHECK-LABEL: @sub_eq_zero_select(
493 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[A:%.*]], [[B:%.*]]
494 ; CHECK-NEXT: store i32 [[SUB]], ptr [[P:%.*]], align 4
495 ; CHECK-NEXT: ret i32 [[B]]
497 %sub = sub i32 %a, %b
498 store i32 %sub, ptr %p
499 %cmp = icmp eq i32 %sub, 0
500 %sel = select i1 %cmp, i32 %a, i32 %b
504 ; Replacing the "SUB == 0" regresses codegen, and it may be hard to recover from that.
506 declare i32 @llvm.umin.i32(i32, i32)
508 define void @PR54558_reduced(i32 %arg) {
509 ; CHECK-LABEL: @PR54558_reduced(
510 ; CHECK-NEXT: bb_entry:
511 ; CHECK-NEXT: br label [[BB_LOOP:%.*]]
513 ; CHECK-NEXT: [[PHI_OUTER:%.*]] = phi i32 [ [[SUB:%.*]], [[BB_LOOP]] ], [ [[ARG:%.*]], [[BB_ENTRY:%.*]] ]
514 ; CHECK-NEXT: [[MIN:%.*]] = tail call i32 @llvm.umin.i32(i32 [[PHI_OUTER]], i32 43)
515 ; CHECK-NEXT: call void @use(i32 [[MIN]])
516 ; CHECK-NEXT: [[SUB]] = sub i32 [[PHI_OUTER]], [[MIN]]
517 ; CHECK-NEXT: [[COND_OUTER:%.*]] = icmp eq i32 [[SUB]], 0
518 ; CHECK-NEXT: br i1 [[COND_OUTER]], label [[BB_EXIT:%.*]], label [[BB_LOOP]]
520 ; CHECK-NEXT: ret void
526 %phi_outer = phi i32 [ %sub, %bb_loop ], [ %arg, %bb_entry ]
527 %min = tail call i32 @llvm.umin.i32(i32 %phi_outer, i32 43)
528 call void @use(i32 %min)
529 %sub = sub i32 %phi_outer, %min
530 %cond_outer = icmp eq i32 %sub, 0
531 br i1 %cond_outer, label %bb_exit, label %bb_loop
537 ; TODO: It might be ok to replace the "SUB == 0" in this example if codegen can invert it.
539 define void @PR54558_reduced_more(i32 %x, i32 %y) {
540 ; CHECK-LABEL: @PR54558_reduced_more(
541 ; CHECK-NEXT: bb_entry:
542 ; CHECK-NEXT: br label [[BB_LOOP:%.*]]
544 ; CHECK-NEXT: [[PHI_OUTER:%.*]] = phi i32 [ [[SUB:%.*]], [[BB_LOOP]] ], [ [[X:%.*]], [[BB_ENTRY:%.*]] ]
545 ; CHECK-NEXT: [[SUB]] = sub i32 [[PHI_OUTER]], [[Y:%.*]]
546 ; CHECK-NEXT: [[COND_OUTER:%.*]] = icmp eq i32 [[SUB]], 0
547 ; CHECK-NEXT: br i1 [[COND_OUTER]], label [[BB_EXIT:%.*]], label [[BB_LOOP]]
549 ; CHECK-NEXT: ret void
555 %phi_outer = phi i32 [ %sub, %bb_loop ], [ %x, %bb_entry ]
556 %sub = sub i32 %phi_outer, %y
557 %cond_outer = icmp eq i32 %sub, 0
558 br i1 %cond_outer, label %bb_exit, label %bb_loop
564 ; https://alive2.llvm.org/ce/z/D2Aph4
565 define i1 @PR60818_ne(i32 %a) {
566 ; CHECK-LABEL: @PR60818_ne(
568 ; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[A:%.*]], 2147483647
569 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[TMP0]], 0
570 ; CHECK-NEXT: ret i1 [[CMP]]
574 %cmp = icmp ne i32 %sub, %a
578 define i1 @PR60818_eq(i32 %a) {
579 ; CHECK-LABEL: @PR60818_eq(
581 ; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[A:%.*]], 2147483647
582 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP0]], 0
583 ; CHECK-NEXT: ret i1 [[CMP]]
587 %cmp = icmp eq i32 %sub, %a
591 define i1 @PR60818_eq_commuted(i32 %x) {
592 ; CHECK-LABEL: @PR60818_eq_commuted(
594 ; CHECK-NEXT: [[A:%.*]] = mul i32 [[X:%.*]], 43
595 ; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[A]], 2147483647
596 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP0]], 0
597 ; CHECK-NEXT: ret i1 [[CMP]]
600 %a = mul i32 %x, 43 ; thwart complexity-based canonicalization
602 %cmp = icmp eq i32 %a, %sub ; negation on RHS
606 define <2 x i1> @PR60818_ne_vector(<2 x i32> %a) {
607 ; CHECK-LABEL: @PR60818_ne_vector(
609 ; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i32> [[A:%.*]], splat (i32 2147483647)
610 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[TMP0]], zeroinitializer
611 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
614 %sub = sub <2 x i32> zeroinitializer, %a
615 %cmp = icmp ne <2 x i32> %a, %sub
619 ; Negative as multi-use
620 define i1 @PR60818_eq_multi_use(i32 %a) {
621 ; CHECK-LABEL: @PR60818_eq_multi_use(
623 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[A:%.*]]
624 ; CHECK-NEXT: call void @use(i32 [[SUB]])
625 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A]], [[SUB]]
626 ; CHECK-NEXT: ret i1 [[CMP]]
630 call void @use(i32 %sub) ; add new user
631 %cmp = icmp eq i32 %sub, %a
635 ; Negative as non-equality predicate
636 define i1 @PR60818_sgt(i32 %a) {
637 ; CHECK-LABEL: @PR60818_sgt(
639 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[A:%.*]]
640 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[A]], [[SUB]]
641 ; CHECK-NEXT: ret i1 [[CMP]]
645 %cmp = icmp sgt i32 %sub, %a