1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
8 define i1 @slt_positive_multip_rem_zero(i8 %x) {
9 ; CHECK-LABEL: @slt_positive_multip_rem_zero(
10 ; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], 7
11 ; CHECK-NEXT: [[B:%.*]] = icmp slt i8 [[A]], 21
12 ; CHECK-NEXT: ret i1 [[B]]
15 %b = icmp slt i8 %a, 21
19 define i1 @slt_negative_multip_rem_zero(i8 %x) {
20 ; CHECK-LABEL: @slt_negative_multip_rem_zero(
21 ; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], -7
22 ; CHECK-NEXT: [[B:%.*]] = icmp slt i8 [[A]], 21
23 ; CHECK-NEXT: ret i1 [[B]]
25 %a = mul nsw i8 %x, -7
26 %b = icmp slt i8 %a, 21
30 define i1 @slt_positive_multip_rem_nz(i8 %x) {
31 ; CHECK-LABEL: @slt_positive_multip_rem_nz(
32 ; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], 5
33 ; CHECK-NEXT: [[B:%.*]] = icmp slt i8 [[A]], 21
34 ; CHECK-NEXT: ret i1 [[B]]
37 %b = icmp slt i8 %a, 21
41 define i1 @ult_rem_zero(i8 %x) {
42 ; CHECK-LABEL: @ult_rem_zero(
43 ; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 7
44 ; CHECK-NEXT: [[B:%.*]] = icmp ult i8 [[A]], 21
45 ; CHECK-NEXT: ret i1 [[B]]
48 %b = icmp ult i8 %a, 21
52 define i1 @ult_rem_nz(i8 %x) {
53 ; CHECK-LABEL: @ult_rem_nz(
54 ; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5
55 ; CHECK-NEXT: [[B:%.*]] = icmp ult i8 [[A]], 21
56 ; CHECK-NEXT: ret i1 [[B]]
59 %b = icmp ult i8 %a, 21
65 define i1 @sgt_positive_multip_rem_zero(i8 %x) {
66 ; CHECK-LABEL: @sgt_positive_multip_rem_zero(
67 ; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], 7
68 ; CHECK-NEXT: [[B:%.*]] = icmp sgt i8 [[A]], 21
69 ; CHECK-NEXT: ret i1 [[B]]
72 %b = icmp sgt i8 %a, 21
76 define i1 @sgt_negative_multip_rem_zero(i8 %x) {
77 ; CHECK-LABEL: @sgt_negative_multip_rem_zero(
78 ; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], -7
79 ; CHECK-NEXT: [[B:%.*]] = icmp sgt i8 [[A]], 21
80 ; CHECK-NEXT: ret i1 [[B]]
82 %a = mul nsw i8 %x, -7
83 %b = icmp sgt i8 %a, 21
87 define i1 @sgt_positive_multip_rem_nz(i8 %x) {
88 ; CHECK-LABEL: @sgt_positive_multip_rem_nz(
89 ; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], 5
90 ; CHECK-NEXT: [[B:%.*]] = icmp sgt i8 [[A]], 21
91 ; CHECK-NEXT: ret i1 [[B]]
94 %b = icmp sgt i8 %a, 21
98 define i1 @ugt_rem_zero(i8 %x) {
99 ; CHECK-LABEL: @ugt_rem_zero(
100 ; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 7
101 ; CHECK-NEXT: [[B:%.*]] = icmp ugt i8 [[A]], 21
102 ; CHECK-NEXT: ret i1 [[B]]
104 %a = mul nuw i8 %x, 7
105 %b = icmp ugt i8 %a, 21
109 define i1 @ugt_rem_nz(i8 %x) {
110 ; CHECK-LABEL: @ugt_rem_nz(
111 ; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5
112 ; CHECK-NEXT: [[B:%.*]] = icmp ugt i8 [[A]], 21
113 ; CHECK-NEXT: ret i1 [[B]]
115 %a = mul nuw i8 %x, 5
116 %b = icmp ugt i8 %a, 21
122 define i1 @eq_nsw_rem_zero(i8 %x) {
123 ; CHECK-LABEL: @eq_nsw_rem_zero(
124 ; CHECK-NEXT: [[B:%.*]] = icmp eq i8 [[X:%.*]], -4
125 ; CHECK-NEXT: ret i1 [[B]]
127 %a = mul nsw i8 %x, -5
128 %b = icmp eq i8 %a, 20
132 define <2 x i1> @ne_nsw_rem_zero(<2 x i8> %x) {
133 ; CHECK-LABEL: @ne_nsw_rem_zero(
134 ; CHECK-NEXT: [[B:%.*]] = icmp ne <2 x i8> [[X:%.*]], <i8 -6, i8 -6>
135 ; CHECK-NEXT: ret <2 x i1> [[B]]
137 %a = mul nsw <2 x i8> %x, <i8 5, i8 5>
138 %b = icmp ne <2 x i8> %a, <i8 -30, i8 -30>
142 ; TODO: Missed fold with undef.
144 define <2 x i1> @ne_nsw_rem_zero_undef1(<2 x i8> %x) {
145 ; CHECK-LABEL: @ne_nsw_rem_zero_undef1(
146 ; CHECK-NEXT: [[A:%.*]] = mul nsw <2 x i8> [[X:%.*]], <i8 5, i8 undef>
147 ; CHECK-NEXT: [[B:%.*]] = icmp ne <2 x i8> [[A]], <i8 -30, i8 -30>
148 ; CHECK-NEXT: ret <2 x i1> [[B]]
150 %a = mul nsw <2 x i8> %x, <i8 5, i8 undef>
151 %b = icmp ne <2 x i8> %a, <i8 -30, i8 -30>
155 ; TODO: Missed fold with undef.
157 define <2 x i1> @ne_nsw_rem_zero_undef2(<2 x i8> %x) {
158 ; CHECK-LABEL: @ne_nsw_rem_zero_undef2(
159 ; CHECK-NEXT: [[A:%.*]] = mul nsw <2 x i8> [[X:%.*]], <i8 5, i8 5>
160 ; CHECK-NEXT: [[B:%.*]] = icmp ne <2 x i8> [[A]], <i8 -30, i8 undef>
161 ; CHECK-NEXT: ret <2 x i1> [[B]]
163 %a = mul nsw <2 x i8> %x, <i8 5, i8 5>
164 %b = icmp ne <2 x i8> %a, <i8 -30, i8 undef>
168 define i1 @eq_nsw_rem_zero_uses(i8 %x) {
169 ; CHECK-LABEL: @eq_nsw_rem_zero_uses(
170 ; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], -5
171 ; CHECK-NEXT: call void @use(i8 [[A]])
172 ; CHECK-NEXT: [[B:%.*]] = icmp eq i8 [[X]], -4
173 ; CHECK-NEXT: ret i1 [[B]]
175 %a = mul nsw i8 %x, -5
176 call void @use(i8 %a)
177 %b = icmp eq i8 %a, 20
181 ; Impossible multiple should be handled by instsimplify.
183 define i1 @eq_nsw_rem_nz(i8 %x) {
184 ; CHECK-LABEL: @eq_nsw_rem_nz(
185 ; CHECK-NEXT: ret i1 false
187 %a = mul nsw i8 %x, 5
188 %b = icmp eq i8 %a, 245
192 ; Impossible multiple should be handled by instsimplify.
194 define i1 @ne_nsw_rem_nz(i8 %x) {
195 ; CHECK-LABEL: @ne_nsw_rem_nz(
196 ; CHECK-NEXT: ret i1 true
198 %a = mul nsw i8 %x, 5
199 %b = icmp ne i8 %a, 130
203 define <2 x i1> @eq_nuw_rem_zero(<2 x i8> %x) {
204 ; CHECK-LABEL: @eq_nuw_rem_zero(
205 ; CHECK-NEXT: [[B:%.*]] = icmp eq <2 x i8> [[X:%.*]], <i8 4, i8 4>
206 ; CHECK-NEXT: ret <2 x i1> [[B]]
208 %a = mul nuw <2 x i8> %x, <i8 5, i8 5>
209 %b = icmp eq <2 x i8> %a, <i8 20, i8 20>
213 ; TODO: Missed fold with undef.
215 define <2 x i1> @eq_nuw_rem_zero_undef1(<2 x i8> %x) {
216 ; CHECK-LABEL: @eq_nuw_rem_zero_undef1(
217 ; CHECK-NEXT: [[A:%.*]] = mul nuw <2 x i8> [[X:%.*]], <i8 undef, i8 5>
218 ; CHECK-NEXT: [[B:%.*]] = icmp eq <2 x i8> [[A]], <i8 20, i8 20>
219 ; CHECK-NEXT: ret <2 x i1> [[B]]
221 %a = mul nuw <2 x i8> %x, <i8 undef, i8 5>
222 %b = icmp eq <2 x i8> %a, <i8 20, i8 20>
226 ; TODO: Missed fold with undef.
228 define <2 x i1> @eq_nuw_rem_zero_undef2(<2 x i8> %x) {
229 ; CHECK-LABEL: @eq_nuw_rem_zero_undef2(
230 ; CHECK-NEXT: [[A:%.*]] = mul nuw <2 x i8> [[X:%.*]], <i8 5, i8 5>
231 ; CHECK-NEXT: [[B:%.*]] = icmp eq <2 x i8> [[A]], <i8 undef, i8 20>
232 ; CHECK-NEXT: ret <2 x i1> [[B]]
234 %a = mul nuw <2 x i8> %x, <i8 5, i8 5>
235 %b = icmp eq <2 x i8> %a, <i8 undef, i8 20>
239 define i1 @ne_nuw_rem_zero(i8 %x) {
240 ; CHECK-LABEL: @ne_nuw_rem_zero(
241 ; CHECK-NEXT: [[B:%.*]] = icmp ne i8 [[X:%.*]], 26
242 ; CHECK-NEXT: ret i1 [[B]]
244 %a = mul nuw i8 %x, 5
245 %b = icmp ne i8 %a, 130
249 define i1 @ne_nuw_rem_zero_uses(i8 %x) {
250 ; CHECK-LABEL: @ne_nuw_rem_zero_uses(
251 ; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5
252 ; CHECK-NEXT: call void @use(i8 [[A]])
253 ; CHECK-NEXT: [[B:%.*]] = icmp ne i8 [[X]], 26
254 ; CHECK-NEXT: ret i1 [[B]]
256 %a = mul nuw i8 %x, 5
257 call void @use(i8 %a)
258 %b = icmp ne i8 %a, 130
262 ; Impossible multiple should be handled by instsimplify.
264 define i1 @eq_nuw_rem_nz(i8 %x) {
265 ; CHECK-LABEL: @eq_nuw_rem_nz(
266 ; CHECK-NEXT: ret i1 false
268 %a = mul nuw i8 %x, -5
269 %b = icmp eq i8 %a, 20
273 ; Impossible multiple should be handled by instsimplify.
275 define i1 @ne_nuw_rem_nz(i8 %x) {
276 ; CHECK-LABEL: @ne_nuw_rem_nz(
277 ; CHECK-NEXT: ret i1 true
279 %a = mul nuw i8 %x, 5
280 %b = icmp ne i8 %a, -30
284 ; Negative tests for the icmp mul folds
286 define i1 @sgt_positive_multip_rem_zero_nonsw(i8 %x) {
287 ; CHECK-LABEL: @sgt_positive_multip_rem_zero_nonsw(
288 ; CHECK-NEXT: [[A:%.*]] = mul i8 [[X:%.*]], 7
289 ; CHECK-NEXT: [[B:%.*]] = icmp sgt i8 [[A]], 21
290 ; CHECK-NEXT: ret i1 [[B]]
293 %b = icmp sgt i8 %a, 21
297 define i1 @ult_multip_rem_zero_nonsw(i8 %x) {
298 ; CHECK-LABEL: @ult_multip_rem_zero_nonsw(
299 ; CHECK-NEXT: [[A:%.*]] = mul i8 [[X:%.*]], 7
300 ; CHECK-NEXT: [[B:%.*]] = icmp ult i8 [[A]], 21
301 ; CHECK-NEXT: ret i1 [[B]]
304 %b = icmp ult i8 %a, 21
308 define i1 @ugt_rem_zero_nonuw(i8 %x) {
309 ; CHECK-LABEL: @ugt_rem_zero_nonuw(
310 ; CHECK-NEXT: [[A:%.*]] = mul i8 [[X:%.*]], 7
311 ; CHECK-NEXT: [[B:%.*]] = icmp ugt i8 [[A]], 21
312 ; CHECK-NEXT: ret i1 [[B]]
315 %b = icmp ugt i8 %a, 21
319 define i1 @sgt_minnum(i8 %x) {
320 ; CHECK-LABEL: @sgt_minnum(
321 ; CHECK-NEXT: ret i1 true
323 %a = mul nsw i8 %x, 7
324 %b = icmp sgt i8 %a, -128
328 define i1 @ule_bignum(i8 %x) {
329 ; CHECK-LABEL: @ule_bignum(
330 ; CHECK-NEXT: [[B:%.*]] = icmp eq i8 [[X:%.*]], 0
331 ; CHECK-NEXT: ret i1 [[B]]
333 %a = mul i8 %x, 2147483647
334 %b = icmp ule i8 %a, 0
338 define i1 @sgt_mulzero(i8 %x) {
339 ; CHECK-LABEL: @sgt_mulzero(
340 ; CHECK-NEXT: ret i1 false
342 %a = mul nsw i8 %x, 0
343 %b = icmp sgt i8 %a, 21
347 define i1 @eq_rem_zero_nonuw(i8 %x) {
348 ; CHECK-LABEL: @eq_rem_zero_nonuw(
349 ; CHECK-NEXT: [[A:%.*]] = mul i8 [[X:%.*]], 5
350 ; CHECK-NEXT: [[B:%.*]] = icmp eq i8 [[A]], 20
351 ; CHECK-NEXT: ret i1 [[B]]
354 %b = icmp eq i8 %a, 20
358 define i1 @ne_rem_zero_nonuw(i8 %x) {
359 ; CHECK-LABEL: @ne_rem_zero_nonuw(
360 ; CHECK-NEXT: [[A:%.*]] = mul i8 [[X:%.*]], 5
361 ; CHECK-NEXT: [[B:%.*]] = icmp ne i8 [[A]], 30
362 ; CHECK-NEXT: ret i1 [[B]]
365 %b = icmp ne i8 %a, 30
369 define i1 @mul_constant_eq(i32 %x, i32 %y) {
370 ; CHECK-LABEL: @mul_constant_eq(
371 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
372 ; CHECK-NEXT: ret i1 [[C]]
376 %C = icmp eq i32 %A, %B
380 define <2 x i1> @mul_constant_ne_splat(<2 x i32> %x, <2 x i32> %y) {
381 ; CHECK-LABEL: @mul_constant_ne_splat(
382 ; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i32> [[X:%.*]], [[Y:%.*]]
383 ; CHECK-NEXT: ret <2 x i1> [[C]]
385 %A = mul <2 x i32> %x, <i32 5, i32 5>
386 %B = mul <2 x i32> %y, <i32 5, i32 5>
387 %C = icmp ne <2 x i32> %A, %B
391 define i1 @mul_constant_ne_extra_use1(i8 %x, i8 %y) {
392 ; CHECK-LABEL: @mul_constant_ne_extra_use1(
393 ; CHECK-NEXT: [[A:%.*]] = mul i8 [[X:%.*]], 5
394 ; CHECK-NEXT: call void @use(i8 [[A]])
395 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[X]], [[Y:%.*]]
396 ; CHECK-NEXT: ret i1 [[C]]
399 call void @use(i8 %A)
401 %C = icmp ne i8 %A, %B
405 define i1 @mul_constant_eq_extra_use2(i8 %x, i8 %y) {
406 ; CHECK-LABEL: @mul_constant_eq_extra_use2(
407 ; CHECK-NEXT: [[B:%.*]] = mul i8 [[Y:%.*]], 5
408 ; CHECK-NEXT: call void @use(i8 [[B]])
409 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[X:%.*]], [[Y]]
410 ; CHECK-NEXT: ret i1 [[C]]
414 call void @use(i8 %B)
415 %C = icmp eq i8 %A, %B
419 define i1 @mul_constant_ne_extra_use3(i8 %x, i8 %y) {
420 ; CHECK-LABEL: @mul_constant_ne_extra_use3(
421 ; CHECK-NEXT: [[A:%.*]] = mul i8 [[X:%.*]], 5
422 ; CHECK-NEXT: call void @use(i8 [[A]])
423 ; CHECK-NEXT: [[B:%.*]] = mul i8 [[Y:%.*]], 5
424 ; CHECK-NEXT: call void @use(i8 [[B]])
425 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[X]], [[Y]]
426 ; CHECK-NEXT: ret i1 [[C]]
429 call void @use(i8 %A)
431 call void @use(i8 %B)
432 %C = icmp ne i8 %A, %B
436 define i1 @mul_constant_eq_nsw(i32 %x, i32 %y) {
437 ; CHECK-LABEL: @mul_constant_eq_nsw(
438 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
439 ; CHECK-NEXT: ret i1 [[C]]
441 %A = mul nsw i32 %x, 6
442 %B = mul nsw i32 %y, 6
443 %C = icmp eq i32 %A, %B
447 define <2 x i1> @mul_constant_ne_nsw_splat(<2 x i32> %x, <2 x i32> %y) {
448 ; CHECK-LABEL: @mul_constant_ne_nsw_splat(
449 ; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i32> [[X:%.*]], [[Y:%.*]]
450 ; CHECK-NEXT: ret <2 x i1> [[C]]
452 %A = mul nsw <2 x i32> %x, <i32 12, i32 12>
453 %B = mul nsw <2 x i32> %y, <i32 12, i32 12>
454 %C = icmp ne <2 x i32> %A, %B
458 define i1 @mul_constant_ne_nsw_extra_use1(i8 %x, i8 %y) {
459 ; CHECK-LABEL: @mul_constant_ne_nsw_extra_use1(
460 ; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], 74
461 ; CHECK-NEXT: call void @use(i8 [[A]])
462 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[X]], [[Y:%.*]]
463 ; CHECK-NEXT: ret i1 [[C]]
465 %A = mul nsw i8 %x, 74
466 call void @use(i8 %A)
467 %B = mul nsw i8 %y, 74
468 %C = icmp ne i8 %A, %B
472 define i1 @mul_constant_eq_nsw_extra_use2(i8 %x, i8 %y) {
473 ; CHECK-LABEL: @mul_constant_eq_nsw_extra_use2(
474 ; CHECK-NEXT: [[B:%.*]] = mul nsw i8 [[Y:%.*]], 20
475 ; CHECK-NEXT: call void @use(i8 [[B]])
476 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[X:%.*]], [[Y]]
477 ; CHECK-NEXT: ret i1 [[C]]
479 %A = mul nsw i8 %x, 20
480 %B = mul nsw i8 %y, 20
481 call void @use(i8 %B)
482 %C = icmp eq i8 %A, %B
486 define i1 @mul_constant_ne_nsw_extra_use3(i8 %x, i8 %y) {
487 ; CHECK-LABEL: @mul_constant_ne_nsw_extra_use3(
488 ; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], 24
489 ; CHECK-NEXT: call void @use(i8 [[A]])
490 ; CHECK-NEXT: [[B:%.*]] = mul nsw i8 [[Y:%.*]], 24
491 ; CHECK-NEXT: call void @use(i8 [[B]])
492 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[X]], [[Y]]
493 ; CHECK-NEXT: ret i1 [[C]]
495 %A = mul nsw i8 %x, 24
496 call void @use(i8 %A)
497 %B = mul nsw i8 %y, 24
498 call void @use(i8 %B)
499 %C = icmp ne i8 %A, %B
503 define i1 @mul_constant_nuw_eq(i32 %x, i32 %y) {
504 ; CHECK-LABEL: @mul_constant_nuw_eq(
505 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
506 ; CHECK-NEXT: ret i1 [[C]]
508 %A = mul nuw i32 %x, 22
509 %B = mul nuw i32 %y, 22
510 %C = icmp eq i32 %A, %B
514 define <2 x i1> @mul_constant_ne_nuw_splat(<2 x i32> %x, <2 x i32> %y) {
515 ; CHECK-LABEL: @mul_constant_ne_nuw_splat(
516 ; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i32> [[X:%.*]], [[Y:%.*]]
517 ; CHECK-NEXT: ret <2 x i1> [[C]]
519 %A = mul nuw <2 x i32> %x, <i32 10, i32 10>
520 %B = mul nuw <2 x i32> %y, <i32 10, i32 10>
521 %C = icmp ne <2 x i32> %A, %B
525 define i1 @mul_constant_ne_nuw_extra_use1(i8 %x, i8 %y) {
526 ; CHECK-LABEL: @mul_constant_ne_nuw_extra_use1(
527 ; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 6
528 ; CHECK-NEXT: call void @use(i8 [[A]])
529 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[X]], [[Y:%.*]]
530 ; CHECK-NEXT: ret i1 [[C]]
532 %A = mul nuw i8 %x, 6
533 call void @use(i8 %A)
534 %B = mul nuw i8 %y, 6
535 %C = icmp ne i8 %A, %B
539 define i1 @mul_constant_eq_nuw_extra_use2(i8 %x, i8 %y) {
540 ; CHECK-LABEL: @mul_constant_eq_nuw_extra_use2(
541 ; CHECK-NEXT: [[B:%.*]] = mul nuw i8 [[Y:%.*]], 36
542 ; CHECK-NEXT: call void @use(i8 [[B]])
543 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[X:%.*]], [[Y]]
544 ; CHECK-NEXT: ret i1 [[C]]
546 %A = mul nuw i8 %x, 36
547 %B = mul nuw i8 %y, 36
548 call void @use(i8 %B)
549 %C = icmp eq i8 %A, %B
553 define i1 @mul_constant_ne_nuw_extra_use3(i8 %x, i8 %y) {
554 ; CHECK-LABEL: @mul_constant_ne_nuw_extra_use3(
555 ; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 38
556 ; CHECK-NEXT: call void @use(i8 [[A]])
557 ; CHECK-NEXT: [[B:%.*]] = mul nuw i8 [[Y:%.*]], 38
558 ; CHECK-NEXT: call void @use(i8 [[B]])
559 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[X]], [[Y]]
560 ; CHECK-NEXT: ret i1 [[C]]
562 %A = mul nuw i8 %x, 38
563 call void @use(i8 %A)
564 %B = mul nuw i8 %y, 38
565 call void @use(i8 %B)
566 %C = icmp ne i8 %A, %B
570 ; Negative test - wrong pred
572 define i1 @mul_constant_ult(i32 %x, i32 %y) {
573 ; CHECK-LABEL: @mul_constant_ult(
574 ; CHECK-NEXT: [[A:%.*]] = mul i32 [[X:%.*]], 47
575 ; CHECK-NEXT: [[B:%.*]] = mul i32 [[Y:%.*]], 47
576 ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[A]], [[B]]
577 ; CHECK-NEXT: ret i1 [[C]]
581 %C = icmp ult i32 %A, %B
585 ; Negative test - wrong pred
587 define i1 @mul_constant_nuw_sgt(i32 %x, i32 %y) {
588 ; CHECK-LABEL: @mul_constant_nuw_sgt(
589 ; CHECK-NEXT: [[A:%.*]] = mul nuw i32 [[X:%.*]], 46
590 ; CHECK-NEXT: [[B:%.*]] = mul nuw i32 [[Y:%.*]], 46
591 ; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[A]], [[B]]
592 ; CHECK-NEXT: ret i1 [[C]]
594 %A = mul nuw i32 %x, 46
595 %B = mul nuw i32 %y, 46
596 %C = icmp sgt i32 %A, %B
600 ; Negative test - wrong constants
602 define i1 @mul_mismatch_constant_nuw_eq(i32 %x, i32 %y) {
603 ; CHECK-LABEL: @mul_mismatch_constant_nuw_eq(
604 ; CHECK-NEXT: [[A:%.*]] = mul nuw i32 [[X:%.*]], 46
605 ; CHECK-NEXT: [[B:%.*]] = mul nuw i32 [[Y:%.*]], 44
606 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[A]], [[B]]
607 ; CHECK-NEXT: ret i1 [[C]]
609 %A = mul nuw i32 %x, 46
610 %B = mul nuw i32 %y, 44
611 %C = icmp eq i32 %A, %B
615 ; If the multiply constant has any trailing zero bits but could overflow,
616 ; we get something completely different.
617 ; We mask off the high bits of each input and then convert:
618 ; (X&Z) == (Y&Z) -> (X^Y) & Z == 0
620 define i1 @mul_constant_partial_nuw_eq(i32 %x, i32 %y) {
621 ; CHECK-LABEL: @mul_constant_partial_nuw_eq(
622 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
623 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 1073741823
624 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[TMP2]], 0
625 ; CHECK-NEXT: ret i1 [[C]]
628 %B = mul nuw i32 %y, 44
629 %C = icmp eq i32 %A, %B
633 define i1 @mul_constant_mismatch_wrap_eq(i32 %x, i32 %y) {
634 ; CHECK-LABEL: @mul_constant_mismatch_wrap_eq(
635 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
636 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 2147483647
637 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[TMP2]], 0
638 ; CHECK-NEXT: ret i1 [[C]]
640 %A = mul nsw i32 %x, 54
641 %B = mul nuw i32 %y, 54
642 %C = icmp eq i32 %A, %B
646 define i1 @eq_mul_constants_with_tz(i32 %x, i32 %y) {
647 ; CHECK-LABEL: @eq_mul_constants_with_tz(
648 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
649 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 1073741823
650 ; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[TMP2]], 0
651 ; CHECK-NEXT: ret i1 [[C]]
655 %C = icmp ne i32 %A, %B
659 define <2 x i1> @eq_mul_constants_with_tz_splat(<2 x i32> %x, <2 x i32> %y) {
660 ; CHECK-LABEL: @eq_mul_constants_with_tz_splat(
661 ; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i32> [[X:%.*]], [[Y:%.*]]
662 ; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], <i32 1073741823, i32 1073741823>
663 ; CHECK-NEXT: [[C:%.*]] = icmp eq <2 x i32> [[TMP2]], zeroinitializer
664 ; CHECK-NEXT: ret <2 x i1> [[C]]
666 %A = mul <2 x i32> %x, <i32 12, i32 12>
667 %B = mul <2 x i32> %y, <i32 12, i32 12>
668 %C = icmp eq <2 x i32> %A, %B