1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 declare i32 @llvm.abs.i32(i32, i1)
6 define i32 @pow2_multiplier(i32 %A) {
7 ; CHECK-LABEL: @pow2_multiplier(
8 ; CHECK-NEXT: [[B:%.*]] = shl i32 [[A:%.*]], 1
9 ; CHECK-NEXT: ret i32 [[B]]
15 define <2 x i32> @pow2_multiplier_vec(<2 x i32> %A) {
16 ; CHECK-LABEL: @pow2_multiplier_vec(
17 ; CHECK-NEXT: [[B:%.*]] = shl <2 x i32> [[A:%.*]], splat (i32 3)
18 ; CHECK-NEXT: ret <2 x i32> [[B]]
20 %B = mul <2 x i32> %A, <i32 8, i32 8>
24 define i8 @combine_shl(i8 %A) {
25 ; CHECK-LABEL: @combine_shl(
26 ; CHECK-NEXT: [[C:%.*]] = shl i8 [[A:%.*]], 6
27 ; CHECK-NEXT: ret i8 [[C]]
34 define i32 @neg(i32 %i) {
36 ; CHECK-NEXT: [[T:%.*]] = sub i32 0, [[I:%.*]]
37 ; CHECK-NEXT: ret i32 [[T]]
43 ; Use the sign-bit as a mask:
44 ; (zext (A < 0)) * B --> (A >> 31) & B
46 define i32 @test10(i32 %a, i32 %b) {
47 ; CHECK-LABEL: @test10(
48 ; CHECK-NEXT: [[ISNEG:%.*]] = icmp slt i32 [[A:%.*]], 0
49 ; CHECK-NEXT: [[E:%.*]] = select i1 [[ISNEG]], i32 [[B:%.*]], i32 0
50 ; CHECK-NEXT: ret i32 [[E]]
52 %c = icmp slt i32 %a, 0
53 %d = zext i1 %c to i32
58 define i32 @test11(i32 %a, i32 %b) {
59 ; CHECK-LABEL: @test11(
60 ; CHECK-NEXT: [[ISNEG:%.*]] = icmp slt i32 [[A:%.*]], 0
61 ; CHECK-NEXT: [[E:%.*]] = select i1 [[ISNEG]], i32 [[B:%.*]], i32 0
62 ; CHECK-NEXT: ret i32 [[E]]
64 %c = icmp sle i32 %a, -1
65 %d = zext i1 %c to i32
70 declare void @use32(i32)
72 define i32 @test12(i32 %a, i32 %b) {
73 ; CHECK-LABEL: @test12(
74 ; CHECK-NEXT: [[A_LOBIT:%.*]] = lshr i32 [[A:%.*]], 31
75 ; CHECK-NEXT: [[ISNEG:%.*]] = icmp slt i32 [[A]], 0
76 ; CHECK-NEXT: [[E:%.*]] = select i1 [[ISNEG]], i32 [[B:%.*]], i32 0
77 ; CHECK-NEXT: call void @use32(i32 [[A_LOBIT]])
78 ; CHECK-NEXT: ret i32 [[E]]
80 %c = icmp ugt i32 %a, 2147483647
81 %d = zext i1 %c to i32
83 call void @use32(i32 %d)
88 define i32 @test15(i32 %A, i32 %B) {
89 ; CHECK-LABEL: @test15(
90 ; CHECK-NEXT: [[M1:%.*]] = shl i32 [[A:%.*]], [[B:%.*]]
91 ; CHECK-NEXT: ret i32 [[M1]]
98 ; X * Y (when Y is a boolean) --> Y ? X : 0
100 define i32 @mul_bool(i32 %x, i1 %y) {
101 ; CHECK-LABEL: @mul_bool(
102 ; CHECK-NEXT: [[M:%.*]] = select i1 [[Y:%.*]], i32 [[X:%.*]], i32 0
103 ; CHECK-NEXT: ret i32 [[M]]
105 %z = zext i1 %y to i32
110 ; Commute and test vector type.
112 define <2 x i32> @mul_bool_vec(<2 x i32> %x, <2 x i1> %y) {
113 ; CHECK-LABEL: @mul_bool_vec(
114 ; CHECK-NEXT: [[M:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i32> [[X:%.*]], <2 x i32> zeroinitializer
115 ; CHECK-NEXT: ret <2 x i32> [[M]]
117 %z = zext <2 x i1> %y to <2 x i32>
118 %m = mul <2 x i32> %x, %z
122 define <2 x i32> @mul_bool_vec_commute(<2 x i32> %x, <2 x i1> %y) {
123 ; CHECK-LABEL: @mul_bool_vec_commute(
124 ; CHECK-NEXT: [[M:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i32> [[X:%.*]], <2 x i32> zeroinitializer
125 ; CHECK-NEXT: ret <2 x i32> [[M]]
127 %z = zext <2 x i1> %y to <2 x i32>
128 %m = mul <2 x i32> %z, %x
132 define <3 x i7> @mul_bools(<3 x i1> %x, <3 x i1> %y) {
133 ; CHECK-LABEL: @mul_bools(
134 ; CHECK-NEXT: [[MULBOOL:%.*]] = and <3 x i1> [[X:%.*]], [[Y:%.*]]
135 ; CHECK-NEXT: [[R:%.*]] = zext <3 x i1> [[MULBOOL]] to <3 x i7>
136 ; CHECK-NEXT: ret <3 x i7> [[R]]
138 %zx = zext <3 x i1> %x to <3 x i7>
139 %zy = zext <3 x i1> %y to <3 x i7>
140 %r = mul <3 x i7> %zx, %zy
144 define i32 @mul_bools_use1(i1 %x, i1 %y) {
145 ; CHECK-LABEL: @mul_bools_use1(
146 ; CHECK-NEXT: [[ZY:%.*]] = zext i1 [[Y:%.*]] to i32
147 ; CHECK-NEXT: call void @use32(i32 [[ZY]])
148 ; CHECK-NEXT: [[MULBOOL:%.*]] = and i1 [[X:%.*]], [[Y]]
149 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[MULBOOL]] to i32
150 ; CHECK-NEXT: ret i32 [[R]]
152 %zx = zext i1 %x to i32
153 %zy = zext i1 %y to i32
154 call void @use32(i32 %zy)
155 %r = mul i32 %zx, %zy
159 define i32 @mul_bools_use2(i1 %x, i1 %y) {
160 ; CHECK-LABEL: @mul_bools_use2(
161 ; CHECK-NEXT: [[ZY:%.*]] = zext i1 [[Y:%.*]] to i32
162 ; CHECK-NEXT: call void @use32(i32 [[ZY]])
163 ; CHECK-NEXT: [[MULBOOL:%.*]] = and i1 [[Y]], [[X:%.*]]
164 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[MULBOOL]] to i32
165 ; CHECK-NEXT: ret i32 [[R]]
167 %zx = zext i1 %x to i32
168 %zy = zext i1 %y to i32
169 call void @use32(i32 %zy)
170 %r = mul i32 %zy, %zx
174 define i32 @mul_bools_use3(i1 %x, i1 %y) {
175 ; CHECK-LABEL: @mul_bools_use3(
176 ; CHECK-NEXT: [[ZX:%.*]] = zext i1 [[X:%.*]] to i32
177 ; CHECK-NEXT: call void @use32(i32 [[ZX]])
178 ; CHECK-NEXT: [[ZY:%.*]] = zext i1 [[Y:%.*]] to i32
179 ; CHECK-NEXT: call void @use32(i32 [[ZY]])
180 ; CHECK-NEXT: [[R:%.*]] = select i1 [[X]], i32 [[ZY]], i32 0
181 ; CHECK-NEXT: ret i32 [[R]]
183 %zx = zext i1 %x to i32
184 call void @use32(i32 %zx)
185 %zy = zext i1 %y to i32
186 call void @use32(i32 %zy)
187 %r = mul i32 %zx, %zy
191 define <3 x i32> @mul_bools_sext(<3 x i1> %x, <3 x i1> %y) {
192 ; CHECK-LABEL: @mul_bools_sext(
193 ; CHECK-NEXT: [[MULBOOL:%.*]] = and <3 x i1> [[X:%.*]], [[Y:%.*]]
194 ; CHECK-NEXT: [[R:%.*]] = zext <3 x i1> [[MULBOOL]] to <3 x i32>
195 ; CHECK-NEXT: ret <3 x i32> [[R]]
197 %sx = sext <3 x i1> %x to <3 x i32>
198 %sy = sext <3 x i1> %y to <3 x i32>
199 %r = mul <3 x i32> %sx, %sy
203 define i32 @mul_bools_sext_use1(i1 %x, i1 %y) {
204 ; CHECK-LABEL: @mul_bools_sext_use1(
205 ; CHECK-NEXT: [[SY:%.*]] = sext i1 [[Y:%.*]] to i32
206 ; CHECK-NEXT: call void @use32(i32 [[SY]])
207 ; CHECK-NEXT: [[MULBOOL:%.*]] = and i1 [[X:%.*]], [[Y]]
208 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[MULBOOL]] to i32
209 ; CHECK-NEXT: ret i32 [[R]]
211 %sx = sext i1 %x to i32
212 %sy = sext i1 %y to i32
213 call void @use32(i32 %sy)
214 %r = mul i32 %sx, %sy
218 define i32 @mul_bools_sext_use2(i1 %x, i1 %y) {
219 ; CHECK-LABEL: @mul_bools_sext_use2(
220 ; CHECK-NEXT: [[SY:%.*]] = sext i1 [[Y:%.*]] to i32
221 ; CHECK-NEXT: call void @use32(i32 [[SY]])
222 ; CHECK-NEXT: [[MULBOOL:%.*]] = and i1 [[Y]], [[X:%.*]]
223 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[MULBOOL]] to i32
224 ; CHECK-NEXT: ret i32 [[R]]
226 %sx = sext i1 %x to i32
227 %sy = sext i1 %y to i32
228 call void @use32(i32 %sy)
229 %r = mul i32 %sy, %sx
233 define i32 @mul_bools_sext_use3(i1 %x, i1 %y) {
234 ; CHECK-LABEL: @mul_bools_sext_use3(
235 ; CHECK-NEXT: [[SX:%.*]] = sext i1 [[X:%.*]] to i32
236 ; CHECK-NEXT: call void @use32(i32 [[SX]])
237 ; CHECK-NEXT: [[SY:%.*]] = sext i1 [[Y:%.*]] to i32
238 ; CHECK-NEXT: call void @use32(i32 [[SY]])
239 ; CHECK-NEXT: [[R:%.*]] = mul nsw i32 [[SY]], [[SX]]
240 ; CHECK-NEXT: ret i32 [[R]]
242 %sx = sext i1 %x to i32
243 call void @use32(i32 %sx)
244 %sy = sext i1 %y to i32
245 call void @use32(i32 %sy)
246 %r = mul i32 %sy, %sx
250 define <3 x i32> @mul_bools_mixed_ext(<3 x i1> %x, <3 x i1> %y) {
251 ; CHECK-LABEL: @mul_bools_mixed_ext(
252 ; CHECK-NEXT: [[MULBOOL:%.*]] = and <3 x i1> [[X:%.*]], [[Y:%.*]]
253 ; CHECK-NEXT: [[R:%.*]] = sext <3 x i1> [[MULBOOL]] to <3 x i32>
254 ; CHECK-NEXT: ret <3 x i32> [[R]]
256 %zx = zext <3 x i1> %x to <3 x i32>
257 %sy = sext <3 x i1> %y to <3 x i32>
258 %r = mul <3 x i32> %zx, %sy
262 define i32 @mul_bools_mixed_ext_use1(i1 %x, i1 %y) {
263 ; CHECK-LABEL: @mul_bools_mixed_ext_use1(
264 ; CHECK-NEXT: [[ZY:%.*]] = zext i1 [[Y:%.*]] to i32
265 ; CHECK-NEXT: call void @use32(i32 [[ZY]])
266 ; CHECK-NEXT: [[MULBOOL:%.*]] = and i1 [[X:%.*]], [[Y]]
267 ; CHECK-NEXT: [[R:%.*]] = sext i1 [[MULBOOL]] to i32
268 ; CHECK-NEXT: ret i32 [[R]]
270 %sx = sext i1 %x to i32
271 %zy = zext i1 %y to i32
272 call void @use32(i32 %zy)
273 %r = mul i32 %sx, %zy
277 define i32 @mul_bools_mixed_ext_use2(i1 %x, i1 %y) {
278 ; CHECK-LABEL: @mul_bools_mixed_ext_use2(
279 ; CHECK-NEXT: [[SY:%.*]] = sext i1 [[Y:%.*]] to i32
280 ; CHECK-NEXT: call void @use32(i32 [[SY]])
281 ; CHECK-NEXT: [[MULBOOL:%.*]] = and i1 [[Y]], [[X:%.*]]
282 ; CHECK-NEXT: [[R:%.*]] = sext i1 [[MULBOOL]] to i32
283 ; CHECK-NEXT: ret i32 [[R]]
285 %zx = zext i1 %x to i32
286 %sy = sext i1 %y to i32
287 call void @use32(i32 %sy)
288 %r = mul i32 %sy, %zx
292 define i32 @mul_bools_mixed_ext_use3(i1 %x, i1 %y) {
293 ; CHECK-LABEL: @mul_bools_mixed_ext_use3(
294 ; CHECK-NEXT: [[SX:%.*]] = sext i1 [[X:%.*]] to i32
295 ; CHECK-NEXT: call void @use32(i32 [[SX]])
296 ; CHECK-NEXT: [[ZY:%.*]] = zext i1 [[Y:%.*]] to i32
297 ; CHECK-NEXT: call void @use32(i32 [[ZY]])
298 ; CHECK-NEXT: [[R:%.*]] = select i1 [[Y]], i32 [[SX]], i32 0
299 ; CHECK-NEXT: ret i32 [[R]]
301 %sx = sext i1 %x to i32
302 call void @use32(i32 %sx)
303 %zy = zext i1 %y to i32
304 call void @use32(i32 %zy)
305 %r = mul i32 %zy, %sx
309 ; (A >>u 31) * B --> (A >>s 31) & B
311 define i32 @signbit_mul(i32 %a, i32 %b) {
312 ; CHECK-LABEL: @signbit_mul(
313 ; CHECK-NEXT: [[ISNEG:%.*]] = icmp slt i32 [[A:%.*]], 0
314 ; CHECK-NEXT: [[E:%.*]] = select i1 [[ISNEG]], i32 [[B:%.*]], i32 0
315 ; CHECK-NEXT: ret i32 [[E]]
322 define i32 @signbit_mul_commute_extra_use(i32 %a, i32 %b) {
323 ; CHECK-LABEL: @signbit_mul_commute_extra_use(
324 ; CHECK-NEXT: [[D:%.*]] = lshr i32 [[A:%.*]], 31
325 ; CHECK-NEXT: [[ISNEG:%.*]] = icmp slt i32 [[A]], 0
326 ; CHECK-NEXT: [[E:%.*]] = select i1 [[ISNEG]], i32 [[B:%.*]], i32 0
327 ; CHECK-NEXT: call void @use32(i32 [[D]])
328 ; CHECK-NEXT: ret i32 [[E]]
332 call void @use32(i32 %d)
336 ; (A >>u 31)) * B --> (A >>s 31) & B
338 define <2 x i32> @signbit_mul_vec(<2 x i32> %a, <2 x i32> %b) {
339 ; CHECK-LABEL: @signbit_mul_vec(
340 ; CHECK-NEXT: [[ISNEG:%.*]] = icmp slt <2 x i32> [[A:%.*]], zeroinitializer
341 ; CHECK-NEXT: [[E:%.*]] = select <2 x i1> [[ISNEG]], <2 x i32> [[B:%.*]], <2 x i32> zeroinitializer
342 ; CHECK-NEXT: ret <2 x i32> [[E]]
344 %d = lshr <2 x i32> %a, <i32 31, i32 31>
345 %e = mul <2 x i32> %d, %b
349 define <2 x i32> @signbit_mul_vec_commute(<2 x i32> %a, <2 x i32> %b) {
350 ; CHECK-LABEL: @signbit_mul_vec_commute(
351 ; CHECK-NEXT: [[ISNEG:%.*]] = icmp slt <2 x i32> [[A:%.*]], zeroinitializer
352 ; CHECK-NEXT: [[E:%.*]] = select <2 x i1> [[ISNEG]], <2 x i32> [[B:%.*]], <2 x i32> zeroinitializer
353 ; CHECK-NEXT: ret <2 x i32> [[E]]
355 %d = lshr <2 x i32> %a, <i32 31, i32 31>
356 %e = mul <2 x i32> %b, %d
360 define i32 @test18(i32 %A, i32 %B) {
361 ; CHECK-LABEL: @test18(
362 ; CHECK-NEXT: ret i32 0
371 declare {i32, i1} @llvm.smul.with.overflow.i32(i32, i32)
372 declare void @use(i1)
374 define i32 @test19(i32 %A, i32 %B) {
375 ; CHECK-LABEL: @test19(
376 ; CHECK-NEXT: call void @use(i1 false)
377 ; CHECK-NEXT: ret i32 0
382 ; It would be nice if we also started proving that this doesn't overflow.
383 %E = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %C, i32 %D)
384 %F = extractvalue {i32, i1} %E, 0
385 %G = extractvalue {i32, i1} %E, 1
386 call void @use(i1 %G)
391 define <2 x i64> @test20(<2 x i64> %A) {
392 ; CHECK-LABEL: @test20(
393 ; CHECK-NEXT: [[TMP1:%.*]] = mul <2 x i64> [[A:%.*]], <i64 3, i64 2>
394 ; CHECK-NEXT: [[C:%.*]] = add <2 x i64> [[TMP1]], <i64 36, i64 28>
395 ; CHECK-NEXT: ret <2 x i64> [[C]]
397 %B = add <2 x i64> %A, <i64 12, i64 14>
398 %C = mul <2 x i64> %B, <i64 3, i64 2>
402 define <2 x i1> @test21(<2 x i1> %A, <2 x i1> %B) {
403 ; CHECK-LABEL: @test21(
404 ; CHECK-NEXT: [[C:%.*]] = and <2 x i1> [[A:%.*]], [[B:%.*]]
405 ; CHECK-NEXT: ret <2 x i1> [[C]]
407 %C = mul <2 x i1> %A, %B
411 define i32 @test22(i32 %A) {
412 ; CHECK-LABEL: @test22(
413 ; CHECK-NEXT: [[B:%.*]] = sub nsw i32 0, [[A:%.*]]
414 ; CHECK-NEXT: ret i32 [[B]]
416 %B = mul nsw i32 %A, -1
420 define i32 @test23(i32 %A) {
421 ; CHECK-LABEL: @test23(
422 ; CHECK-NEXT: [[C:%.*]] = mul nuw i32 [[A:%.*]], 6
423 ; CHECK-NEXT: ret i32 [[C]]
425 %B = shl nuw i32 %A, 1
426 %C = mul nuw i32 %B, 3
430 define i32 @test24(i32 %A) {
431 ; CHECK-LABEL: @test24(
432 ; CHECK-NEXT: [[C:%.*]] = mul nsw i32 [[A:%.*]], 6
433 ; CHECK-NEXT: ret i32 [[C]]
435 %B = shl nsw i32 %A, 1
436 %C = mul nsw i32 %B, 3
440 define i32 @neg_neg_mul(i32 %A, i32 %B) {
441 ; CHECK-LABEL: @neg_neg_mul(
442 ; CHECK-NEXT: [[E:%.*]] = mul i32 [[A:%.*]], [[B:%.*]]
443 ; CHECK-NEXT: ret i32 [[E]]
451 define i32 @neg_neg_mul_nsw(i32 %A, i32 %B) {
452 ; CHECK-LABEL: @neg_neg_mul_nsw(
453 ; CHECK-NEXT: [[E:%.*]] = mul nsw i32 [[A:%.*]], [[B:%.*]]
454 ; CHECK-NEXT: ret i32 [[E]]
456 %C = sub nsw i32 0, %A
457 %D = sub nsw i32 0, %B
458 %E = mul nsw i32 %C, %D
462 define i124 @neg_neg_mul_apint(i124 %A, i124 %B) {
463 ; CHECK-LABEL: @neg_neg_mul_apint(
464 ; CHECK-NEXT: [[E:%.*]] = mul i124 [[A:%.*]], [[B:%.*]]
465 ; CHECK-NEXT: ret i124 [[E]]
473 define i32 @neg_mul_constant(i32 %A) {
474 ; CHECK-LABEL: @neg_mul_constant(
475 ; CHECK-NEXT: [[E:%.*]] = mul i32 [[A:%.*]], -7
476 ; CHECK-NEXT: ret i32 [[E]]
483 define i55 @neg_mul_constant_apint(i55 %A) {
484 ; CHECK-LABEL: @neg_mul_constant_apint(
485 ; CHECK-NEXT: [[E:%.*]] = mul i55 [[A:%.*]], -7
486 ; CHECK-NEXT: ret i55 [[E]]
493 define <3 x i8> @neg_mul_constant_vec(<3 x i8> %a) {
494 ; CHECK-LABEL: @neg_mul_constant_vec(
495 ; CHECK-NEXT: [[B:%.*]] = mul <3 x i8> [[A:%.*]], splat (i8 -5)
496 ; CHECK-NEXT: ret <3 x i8> [[B]]
498 %A = sub <3 x i8> zeroinitializer, %a
499 %B = mul <3 x i8> %A, <i8 5, i8 5, i8 5>
503 define <3 x i4> @neg_mul_constant_vec_weird(<3 x i4> %a) {
504 ; CHECK-LABEL: @neg_mul_constant_vec_weird(
505 ; CHECK-NEXT: [[B:%.*]] = mul <3 x i4> [[A:%.*]], splat (i4 -5)
506 ; CHECK-NEXT: ret <3 x i4> [[B]]
508 %A = sub <3 x i4> zeroinitializer, %a
509 %B = mul <3 x i4> %A, <i4 5, i4 5, i4 5>
513 define i32 @test26(i32 %A, i32 %B) {
514 ; CHECK-LABEL: @test26(
515 ; CHECK-NEXT: [[D1:%.*]] = shl nsw i32 [[A:%.*]], [[B:%.*]]
516 ; CHECK-NEXT: ret i32 [[D1]]
518 %C = shl nsw i32 1, %B
519 %D = mul nsw i32 %A, %C
523 define i32 @test27(i32 %A, i32 %B) {
524 ; CHECK-LABEL: @test27(
525 ; CHECK-NEXT: [[D1:%.*]] = shl nuw i32 [[A:%.*]], [[B:%.*]]
526 ; CHECK-NEXT: ret i32 [[D1]]
529 %D = mul nuw i32 %A, %C
533 define i32 @test28(i32 %A) {
534 ; CHECK-LABEL: @test28(
535 ; CHECK-NEXT: [[B:%.*]] = shl nuw i32 1, [[A:%.*]]
536 ; CHECK-NEXT: [[C1:%.*]] = shl i32 [[B]], [[A]]
537 ; CHECK-NEXT: ret i32 [[C1]]
540 %C = mul nsw i32 %B, %B
544 define i64 @test29(i31 %A, i31 %B) {
545 ; CHECK-LABEL: @test29(
546 ; CHECK-NEXT: [[C:%.*]] = sext i31 [[A:%.*]] to i64
547 ; CHECK-NEXT: [[D:%.*]] = sext i31 [[B:%.*]] to i64
548 ; CHECK-NEXT: [[E:%.*]] = mul nsw i64 [[C]], [[D]]
549 ; CHECK-NEXT: ret i64 [[E]]
551 %C = sext i31 %A to i64
552 %D = sext i31 %B to i64
557 define i64 @test30(i32 %A, i32 %B) {
558 ; CHECK-LABEL: @test30(
559 ; CHECK-NEXT: [[C:%.*]] = zext i32 [[A:%.*]] to i64
560 ; CHECK-NEXT: [[D:%.*]] = zext i32 [[B:%.*]] to i64
561 ; CHECK-NEXT: [[E:%.*]] = mul nuw i64 [[C]], [[D]]
562 ; CHECK-NEXT: ret i64 [[E]]
564 %C = zext i32 %A to i64
565 %D = zext i32 %B to i64
570 @PR22087 = external global i32
571 define i32 @test31(i32 %V) {
572 ; CHECK-LABEL: @test31(
573 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr inttoptr (i64 4 to ptr), @PR22087
574 ; CHECK-NEXT: [[EXT:%.*]] = zext i1 [[CMP]] to i32
575 ; CHECK-NEXT: [[MUL1:%.*]] = shl i32 [[V:%.*]], [[EXT]]
576 ; CHECK-NEXT: ret i32 [[MUL1]]
578 %cmp = icmp ne ptr inttoptr (i64 4 to ptr), @PR22087
579 %ext = zext i1 %cmp to i32
580 %shl = shl i32 1, %ext
581 %mul = mul i32 %V, %shl
585 define i32 @test32(i32 %X) {
586 ; CHECK-LABEL: @test32(
587 ; CHECK-NEXT: [[MUL:%.*]] = shl i32 [[X:%.*]], 31
588 ; CHECK-NEXT: ret i32 [[MUL]]
590 %mul = mul nsw i32 %X, -2147483648
594 define <2 x i32> @test32vec(<2 x i32> %X) {
595 ; CHECK-LABEL: @test32vec(
596 ; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[X:%.*]], splat (i32 31)
597 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
599 %mul = mul nsw <2 x i32> %X, <i32 -2147483648, i32 -2147483648>
603 define i32 @test33(i32 %X) {
604 ; CHECK-LABEL: @test33(
605 ; CHECK-NEXT: [[MUL:%.*]] = shl nsw i32 [[X:%.*]], 30
606 ; CHECK-NEXT: ret i32 [[MUL]]
608 %mul = mul nsw i32 %X, 1073741824
612 define <2 x i32> @test33vec(<2 x i32> %X) {
613 ; CHECK-LABEL: @test33vec(
614 ; CHECK-NEXT: [[MUL:%.*]] = shl nsw <2 x i32> [[X:%.*]], splat (i32 30)
615 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
617 %mul = mul nsw <2 x i32> %X, <i32 1073741824, i32 1073741824>
621 define i128 @test34(i128 %X) {
622 ; CHECK-LABEL: @test34(
623 ; CHECK-NEXT: [[MUL:%.*]] = shl nsw i128 [[X:%.*]], 1
624 ; CHECK-NEXT: ret i128 [[MUL]]
626 %mul = mul nsw i128 %X, 2
630 define i32 @test_mul_canonicalize_op0(i32 %x, i32 %y) {
631 ; CHECK-LABEL: @test_mul_canonicalize_op0(
632 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[X:%.*]], [[Y:%.*]]
633 ; CHECK-NEXT: [[MUL:%.*]] = sub i32 0, [[TMP1]]
634 ; CHECK-NEXT: ret i32 [[MUL]]
637 %mul = mul i32 %neg, %y
641 define i32 @test_mul_canonicalize_op1(i32 %x, i32 %z) {
642 ; CHECK-LABEL: @test_mul_canonicalize_op1(
643 ; CHECK-NEXT: [[Y_NEG:%.*]] = mul i32 [[Z:%.*]], -3
644 ; CHECK-NEXT: [[DOTNEG:%.*]] = mul i32 [[Y_NEG]], [[X:%.*]]
645 ; CHECK-NEXT: ret i32 [[DOTNEG]]
649 %mul = mul i32 %y, %neg
653 define i32 @test_mul_canonicalize_nsw(i32 %x, i32 %y) {
654 ; CHECK-LABEL: @test_mul_canonicalize_nsw(
655 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[X:%.*]], [[Y:%.*]]
656 ; CHECK-NEXT: [[MUL:%.*]] = sub i32 0, [[TMP1]]
657 ; CHECK-NEXT: ret i32 [[MUL]]
659 %neg = sub nsw i32 0, %x
660 %mul = mul nsw i32 %neg, %y
664 define <2 x i32> @test_mul_canonicalize_vec(<2 x i32> %x, <2 x i32> %y) {
665 ; CHECK-LABEL: @test_mul_canonicalize_vec(
666 ; CHECK-NEXT: [[TMP1:%.*]] = mul <2 x i32> [[X:%.*]], [[Y:%.*]]
667 ; CHECK-NEXT: [[MUL:%.*]] = sub <2 x i32> zeroinitializer, [[TMP1]]
668 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
670 %neg = sub <2 x i32> <i32 0, i32 0>, %x
671 %mul = mul <2 x i32> %neg, %y
675 define i32 @test_mul_canonicalize_multiple_uses(i32 %x, i32 %y) {
676 ; CHECK-LABEL: @test_mul_canonicalize_multiple_uses(
677 ; CHECK-NEXT: [[MUL_NEG:%.*]] = mul i32 [[X:%.*]], [[Y:%.*]]
678 ; CHECK-NEXT: [[MUL2:%.*]] = mul i32 [[MUL_NEG]], [[X]]
679 ; CHECK-NEXT: ret i32 [[MUL2]]
682 %mul = mul i32 %neg, %y
683 %mul2 = mul i32 %mul, %neg
689 define i64 @test_mul_canonicalize_neg_is_not_undone(i64 %L1) {
690 ; Check we do not undo the canonicalization of 0 - (X * Y), if Y is a constant
692 ; CHECK-LABEL: @test_mul_canonicalize_neg_is_not_undone(
693 ; CHECK-NEXT: [[B4:%.*]] = mul i64 [[L1:%.*]], sub (i64 0, i64 ptrtoint (ptr @X to i64))
694 ; CHECK-NEXT: ret i64 [[B4]]
696 %v1 = ptrtoint ptr @X to i64
698 %B4 = mul i64 %B8, %L1
702 define i32 @negate_if_true(i32 %x, i1 %cond) {
703 ; CHECK-LABEL: @negate_if_true(
704 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[X:%.*]]
705 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[X]]
706 ; CHECK-NEXT: ret i32 [[R]]
708 %sel = select i1 %cond, i32 -1, i32 1
709 %r = mul i32 %sel, %x
713 define i32 @negate_if_false(i32 %x, i1 %cond) {
714 ; CHECK-LABEL: @negate_if_false(
715 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[X:%.*]]
716 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[X]], i32 [[TMP1]]
717 ; CHECK-NEXT: ret i32 [[R]]
719 %sel = select i1 %cond, i32 1, i32 -1
720 %r = mul i32 %sel, %x
724 define i32 @negate_if_true_nsw(i32 %x, i1 %cond) {
725 ; CHECK-LABEL: @negate_if_true_nsw(
726 ; CHECK-NEXT: [[TMP1:%.*]] = sub nsw i32 0, [[X:%.*]]
727 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[X]]
728 ; CHECK-NEXT: ret i32 [[R]]
730 %sel = select i1 %cond, i32 -1, i32 1
731 %r = mul nsw i32 %sel, %x
735 define i32 @negate_if_true_nuw(i32 %x, i1 %cond) {
736 ; CHECK-LABEL: @negate_if_true_nuw(
737 ; CHECK-NEXT: [[TMP1:%.*]] = sub nsw i32 0, [[X:%.*]]
738 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[X]]
739 ; CHECK-NEXT: ret i32 [[R]]
741 %sel = select i1 %cond, i32 -1, i32 1
742 %r = mul nuw i32 %sel, %x
746 define i32 @negate_if_false_nsw(i32 %x, i1 %cond) {
747 ; CHECK-LABEL: @negate_if_false_nsw(
748 ; CHECK-NEXT: [[TMP1:%.*]] = sub nsw i32 0, [[X:%.*]]
749 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[X]], i32 [[TMP1]]
750 ; CHECK-NEXT: ret i32 [[R]]
752 %sel = select i1 %cond, i32 1, i32 -1
753 %r = mul nsw i32 %sel, %x
757 define i32 @negate_if_false_nuw(i32 %x, i1 %cond) {
758 ; CHECK-LABEL: @negate_if_false_nuw(
759 ; CHECK-NEXT: [[TMP1:%.*]] = sub nsw i32 0, [[X:%.*]]
760 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[X]], i32 [[TMP1]]
761 ; CHECK-NEXT: ret i32 [[R]]
763 %sel = select i1 %cond, i32 1, i32 -1
764 %r = mul nuw i32 %sel, %x
768 define <2 x i8> @negate_if_true_commute(<2 x i8> %px, i1 %cond) {
769 ; CHECK-LABEL: @negate_if_true_commute(
770 ; CHECK-NEXT: [[X:%.*]] = sdiv <2 x i8> splat (i8 42), [[PX:%.*]]
771 ; CHECK-NEXT: [[TMP1:%.*]] = sub nsw <2 x i8> zeroinitializer, [[X]]
772 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], <2 x i8> [[TMP1]], <2 x i8> [[X]]
773 ; CHECK-NEXT: ret <2 x i8> [[R]]
775 %x = sdiv <2 x i8> <i8 42, i8 42>, %px ; thwart complexity-based canonicalization
776 %sel = select i1 %cond, <2 x i8> <i8 -1, i8 -1>, <2 x i8> <i8 1, i8 1>
777 %r = mul <2 x i8> %x, %sel
781 define <2 x i8> @negate_if_false_commute(<2 x i8> %px, <2 x i1> %cond) {
782 ; CHECK-LABEL: @negate_if_false_commute(
783 ; CHECK-NEXT: [[X:%.*]] = sdiv <2 x i8> <i8 42, i8 5>, [[PX:%.*]]
784 ; CHECK-NEXT: [[TMP1:%.*]] = sub <2 x i8> zeroinitializer, [[X]]
785 ; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[COND:%.*]], <2 x i8> [[X]], <2 x i8> [[TMP1]]
786 ; CHECK-NEXT: ret <2 x i8> [[R]]
788 %x = sdiv <2 x i8> <i8 42, i8 5>, %px ; thwart complexity-based canonicalization
789 %sel = select <2 x i1> %cond, <2 x i8> <i8 1, i8 poison>, <2 x i8> <i8 -1, i8 -1>
790 %r = mul <2 x i8> %x, %sel
796 define i32 @negate_if_true_extra_use(i32 %x, i1 %cond) {
797 ; CHECK-LABEL: @negate_if_true_extra_use(
798 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i32 -1, i32 1
799 ; CHECK-NEXT: call void @use32(i32 [[SEL]])
800 ; CHECK-NEXT: [[R:%.*]] = mul i32 [[SEL]], [[X:%.*]]
801 ; CHECK-NEXT: ret i32 [[R]]
803 %sel = select i1 %cond, i32 -1, i32 1
804 call void @use32(i32 %sel)
805 %r = mul i32 %sel, %x
811 define <2 x i8> @negate_if_true_wrong_constant(<2 x i8> %px, i1 %cond) {
812 ; CHECK-LABEL: @negate_if_true_wrong_constant(
813 ; CHECK-NEXT: [[X:%.*]] = sdiv <2 x i8> splat (i8 42), [[PX:%.*]]
814 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], <2 x i8> <i8 -1, i8 0>, <2 x i8> splat (i8 1)
815 ; CHECK-NEXT: [[R:%.*]] = mul <2 x i8> [[X]], [[SEL]]
816 ; CHECK-NEXT: ret <2 x i8> [[R]]
818 %x = sdiv <2 x i8> <i8 42, i8 42>, %px ; thwart complexity-based canonicalization
819 %sel = select i1 %cond, <2 x i8> <i8 -1, i8 0>, <2 x i8> <i8 1, i8 1>
820 %r = mul <2 x i8> %x, %sel
824 ; (C ? (X /exact Y) : 1) * Y -> C ? X : Y
825 define i32 @mul_div_select(i32 %x, i32 %y, i1 %c) {
826 ; CHECK-LABEL: @mul_div_select(
827 ; CHECK-NEXT: [[MUL:%.*]] = select i1 [[C:%.*]], i32 [[X:%.*]], i32 [[Y:%.*]]
828 ; CHECK-NEXT: ret i32 [[MUL]]
830 %div = udiv exact i32 %x, %y
831 %sel = select i1 %c, i32 %div, i32 1
832 %mul = mul i32 %sel, %y
836 ; fold mul(abs(x),abs(x)) -> mul(x,x)
837 define i31 @combine_mul_abs_i31(i31 %0) {
838 ; CHECK-LABEL: @combine_mul_abs_i31(
839 ; CHECK-NEXT: [[M:%.*]] = mul i31 [[TMP0:%.*]], [[TMP0]]
840 ; CHECK-NEXT: ret i31 [[M]]
842 %c = icmp slt i31 %0, 0
843 %s = sub nsw i31 0, %0
844 %r = select i1 %c, i31 %s, i31 %0
849 define i32 @combine_mul_abs_i32(i32 %0) {
850 ; CHECK-LABEL: @combine_mul_abs_i32(
851 ; CHECK-NEXT: [[M:%.*]] = mul i32 [[TMP0:%.*]], [[TMP0]]
852 ; CHECK-NEXT: ret i32 [[M]]
854 %c = icmp slt i32 %0, 0
855 %s = sub nsw i32 0, %0
856 %r = select i1 %c, i32 %s, i32 %0
861 define <4 x i32> @combine_mul_abs_v4i32(<4 x i32> %0) {
862 ; CHECK-LABEL: @combine_mul_abs_v4i32(
863 ; CHECK-NEXT: [[M:%.*]] = mul <4 x i32> [[TMP0:%.*]], [[TMP0]]
864 ; CHECK-NEXT: ret <4 x i32> [[M]]
866 %c = icmp slt <4 x i32> %0, zeroinitializer
867 %s = sub nsw <4 x i32> zeroinitializer, %0
868 %r = select <4 x i1> %c, <4 x i32> %s, <4 x i32> %0
869 %m = mul <4 x i32> %r, %r
873 ; fold mul(nabs(x),nabs(x)) -> mul(x,x)
874 define i31 @combine_mul_nabs_i31(i31 %0) {
875 ; CHECK-LABEL: @combine_mul_nabs_i31(
876 ; CHECK-NEXT: [[M:%.*]] = mul i31 [[TMP0:%.*]], [[TMP0]]
877 ; CHECK-NEXT: ret i31 [[M]]
879 %c = icmp slt i31 %0, 0
880 %s = sub nsw i31 0, %0
881 %r = select i1 %c, i31 %0, i31 %s
886 define i32 @combine_mul_nabs_i32(i32 %0) {
887 ; CHECK-LABEL: @combine_mul_nabs_i32(
888 ; CHECK-NEXT: [[M:%.*]] = mul i32 [[TMP0:%.*]], [[TMP0]]
889 ; CHECK-NEXT: ret i32 [[M]]
891 %c = icmp slt i32 %0, 0
892 %s = sub nsw i32 0, %0
893 %r = select i1 %c, i32 %0, i32 %s
898 define <4 x i32> @combine_mul_nabs_v4i32(<4 x i32> %0) {
899 ; CHECK-LABEL: @combine_mul_nabs_v4i32(
900 ; CHECK-NEXT: [[M:%.*]] = mul <4 x i32> [[TMP0:%.*]], [[TMP0]]
901 ; CHECK-NEXT: ret <4 x i32> [[M]]
903 %c = icmp slt <4 x i32> %0, zeroinitializer
904 %s = sub nsw <4 x i32> zeroinitializer, %0
905 %r = select <4 x i1> %c, <4 x i32> %0, <4 x i32> %s
906 %m = mul <4 x i32> %r, %r
910 define i32 @combine_mul_abs_intrin(i32 %x) {
911 ; CHECK-LABEL: @combine_mul_abs_intrin(
912 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[X:%.*]], [[X]]
913 ; CHECK-NEXT: ret i32 [[MUL]]
915 %abs = call i32 @llvm.abs.i32(i32 %x, i1 false)
916 %mul = mul i32 %abs, %abs
920 define i32 @combine_mul_nabs_intrin(i32 %x) {
921 ; CHECK-LABEL: @combine_mul_nabs_intrin(
922 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[X:%.*]], [[X]]
923 ; CHECK-NEXT: ret i32 [[MUL]]
925 %abs = call i32 @llvm.abs.i32(i32 %x, i1 false)
926 %neg = sub i32 0, %abs
927 %mul = mul i32 %neg, %neg
931 ; z * splat(0) = splat(0), even for scalable vectors
932 define <vscale x 2 x i64> @mul_scalable_splat_zero(<vscale x 2 x i64> %z) {
933 ; CHECK-LABEL: @mul_scalable_splat_zero(
934 ; CHECK-NEXT: ret <vscale x 2 x i64> zeroinitializer
936 %shuf = shufflevector <vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 0, i32 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
937 %t3 = mul <vscale x 2 x i64> %shuf, %z
938 ret <vscale x 2 x i64> %t3
942 ; fold mul(sub(x,y),negpow2) -> shl(sub(y,x),log2(pow2))
945 define i32 @mulsub1(i32 %a0, i32 %a1) {
946 ; CHECK-LABEL: @mulsub1(
947 ; CHECK-NEXT: [[SUB_NEG:%.*]] = sub i32 [[A0:%.*]], [[A1:%.*]]
948 ; CHECK-NEXT: [[MUL:%.*]] = shl i32 [[SUB_NEG]], 2
949 ; CHECK-NEXT: ret i32 [[MUL]]
951 %sub = sub i32 %a1, %a0
952 %mul = mul i32 %sub, -4
956 define <2 x i32> @mulsub1_vec(<2 x i32> %a0, <2 x i32> %a1) {
957 ; CHECK-LABEL: @mulsub1_vec(
958 ; CHECK-NEXT: [[SUB_NEG:%.*]] = sub <2 x i32> [[A0:%.*]], [[A1:%.*]]
959 ; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[SUB_NEG]], splat (i32 2)
960 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
962 %sub = sub <2 x i32> %a1, %a0
963 %mul = mul <2 x i32> %sub, <i32 -4, i32 -4>
967 define <2 x i32> @mulsub1_vec_nonuniform(<2 x i32> %a0, <2 x i32> %a1) {
968 ; CHECK-LABEL: @mulsub1_vec_nonuniform(
969 ; CHECK-NEXT: [[SUB_NEG:%.*]] = sub <2 x i32> [[A0:%.*]], [[A1:%.*]]
970 ; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[SUB_NEG]], <i32 2, i32 3>
971 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
973 %sub = sub <2 x i32> %a1, %a0
974 %mul = mul <2 x i32> %sub, <i32 -4, i32 -8>
978 define <2 x i32> @mulsub1_vec_nonuniform_poison(<2 x i32> %a0, <2 x i32> %a1) {
979 ; CHECK-LABEL: @mulsub1_vec_nonuniform_poison(
980 ; CHECK-NEXT: [[SUB_NEG:%.*]] = sub <2 x i32> [[A0:%.*]], [[A1:%.*]]
981 ; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[SUB_NEG]], <i32 2, i32 0>
982 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
984 %sub = sub <2 x i32> %a1, %a0
985 %mul = mul <2 x i32> %sub, <i32 -4, i32 poison>
989 define i32 @mulsub2(i32 %a0) {
990 ; CHECK-LABEL: @mulsub2(
991 ; CHECK-NEXT: [[SUB_NEG:%.*]] = shl i32 [[A0:%.*]], 2
992 ; CHECK-NEXT: [[MUL:%.*]] = add i32 [[SUB_NEG]], -64
993 ; CHECK-NEXT: ret i32 [[MUL]]
995 %sub = sub i32 16, %a0
996 %mul = mul i32 %sub, -4
1000 define <2 x i32> @mulsub2_vec(<2 x i32> %a0) {
1001 ; CHECK-LABEL: @mulsub2_vec(
1002 ; CHECK-NEXT: [[SUB_NEG:%.*]] = shl <2 x i32> [[A0:%.*]], splat (i32 2)
1003 ; CHECK-NEXT: [[MUL:%.*]] = add <2 x i32> [[SUB_NEG]], splat (i32 -64)
1004 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
1006 %sub = sub <2 x i32> <i32 16, i32 16>, %a0
1007 %mul = mul <2 x i32> %sub, <i32 -4, i32 -4>
1011 define <2 x i32> @mulsub2_vec_nonuniform(<2 x i32> %a0) {
1012 ; CHECK-LABEL: @mulsub2_vec_nonuniform(
1013 ; CHECK-NEXT: [[SUB_NEG:%.*]] = add <2 x i32> [[A0:%.*]], <i32 -16, i32 -32>
1014 ; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[SUB_NEG]], <i32 2, i32 3>
1015 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
1017 %sub = sub <2 x i32> <i32 16, i32 32>, %a0
1018 %mul = mul <2 x i32> %sub, <i32 -4, i32 -8>
1022 define <2 x i32> @mulsub2_vec_nonuniform_poison(<2 x i32> %a0) {
1023 ; CHECK-LABEL: @mulsub2_vec_nonuniform_poison(
1024 ; CHECK-NEXT: [[SUB_NEG:%.*]] = add <2 x i32> [[A0:%.*]], <i32 -16, i32 -32>
1025 ; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[SUB_NEG]], <i32 2, i32 0>
1026 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
1028 %sub = sub <2 x i32> <i32 16, i32 32>, %a0
1029 %mul = mul <2 x i32> %sub, <i32 -4, i32 poison>
1033 define i32 @muladd2(i32 %a0) {
1034 ; CHECK-LABEL: @muladd2(
1035 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[A0:%.*]], 2
1036 ; CHECK-NEXT: [[MUL:%.*]] = sub i32 -64, [[TMP1]]
1037 ; CHECK-NEXT: ret i32 [[MUL]]
1039 %add = add i32 %a0, 16
1040 %mul = mul i32 %add, -4
1044 define <2 x i32> @muladd2_vec(<2 x i32> %a0) {
1045 ; CHECK-LABEL: @muladd2_vec(
1046 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> [[A0:%.*]], splat (i32 2)
1047 ; CHECK-NEXT: [[MUL:%.*]] = sub <2 x i32> splat (i32 -64), [[TMP1]]
1048 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
1050 %add = add <2 x i32> %a0, <i32 16, i32 16>
1051 %mul = mul <2 x i32> %add, <i32 -4, i32 -4>
1055 define <2 x i32> @muladd2_vec_nonuniform(<2 x i32> %a0) {
1056 ; CHECK-LABEL: @muladd2_vec_nonuniform(
1057 ; CHECK-NEXT: [[ADD_NEG:%.*]] = sub <2 x i32> <i32 -16, i32 -32>, [[A0:%.*]]
1058 ; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[ADD_NEG]], <i32 2, i32 3>
1059 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
1061 %add = add <2 x i32> %a0, <i32 16, i32 32>
1062 %mul = mul <2 x i32> %add, <i32 -4, i32 -8>
1066 define <2 x i32> @muladd2_vec_nonuniform_poison(<2 x i32> %a0) {
1067 ; CHECK-LABEL: @muladd2_vec_nonuniform_poison(
1068 ; CHECK-NEXT: [[ADD_NEG:%.*]] = sub <2 x i32> <i32 -16, i32 -32>, [[A0:%.*]]
1069 ; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[ADD_NEG]], <i32 2, i32 0>
1070 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
1072 %add = add <2 x i32> %a0, <i32 16, i32 32>
1073 %mul = mul <2 x i32> %add, <i32 -4, i32 poison>
1077 define i32 @mulmuladd2(i32 %a0, i32 %a1) {
1078 ; CHECK-LABEL: @mulmuladd2(
1079 ; CHECK-NEXT: [[ADD_NEG:%.*]] = sub i32 1073741808, [[A0:%.*]]
1080 ; CHECK-NEXT: [[MUL1_NEG:%.*]] = mul i32 [[ADD_NEG]], [[A1:%.*]]
1081 ; CHECK-NEXT: [[MUL2:%.*]] = shl i32 [[MUL1_NEG]], 2
1082 ; CHECK-NEXT: ret i32 [[MUL2]]
1084 %add = add i32 %a0, 16
1085 %mul1 = mul i32 %add, %a1
1086 %mul2 = mul i32 %mul1, -4
1089 define i32 @mulmuladd2_extrause0(i32 %a0, i32 %a1) {
1090 ; CHECK-LABEL: @mulmuladd2_extrause0(
1091 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[A0:%.*]], 16
1092 ; CHECK-NEXT: [[MUL1:%.*]] = mul i32 [[ADD]], [[A1:%.*]]
1093 ; CHECK-NEXT: call void @use32(i32 [[MUL1]])
1094 ; CHECK-NEXT: [[MUL2:%.*]] = mul i32 [[MUL1]], -4
1095 ; CHECK-NEXT: ret i32 [[MUL2]]
1097 %add = add i32 %a0, 16
1098 %mul1 = mul i32 %add, %a1
1099 call void @use32(i32 %mul1)
1100 %mul2 = mul i32 %mul1, -4
1103 define i32 @mulmuladd2_extrause1(i32 %a0, i32 %a1) {
1104 ; CHECK-LABEL: @mulmuladd2_extrause1(
1105 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[A0:%.*]], 16
1106 ; CHECK-NEXT: call void @use32(i32 [[ADD]])
1107 ; CHECK-NEXT: [[MUL1:%.*]] = mul i32 [[ADD]], [[A1:%.*]]
1108 ; CHECK-NEXT: [[MUL2:%.*]] = mul i32 [[MUL1]], -4
1109 ; CHECK-NEXT: ret i32 [[MUL2]]
1111 %add = add i32 %a0, 16
1112 call void @use32(i32 %add)
1113 %mul1 = mul i32 %add, %a1
1114 %mul2 = mul i32 %mul1, -4
1117 define i32 @mulmuladd2_extrause2(i32 %a0, i32 %a1) {
1118 ; CHECK-LABEL: @mulmuladd2_extrause2(
1119 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[A0:%.*]], 16
1120 ; CHECK-NEXT: call void @use32(i32 [[ADD]])
1121 ; CHECK-NEXT: [[MUL1:%.*]] = mul i32 [[ADD]], [[A1:%.*]]
1122 ; CHECK-NEXT: call void @use32(i32 [[MUL1]])
1123 ; CHECK-NEXT: [[MUL2:%.*]] = mul i32 [[MUL1]], -4
1124 ; CHECK-NEXT: ret i32 [[MUL2]]
1126 %add = add i32 %a0, 16
1127 call void @use32(i32 %add)
1128 %mul1 = mul i32 %add, %a1
1129 call void @use32(i32 %mul1)
1130 %mul2 = mul i32 %mul1, -4
1134 define i32 @mulnot(i32 %a0) {
1135 ; CHECK-LABEL: @mulnot(
1136 ; CHECK-NEXT: [[ADD_NEG:%.*]] = shl i32 [[A0:%.*]], 2
1137 ; CHECK-NEXT: [[MUL:%.*]] = add i32 [[ADD_NEG]], 4
1138 ; CHECK-NEXT: ret i32 [[MUL]]
1140 %add = xor i32 %a0, -1
1141 %mul = mul i32 %add, -4
1144 define i32 @mulnot_extrause(i32 %a0) {
1145 ; CHECK-LABEL: @mulnot_extrause(
1146 ; CHECK-NEXT: [[NOT:%.*]] = xor i32 [[A0:%.*]], -1
1147 ; CHECK-NEXT: call void @use32(i32 [[NOT]])
1148 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[NOT]], -4
1149 ; CHECK-NEXT: ret i32 [[MUL]]
1151 %not = xor i32 %a0, -1
1152 call void @use32(i32 %not)
1153 %mul = mul i32 %not, -4