1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -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:%.*]], <i32 3, 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: [[TMP1:%.*]] = ashr i32 [[A:%.*]], 31
49 ; CHECK-NEXT: [[E:%.*]] = and i32 [[TMP1]], [[B:%.*]]
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: [[TMP1:%.*]] = ashr i32 [[A:%.*]], 31
61 ; CHECK-NEXT: [[E:%.*]] = and i32 [[TMP1]], [[B:%.*]]
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: [[TMP1:%.*]] = ashr i32 [[A]], 31
76 ; CHECK-NEXT: [[E:%.*]] = and i32 [[TMP1]], [[B:%.*]]
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: [[M:%.*]] = shl i32 [[A:%.*]], [[B:%.*]]
91 ; CHECK-NEXT: ret i32 [[M]]
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 i32 @mul_bools_sext_one_use_per_op(i1 %x, i1 %y) {
251 ; CHECK-LABEL: @mul_bools_sext_one_use_per_op(
252 ; CHECK-NEXT: [[MULBOOL:%.*]] = and i1 [[X:%.*]], [[Y:%.*]]
253 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[MULBOOL]] to i32
254 ; CHECK-NEXT: ret i32 [[R]]
256 %sx = sext i1 %x to i32
257 %sy = sext i1 %y to i32
258 %r = mul i32 %sx, %sy
262 define i32 @mul_bool_sext_one_user(i1 %x) {
263 ; CHECK-LABEL: @mul_bool_sext_one_user(
264 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[X:%.*]] to i32
265 ; CHECK-NEXT: ret i32 [[R]]
267 %sx = sext i1 %x to i32
268 %r = mul i32 %sx, %sx
272 define i32 @mul_bools_zext_one_use_per_op(i1 %x, i1 %y) {
273 ; CHECK-LABEL: @mul_bools_zext_one_use_per_op(
274 ; CHECK-NEXT: [[MULBOOL:%.*]] = and i1 [[X:%.*]], [[Y:%.*]]
275 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[MULBOOL]] to i32
276 ; CHECK-NEXT: ret i32 [[R]]
278 %zx = zext i1 %x to i32
279 %zy = zext i1 %y to i32
280 %r = mul i32 %zx, %zy
284 define i32 @mul_bool_zext_one_user(i1 %x) {
285 ; CHECK-LABEL: @mul_bool_zext_one_user(
286 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[X:%.*]] to i32
287 ; CHECK-NEXT: ret i32 [[R]]
289 %sx = zext i1 %x to i32
290 %r = mul i32 %sx, %sx
294 define i32 @mul_bool_sext_one_extra_user(i1 %x) {
295 ; CHECK-LABEL: @mul_bool_sext_one_extra_user(
296 ; CHECK-NEXT: [[SX:%.*]] = sext i1 [[X:%.*]] to i32
297 ; CHECK-NEXT: call void @use32(i32 [[SX]])
298 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[X]] to i32
299 ; CHECK-NEXT: ret i32 [[R]]
301 %sx = sext i1 %x to i32
302 call void @use32(i32 %sx)
303 %r = mul i32 %sx, %sx
307 define i32 @mul_bool_zext_one_extra_user(i1 %x) {
308 ; CHECK-LABEL: @mul_bool_zext_one_extra_user(
309 ; CHECK-NEXT: [[SX:%.*]] = zext i1 [[X:%.*]] to i32
310 ; CHECK-NEXT: call void @use32(i32 [[SX]])
311 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[X]] to i32
312 ; CHECK-NEXT: ret i32 [[R]]
314 %sx = zext i1 %x to i32
315 call void @use32(i32 %sx)
316 %r = mul i32 %sx, %sx
320 define <3 x i32> @mul_bools_mixed_ext(<3 x i1> %x, <3 x i1> %y) {
321 ; CHECK-LABEL: @mul_bools_mixed_ext(
322 ; CHECK-NEXT: [[MULBOOL:%.*]] = and <3 x i1> [[X:%.*]], [[Y:%.*]]
323 ; CHECK-NEXT: [[R:%.*]] = sext <3 x i1> [[MULBOOL]] to <3 x i32>
324 ; CHECK-NEXT: ret <3 x i32> [[R]]
326 %zx = zext <3 x i1> %x to <3 x i32>
327 %sy = sext <3 x i1> %y to <3 x i32>
328 %r = mul <3 x i32> %zx, %sy
332 define i32 @mul_bools_mixed_ext_use1(i1 %x, i1 %y) {
333 ; CHECK-LABEL: @mul_bools_mixed_ext_use1(
334 ; CHECK-NEXT: [[ZY:%.*]] = zext i1 [[Y:%.*]] to i32
335 ; CHECK-NEXT: call void @use32(i32 [[ZY]])
336 ; CHECK-NEXT: [[MULBOOL:%.*]] = and i1 [[X:%.*]], [[Y]]
337 ; CHECK-NEXT: [[R:%.*]] = sext i1 [[MULBOOL]] to i32
338 ; CHECK-NEXT: ret i32 [[R]]
340 %sx = sext i1 %x to i32
341 %zy = zext i1 %y to i32
342 call void @use32(i32 %zy)
343 %r = mul i32 %sx, %zy
347 define i32 @mul_bools_mixed_ext_use2(i1 %x, i1 %y) {
348 ; CHECK-LABEL: @mul_bools_mixed_ext_use2(
349 ; CHECK-NEXT: [[SY:%.*]] = sext i1 [[Y:%.*]] to i32
350 ; CHECK-NEXT: call void @use32(i32 [[SY]])
351 ; CHECK-NEXT: [[MULBOOL:%.*]] = and i1 [[Y]], [[X:%.*]]
352 ; CHECK-NEXT: [[R:%.*]] = sext i1 [[MULBOOL]] to i32
353 ; CHECK-NEXT: ret i32 [[R]]
355 %zx = zext i1 %x to i32
356 %sy = sext i1 %y to i32
357 call void @use32(i32 %sy)
358 %r = mul i32 %sy, %zx
362 define i32 @mul_bools_mixed_ext_use3(i1 %x, i1 %y) {
363 ; CHECK-LABEL: @mul_bools_mixed_ext_use3(
364 ; CHECK-NEXT: [[SX:%.*]] = sext i1 [[X:%.*]] to i32
365 ; CHECK-NEXT: call void @use32(i32 [[SX]])
366 ; CHECK-NEXT: [[ZY:%.*]] = zext i1 [[Y:%.*]] to i32
367 ; CHECK-NEXT: call void @use32(i32 [[ZY]])
368 ; CHECK-NEXT: [[R:%.*]] = select i1 [[Y]], i32 [[SX]], i32 0
369 ; CHECK-NEXT: ret i32 [[R]]
371 %sx = sext i1 %x to i32
372 call void @use32(i32 %sx)
373 %zy = zext i1 %y to i32
374 call void @use32(i32 %zy)
375 %r = mul i32 %zy, %sx
379 ; (A >>u 31) * B --> (A >>s 31) & B
381 define i32 @signbit_mul(i32 %a, i32 %b) {
382 ; CHECK-LABEL: @signbit_mul(
383 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[A:%.*]], 31
384 ; CHECK-NEXT: [[E:%.*]] = and i32 [[TMP1]], [[B:%.*]]
385 ; CHECK-NEXT: ret i32 [[E]]
392 define i32 @signbit_mul_commute_extra_use(i32 %a, i32 %b) {
393 ; CHECK-LABEL: @signbit_mul_commute_extra_use(
394 ; CHECK-NEXT: [[D:%.*]] = lshr i32 [[A:%.*]], 31
395 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[A]], 31
396 ; CHECK-NEXT: [[E:%.*]] = and i32 [[TMP1]], [[B:%.*]]
397 ; CHECK-NEXT: call void @use32(i32 [[D]])
398 ; CHECK-NEXT: ret i32 [[E]]
402 call void @use32(i32 %d)
406 ; (A >>u 31)) * B --> (A >>s 31) & B
408 define <2 x i32> @signbit_mul_vec(<2 x i32> %a, <2 x i32> %b) {
409 ; CHECK-LABEL: @signbit_mul_vec(
410 ; CHECK-NEXT: [[TMP1:%.*]] = ashr <2 x i32> [[A:%.*]], <i32 31, i32 31>
411 ; CHECK-NEXT: [[E:%.*]] = and <2 x i32> [[TMP1]], [[B:%.*]]
412 ; CHECK-NEXT: ret <2 x i32> [[E]]
414 %d = lshr <2 x i32> %a, <i32 31, i32 31>
415 %e = mul <2 x i32> %d, %b
419 define <2 x i32> @signbit_mul_vec_commute(<2 x i32> %a, <2 x i32> %b) {
420 ; CHECK-LABEL: @signbit_mul_vec_commute(
421 ; CHECK-NEXT: [[TMP1:%.*]] = ashr <2 x i32> [[A:%.*]], <i32 31, i32 31>
422 ; CHECK-NEXT: [[E:%.*]] = and <2 x i32> [[TMP1]], [[B:%.*]]
423 ; CHECK-NEXT: ret <2 x i32> [[E]]
425 %d = lshr <2 x i32> %a, <i32 31, i32 31>
426 %e = mul <2 x i32> %b, %d
430 define i32 @test18(i32 %A, i32 %B) {
431 ; CHECK-LABEL: @test18(
432 ; CHECK-NEXT: ret i32 0
441 declare {i32, i1} @llvm.smul.with.overflow.i32(i32, i32)
442 declare void @use(i1)
444 define i32 @test19(i32 %A, i32 %B) {
445 ; CHECK-LABEL: @test19(
446 ; CHECK-NEXT: call void @use(i1 false)
447 ; CHECK-NEXT: ret i32 0
452 ; It would be nice if we also started proving that this doesn't overflow.
453 %E = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %C, i32 %D)
454 %F = extractvalue {i32, i1} %E, 0
455 %G = extractvalue {i32, i1} %E, 1
456 call void @use(i1 %G)
461 define <2 x i64> @test20(<2 x i64> %A) {
462 ; CHECK-LABEL: @test20(
463 ; CHECK-NEXT: [[TMP1:%.*]] = mul <2 x i64> [[A:%.*]], <i64 3, i64 2>
464 ; CHECK-NEXT: [[C:%.*]] = add <2 x i64> [[TMP1]], <i64 36, i64 28>
465 ; CHECK-NEXT: ret <2 x i64> [[C]]
467 %B = add <2 x i64> %A, <i64 12, i64 14>
468 %C = mul <2 x i64> %B, <i64 3, i64 2>
472 define <2 x i1> @test21(<2 x i1> %A, <2 x i1> %B) {
473 ; CHECK-LABEL: @test21(
474 ; CHECK-NEXT: [[C:%.*]] = and <2 x i1> [[A:%.*]], [[B:%.*]]
475 ; CHECK-NEXT: ret <2 x i1> [[C]]
477 %C = mul <2 x i1> %A, %B
481 define i32 @test22(i32 %A) {
482 ; CHECK-LABEL: @test22(
483 ; CHECK-NEXT: [[B:%.*]] = sub nsw i32 0, [[A:%.*]]
484 ; CHECK-NEXT: ret i32 [[B]]
486 %B = mul nsw i32 %A, -1
490 define i32 @test23(i32 %A) {
491 ; CHECK-LABEL: @test23(
492 ; CHECK-NEXT: [[C:%.*]] = mul nuw i32 [[A:%.*]], 6
493 ; CHECK-NEXT: ret i32 [[C]]
495 %B = shl nuw i32 %A, 1
496 %C = mul nuw i32 %B, 3
500 define i32 @test24(i32 %A) {
501 ; CHECK-LABEL: @test24(
502 ; CHECK-NEXT: [[C:%.*]] = mul nsw i32 [[A:%.*]], 6
503 ; CHECK-NEXT: ret i32 [[C]]
505 %B = shl nsw i32 %A, 1
506 %C = mul nsw i32 %B, 3
510 define i32 @neg_neg_mul(i32 %A, i32 %B) {
511 ; CHECK-LABEL: @neg_neg_mul(
512 ; CHECK-NEXT: [[E:%.*]] = mul i32 [[A:%.*]], [[B:%.*]]
513 ; CHECK-NEXT: ret i32 [[E]]
521 define i32 @neg_neg_mul_nsw(i32 %A, i32 %B) {
522 ; CHECK-LABEL: @neg_neg_mul_nsw(
523 ; CHECK-NEXT: [[E:%.*]] = mul nsw i32 [[A:%.*]], [[B:%.*]]
524 ; CHECK-NEXT: ret i32 [[E]]
526 %C = sub nsw i32 0, %A
527 %D = sub nsw i32 0, %B
528 %E = mul nsw i32 %C, %D
532 define i124 @neg_neg_mul_apint(i124 %A, i124 %B) {
533 ; CHECK-LABEL: @neg_neg_mul_apint(
534 ; CHECK-NEXT: [[E:%.*]] = mul i124 [[A:%.*]], [[B:%.*]]
535 ; CHECK-NEXT: ret i124 [[E]]
543 define i32 @neg_mul_constant(i32 %A) {
544 ; CHECK-LABEL: @neg_mul_constant(
545 ; CHECK-NEXT: [[E:%.*]] = mul i32 [[A:%.*]], -7
546 ; CHECK-NEXT: ret i32 [[E]]
553 define i55 @neg_mul_constant_apint(i55 %A) {
554 ; CHECK-LABEL: @neg_mul_constant_apint(
555 ; CHECK-NEXT: [[E:%.*]] = mul i55 [[A:%.*]], -7
556 ; CHECK-NEXT: ret i55 [[E]]
563 define <3 x i8> @neg_mul_constant_vec(<3 x i8> %a) {
564 ; CHECK-LABEL: @neg_mul_constant_vec(
565 ; CHECK-NEXT: [[B:%.*]] = mul <3 x i8> [[A:%.*]], <i8 -5, i8 -5, i8 -5>
566 ; CHECK-NEXT: ret <3 x i8> [[B]]
568 %A = sub <3 x i8> zeroinitializer, %a
569 %B = mul <3 x i8> %A, <i8 5, i8 5, i8 5>
573 define <3 x i4> @neg_mul_constant_vec_weird(<3 x i4> %a) {
574 ; CHECK-LABEL: @neg_mul_constant_vec_weird(
575 ; CHECK-NEXT: [[B:%.*]] = mul <3 x i4> [[A:%.*]], <i4 -5, i4 -5, i4 -5>
576 ; CHECK-NEXT: ret <3 x i4> [[B]]
578 %A = sub <3 x i4> zeroinitializer, %a
579 %B = mul <3 x i4> %A, <i4 5, i4 5, i4 5>
583 define i32 @test26(i32 %A, i32 %B) {
584 ; CHECK-LABEL: @test26(
585 ; CHECK-NEXT: [[D:%.*]] = shl nsw i32 [[A:%.*]], [[B:%.*]]
586 ; CHECK-NEXT: ret i32 [[D]]
588 %C = shl nsw i32 1, %B
589 %D = mul nsw i32 %A, %C
593 define i32 @test27(i32 %A, i32 %B) {
594 ; CHECK-LABEL: @test27(
595 ; CHECK-NEXT: [[D:%.*]] = shl nuw i32 [[A:%.*]], [[B:%.*]]
596 ; CHECK-NEXT: ret i32 [[D]]
599 %D = mul nuw i32 %A, %C
603 define i32 @test28(i32 %A) {
604 ; CHECK-LABEL: @test28(
605 ; CHECK-NEXT: [[B:%.*]] = shl i32 1, [[A:%.*]]
606 ; CHECK-NEXT: [[C:%.*]] = shl i32 [[B]], [[A]]
607 ; CHECK-NEXT: ret i32 [[C]]
610 %C = mul nsw i32 %B, %B
614 define i64 @test29(i31 %A, i31 %B) {
615 ; CHECK-LABEL: @test29(
616 ; CHECK-NEXT: [[C:%.*]] = sext i31 [[A:%.*]] to i64
617 ; CHECK-NEXT: [[D:%.*]] = sext i31 [[B:%.*]] to i64
618 ; CHECK-NEXT: [[E:%.*]] = mul nsw i64 [[C]], [[D]]
619 ; CHECK-NEXT: ret i64 [[E]]
621 %C = sext i31 %A to i64
622 %D = sext i31 %B to i64
627 define i64 @test30(i32 %A, i32 %B) {
628 ; CHECK-LABEL: @test30(
629 ; CHECK-NEXT: [[C:%.*]] = zext i32 [[A:%.*]] to i64
630 ; CHECK-NEXT: [[D:%.*]] = zext i32 [[B:%.*]] to i64
631 ; CHECK-NEXT: [[E:%.*]] = mul nuw i64 [[C]], [[D]]
632 ; CHECK-NEXT: ret i64 [[E]]
634 %C = zext i32 %A to i64
635 %D = zext i32 %B to i64
640 @PR22087 = external global i32
641 define i32 @test31(i32 %V) {
642 ; CHECK-LABEL: @test31(
643 ; CHECK-NEXT: [[MUL:%.*]] = shl i32 [[V:%.*]], zext (i1 icmp ne (i32* inttoptr (i64 1 to i32*), i32* @PR22087) to i32)
644 ; CHECK-NEXT: ret i32 [[MUL]]
646 %mul = mul i32 %V, shl (i32 1, i32 zext (i1 icmp ne (i32* inttoptr (i64 1 to i32*), i32* @PR22087) to i32))
650 define i32 @test32(i32 %X) {
651 ; CHECK-LABEL: @test32(
652 ; CHECK-NEXT: [[MUL:%.*]] = shl i32 [[X:%.*]], 31
653 ; CHECK-NEXT: ret i32 [[MUL]]
655 %mul = mul nsw i32 %X, -2147483648
659 define <2 x i32> @test32vec(<2 x i32> %X) {
660 ; CHECK-LABEL: @test32vec(
661 ; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[X:%.*]], <i32 31, i32 31>
662 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
664 %mul = mul nsw <2 x i32> %X, <i32 -2147483648, i32 -2147483648>
668 define i32 @test33(i32 %X) {
669 ; CHECK-LABEL: @test33(
670 ; CHECK-NEXT: [[MUL:%.*]] = shl nsw i32 [[X:%.*]], 30
671 ; CHECK-NEXT: ret i32 [[MUL]]
673 %mul = mul nsw i32 %X, 1073741824
677 define <2 x i32> @test33vec(<2 x i32> %X) {
678 ; CHECK-LABEL: @test33vec(
679 ; CHECK-NEXT: [[MUL:%.*]] = shl nsw <2 x i32> [[X:%.*]], <i32 30, i32 30>
680 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
682 %mul = mul nsw <2 x i32> %X, <i32 1073741824, i32 1073741824>
686 define i128 @test34(i128 %X) {
687 ; CHECK-LABEL: @test34(
688 ; CHECK-NEXT: [[MUL:%.*]] = shl nsw i128 [[X:%.*]], 1
689 ; CHECK-NEXT: ret i128 [[MUL]]
691 %mul = mul nsw i128 %X, 2
695 define i32 @test_mul_canonicalize_op0(i32 %x, i32 %y) {
696 ; CHECK-LABEL: @test_mul_canonicalize_op0(
697 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[X:%.*]], [[Y:%.*]]
698 ; CHECK-NEXT: [[MUL:%.*]] = sub i32 0, [[TMP1]]
699 ; CHECK-NEXT: ret i32 [[MUL]]
702 %mul = mul i32 %neg, %y
706 define i32 @test_mul_canonicalize_op1(i32 %x, i32 %z) {
707 ; CHECK-LABEL: @test_mul_canonicalize_op1(
708 ; CHECK-NEXT: [[Y_NEG:%.*]] = mul i32 [[Z:%.*]], -3
709 ; CHECK-NEXT: [[DOTNEG:%.*]] = mul i32 [[Y_NEG]], [[X:%.*]]
710 ; CHECK-NEXT: ret i32 [[DOTNEG]]
714 %mul = mul i32 %y, %neg
718 define i32 @test_mul_canonicalize_nsw(i32 %x, i32 %y) {
719 ; CHECK-LABEL: @test_mul_canonicalize_nsw(
720 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[X:%.*]], [[Y:%.*]]
721 ; CHECK-NEXT: [[MUL:%.*]] = sub i32 0, [[TMP1]]
722 ; CHECK-NEXT: ret i32 [[MUL]]
724 %neg = sub nsw i32 0, %x
725 %mul = mul nsw i32 %neg, %y
729 define <2 x i32> @test_mul_canonicalize_vec(<2 x i32> %x, <2 x i32> %y) {
730 ; CHECK-LABEL: @test_mul_canonicalize_vec(
731 ; CHECK-NEXT: [[TMP1:%.*]] = mul <2 x i32> [[X:%.*]], [[Y:%.*]]
732 ; CHECK-NEXT: [[MUL:%.*]] = sub <2 x i32> zeroinitializer, [[TMP1]]
733 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
735 %neg = sub <2 x i32> <i32 0, i32 0>, %x
736 %mul = mul <2 x i32> %neg, %y
740 define i32 @test_mul_canonicalize_multiple_uses(i32 %x, i32 %y) {
741 ; CHECK-LABEL: @test_mul_canonicalize_multiple_uses(
742 ; CHECK-NEXT: [[NEG:%.*]] = sub i32 0, [[X:%.*]]
743 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[NEG]], [[Y:%.*]]
744 ; CHECK-NEXT: [[MUL2:%.*]] = mul i32 [[MUL]], [[NEG]]
745 ; CHECK-NEXT: ret i32 [[MUL2]]
748 %mul = mul i32 %neg, %y
749 %mul2 = mul i32 %mul, %neg
755 define i64 @test_mul_canonicalize_neg_is_not_undone(i64 %L1) {
756 ; Check we do not undo the canonicalization of 0 - (X * Y), if Y is a constant
758 ; CHECK-LABEL: @test_mul_canonicalize_neg_is_not_undone(
759 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[L1:%.*]], ptrtoint (i32* @X to i64)
760 ; CHECK-NEXT: [[B4:%.*]] = sub i64 0, [[TMP1]]
761 ; CHECK-NEXT: ret i64 [[B4]]
763 %v1 = ptrtoint i32* @X to i64
765 %B4 = mul i64 %B8, %L1
769 define i32 @negate_if_true(i32 %x, i1 %cond) {
770 ; CHECK-LABEL: @negate_if_true(
771 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[X:%.*]]
772 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[X]]
773 ; CHECK-NEXT: ret i32 [[TMP2]]
775 %sel = select i1 %cond, i32 -1, i32 1
776 %r = mul i32 %sel, %x
780 define i32 @negate_if_false(i32 %x, i1 %cond) {
781 ; CHECK-LABEL: @negate_if_false(
782 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[X:%.*]]
783 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[COND:%.*]], i32 [[X]], i32 [[TMP1]]
784 ; CHECK-NEXT: ret i32 [[TMP2]]
786 %sel = select i1 %cond, i32 1, i32 -1
787 %r = mul i32 %sel, %x
791 define <2 x i8> @negate_if_true_commute(<2 x i8> %px, i1 %cond) {
792 ; CHECK-LABEL: @negate_if_true_commute(
793 ; CHECK-NEXT: [[X:%.*]] = sdiv <2 x i8> <i8 42, i8 42>, [[PX:%.*]]
794 ; CHECK-NEXT: [[TMP1:%.*]] = sub nsw <2 x i8> zeroinitializer, [[X]]
795 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[COND:%.*]], <2 x i8> [[TMP1]], <2 x i8> [[X]]
796 ; CHECK-NEXT: ret <2 x i8> [[TMP2]]
798 %x = sdiv <2 x i8> <i8 42, i8 42>, %px ; thwart complexity-based canonicalization
799 %sel = select i1 %cond, <2 x i8> <i8 -1, i8 -1>, <2 x i8> <i8 1, i8 1>
800 %r = mul <2 x i8> %x, %sel
804 define <2 x i8> @negate_if_false_commute(<2 x i8> %px, <2 x i1> %cond) {
805 ; CHECK-LABEL: @negate_if_false_commute(
806 ; CHECK-NEXT: [[X:%.*]] = sdiv <2 x i8> <i8 42, i8 5>, [[PX:%.*]]
807 ; CHECK-NEXT: [[TMP1:%.*]] = sub <2 x i8> zeroinitializer, [[X]]
808 ; CHECK-NEXT: [[TMP2:%.*]] = select <2 x i1> [[COND:%.*]], <2 x i8> [[X]], <2 x i8> [[TMP1]]
809 ; CHECK-NEXT: ret <2 x i8> [[TMP2]]
811 %x = sdiv <2 x i8> <i8 42, i8 5>, %px ; thwart complexity-based canonicalization
812 %sel = select <2 x i1> %cond, <2 x i8> <i8 1, i8 undef>, <2 x i8> <i8 -1, i8 -1>
813 %r = mul <2 x i8> %x, %sel
819 define i32 @negate_if_true_extra_use(i32 %x, i1 %cond) {
820 ; CHECK-LABEL: @negate_if_true_extra_use(
821 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i32 -1, i32 1
822 ; CHECK-NEXT: call void @use32(i32 [[SEL]])
823 ; CHECK-NEXT: [[R:%.*]] = mul i32 [[SEL]], [[X:%.*]]
824 ; CHECK-NEXT: ret i32 [[R]]
826 %sel = select i1 %cond, i32 -1, i32 1
827 call void @use32(i32 %sel)
828 %r = mul i32 %sel, %x
834 define <2 x i8> @negate_if_true_wrong_constant(<2 x i8> %px, i1 %cond) {
835 ; CHECK-LABEL: @negate_if_true_wrong_constant(
836 ; CHECK-NEXT: [[X:%.*]] = sdiv <2 x i8> <i8 42, i8 42>, [[PX:%.*]]
837 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], <2 x i8> <i8 -1, i8 0>, <2 x i8> <i8 1, i8 1>
838 ; CHECK-NEXT: [[R:%.*]] = mul <2 x i8> [[X]], [[SEL]]
839 ; CHECK-NEXT: ret <2 x i8> [[R]]
841 %x = sdiv <2 x i8> <i8 42, i8 42>, %px ; thwart complexity-based canonicalization
842 %sel = select i1 %cond, <2 x i8> <i8 -1, i8 0>, <2 x i8> <i8 1, i8 1>
843 %r = mul <2 x i8> %x, %sel
847 ; (C ? (X /exact Y) : 1) * Y -> C ? X : Y
848 define i32 @mul_div_select(i32 %x, i32 %y, i1 %c) {
849 ; CHECK-LABEL: @mul_div_select(
850 ; CHECK-NEXT: [[MUL:%.*]] = select i1 [[C:%.*]], i32 [[X:%.*]], i32 [[Y:%.*]]
851 ; CHECK-NEXT: ret i32 [[MUL]]
853 %div = udiv exact i32 %x, %y
854 %sel = select i1 %c, i32 %div, i32 1
855 %mul = mul i32 %sel, %y
859 ; fold mul(abs(x),abs(x)) -> mul(x,x)
860 define i31 @combine_mul_abs_i31(i31 %0) {
861 ; CHECK-LABEL: @combine_mul_abs_i31(
862 ; CHECK-NEXT: [[M:%.*]] = mul i31 [[TMP0:%.*]], [[TMP0]]
863 ; CHECK-NEXT: ret i31 [[M]]
865 %c = icmp slt i31 %0, 0
866 %s = sub nsw i31 0, %0
867 %r = select i1 %c, i31 %s, i31 %0
872 define i32 @combine_mul_abs_i32(i32 %0) {
873 ; CHECK-LABEL: @combine_mul_abs_i32(
874 ; CHECK-NEXT: [[M:%.*]] = mul i32 [[TMP0:%.*]], [[TMP0]]
875 ; CHECK-NEXT: ret i32 [[M]]
877 %c = icmp slt i32 %0, 0
878 %s = sub nsw i32 0, %0
879 %r = select i1 %c, i32 %s, i32 %0
884 define <4 x i32> @combine_mul_abs_v4i32(<4 x i32> %0) {
885 ; CHECK-LABEL: @combine_mul_abs_v4i32(
886 ; CHECK-NEXT: [[M:%.*]] = mul <4 x i32> [[TMP0:%.*]], [[TMP0]]
887 ; CHECK-NEXT: ret <4 x i32> [[M]]
889 %c = icmp slt <4 x i32> %0, zeroinitializer
890 %s = sub nsw <4 x i32> zeroinitializer, %0
891 %r = select <4 x i1> %c, <4 x i32> %s, <4 x i32> %0
892 %m = mul <4 x i32> %r, %r
896 ; fold mul(nabs(x),nabs(x)) -> mul(x,x)
897 define i31 @combine_mul_nabs_i31(i31 %0) {
898 ; CHECK-LABEL: @combine_mul_nabs_i31(
899 ; CHECK-NEXT: [[M:%.*]] = mul i31 [[TMP0:%.*]], [[TMP0]]
900 ; CHECK-NEXT: ret i31 [[M]]
902 %c = icmp slt i31 %0, 0
903 %s = sub nsw i31 0, %0
904 %r = select i1 %c, i31 %0, i31 %s
909 define i32 @combine_mul_nabs_i32(i32 %0) {
910 ; CHECK-LABEL: @combine_mul_nabs_i32(
911 ; CHECK-NEXT: [[M:%.*]] = mul i32 [[TMP0:%.*]], [[TMP0]]
912 ; CHECK-NEXT: ret i32 [[M]]
914 %c = icmp slt i32 %0, 0
915 %s = sub nsw i32 0, %0
916 %r = select i1 %c, i32 %0, i32 %s
921 define <4 x i32> @combine_mul_nabs_v4i32(<4 x i32> %0) {
922 ; CHECK-LABEL: @combine_mul_nabs_v4i32(
923 ; CHECK-NEXT: [[M:%.*]] = mul <4 x i32> [[TMP0:%.*]], [[TMP0]]
924 ; CHECK-NEXT: ret <4 x i32> [[M]]
926 %c = icmp slt <4 x i32> %0, zeroinitializer
927 %s = sub nsw <4 x i32> zeroinitializer, %0
928 %r = select <4 x i1> %c, <4 x i32> %0, <4 x i32> %s
929 %m = mul <4 x i32> %r, %r
933 define i32 @combine_mul_abs_intrin(i32 %x) {
934 ; CHECK-LABEL: @combine_mul_abs_intrin(
935 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[X:%.*]], [[X]]
936 ; CHECK-NEXT: ret i32 [[MUL]]
938 %abs = call i32 @llvm.abs.i32(i32 %x, i1 false)
939 %mul = mul i32 %abs, %abs
943 define i32 @combine_mul_nabs_intrin(i32 %x) {
944 ; CHECK-LABEL: @combine_mul_nabs_intrin(
945 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[X:%.*]], [[X]]
946 ; CHECK-NEXT: ret i32 [[MUL]]
948 %abs = call i32 @llvm.abs.i32(i32 %x, i1 false)
949 %neg = sub i32 0, %abs
950 %mul = mul i32 %neg, %neg
954 ; z * splat(0) = splat(0), even for scalable vectors
955 define <vscale x 2 x i64> @mul_scalable_splat_zero(<vscale x 2 x i64> %z) {
956 ; CHECK-LABEL: @mul_scalable_splat_zero(
957 ; CHECK-NEXT: ret <vscale x 2 x i64> zeroinitializer
959 %shuf = shufflevector <vscale x 2 x i64> insertelement (<vscale x 2 x i64> undef, i64 0, i32 0), <vscale x 2 x i64> undef, <vscale x 2 x i32> zeroinitializer
960 %t3 = mul <vscale x 2 x i64> %shuf, %z
961 ret <vscale x 2 x i64> %t3
965 ; fold mul(sub(x,y),negpow2) -> shl(sub(y,x),log2(pow2))
968 define i32 @mulsub1(i32 %a0, i32 %a1) {
969 ; CHECK-LABEL: @mulsub1(
970 ; CHECK-NEXT: [[SUB_NEG:%.*]] = sub i32 [[A0:%.*]], [[A1:%.*]]
971 ; CHECK-NEXT: [[MUL:%.*]] = shl i32 [[SUB_NEG]], 2
972 ; CHECK-NEXT: ret i32 [[MUL]]
974 %sub = sub i32 %a1, %a0
975 %mul = mul i32 %sub, -4
979 define <2 x i32> @mulsub1_vec(<2 x i32> %a0, <2 x i32> %a1) {
980 ; CHECK-LABEL: @mulsub1_vec(
981 ; CHECK-NEXT: [[SUB_NEG:%.*]] = sub <2 x i32> [[A0:%.*]], [[A1:%.*]]
982 ; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[SUB_NEG]], <i32 2, i32 2>
983 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
985 %sub = sub <2 x i32> %a1, %a0
986 %mul = mul <2 x i32> %sub, <i32 -4, i32 -4>
990 define <2 x i32> @mulsub1_vec_nonuniform(<2 x i32> %a0, <2 x i32> %a1) {
991 ; CHECK-LABEL: @mulsub1_vec_nonuniform(
992 ; CHECK-NEXT: [[SUB_NEG:%.*]] = sub <2 x i32> [[A0:%.*]], [[A1:%.*]]
993 ; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[SUB_NEG]], <i32 2, i32 3>
994 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
996 %sub = sub <2 x i32> %a1, %a0
997 %mul = mul <2 x i32> %sub, <i32 -4, i32 -8>
1001 define <2 x i32> @mulsub1_vec_nonuniform_undef(<2 x i32> %a0, <2 x i32> %a1) {
1002 ; CHECK-LABEL: @mulsub1_vec_nonuniform_undef(
1003 ; CHECK-NEXT: [[SUB_NEG:%.*]] = sub <2 x i32> [[A0:%.*]], [[A1:%.*]]
1004 ; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[SUB_NEG]], <i32 2, i32 0>
1005 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
1007 %sub = sub <2 x i32> %a1, %a0
1008 %mul = mul <2 x i32> %sub, <i32 -4, i32 undef>
1012 define i32 @mulsub2(i32 %a0) {
1013 ; CHECK-LABEL: @mulsub2(
1014 ; CHECK-NEXT: [[SUB_NEG:%.*]] = shl i32 [[A0:%.*]], 2
1015 ; CHECK-NEXT: [[MUL:%.*]] = add i32 [[SUB_NEG]], -64
1016 ; CHECK-NEXT: ret i32 [[MUL]]
1018 %sub = sub i32 16, %a0
1019 %mul = mul i32 %sub, -4
1023 define <2 x i32> @mulsub2_vec(<2 x i32> %a0) {
1024 ; CHECK-LABEL: @mulsub2_vec(
1025 ; CHECK-NEXT: [[SUB_NEG:%.*]] = shl <2 x i32> [[A0:%.*]], <i32 2, i32 2>
1026 ; CHECK-NEXT: [[MUL:%.*]] = add <2 x i32> [[SUB_NEG]], <i32 -64, i32 -64>
1027 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
1029 %sub = sub <2 x i32> <i32 16, i32 16>, %a0
1030 %mul = mul <2 x i32> %sub, <i32 -4, i32 -4>
1034 define <2 x i32> @mulsub2_vec_nonuniform(<2 x i32> %a0) {
1035 ; CHECK-LABEL: @mulsub2_vec_nonuniform(
1036 ; CHECK-NEXT: [[SUB_NEG:%.*]] = add <2 x i32> [[A0:%.*]], <i32 -16, i32 -32>
1037 ; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[SUB_NEG]], <i32 2, i32 3>
1038 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
1040 %sub = sub <2 x i32> <i32 16, i32 32>, %a0
1041 %mul = mul <2 x i32> %sub, <i32 -4, i32 -8>
1045 define <2 x i32> @mulsub2_vec_nonuniform_undef(<2 x i32> %a0) {
1046 ; CHECK-LABEL: @mulsub2_vec_nonuniform_undef(
1047 ; CHECK-NEXT: [[SUB_NEG:%.*]] = add <2 x i32> [[A0:%.*]], <i32 -16, i32 -32>
1048 ; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[SUB_NEG]], <i32 2, i32 0>
1049 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
1051 %sub = sub <2 x i32> <i32 16, i32 32>, %a0
1052 %mul = mul <2 x i32> %sub, <i32 -4, i32 undef>
1056 define i32 @muladd2(i32 %a0) {
1057 ; CHECK-LABEL: @muladd2(
1058 ; CHECK-NEXT: [[ADD_NEG_NEG:%.*]] = mul i32 [[A0:%.*]], -4
1059 ; CHECK-NEXT: [[MUL:%.*]] = add i32 [[ADD_NEG_NEG]], -64
1060 ; CHECK-NEXT: ret i32 [[MUL]]
1062 %add = add i32 %a0, 16
1063 %mul = mul i32 %add, -4
1067 define <2 x i32> @muladd2_vec(<2 x i32> %a0) {
1068 ; CHECK-LABEL: @muladd2_vec(
1069 ; CHECK-NEXT: [[ADD_NEG_NEG:%.*]] = mul <2 x i32> [[A0:%.*]], <i32 -4, i32 -4>
1070 ; CHECK-NEXT: [[MUL:%.*]] = add <2 x i32> [[ADD_NEG_NEG]], <i32 -64, i32 -64>
1071 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
1073 %add = add <2 x i32> %a0, <i32 16, i32 16>
1074 %mul = mul <2 x i32> %add, <i32 -4, i32 -4>
1078 define <2 x i32> @muladd2_vec_nonuniform(<2 x i32> %a0) {
1079 ; CHECK-LABEL: @muladd2_vec_nonuniform(
1080 ; CHECK-NEXT: [[ADD_NEG:%.*]] = sub <2 x i32> <i32 -16, i32 -32>, [[A0:%.*]]
1081 ; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[ADD_NEG]], <i32 2, i32 3>
1082 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
1084 %add = add <2 x i32> %a0, <i32 16, i32 32>
1085 %mul = mul <2 x i32> %add, <i32 -4, i32 -8>
1089 define <2 x i32> @muladd2_vec_nonuniform_undef(<2 x i32> %a0) {
1090 ; CHECK-LABEL: @muladd2_vec_nonuniform_undef(
1091 ; CHECK-NEXT: [[ADD_NEG:%.*]] = sub <2 x i32> <i32 -16, i32 -32>, [[A0:%.*]]
1092 ; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[ADD_NEG]], <i32 2, i32 0>
1093 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
1095 %add = add <2 x i32> %a0, <i32 16, i32 32>
1096 %mul = mul <2 x i32> %add, <i32 -4, i32 undef>
1100 define i32 @mulmuladd2(i32 %a0, i32 %a1) {
1101 ; CHECK-LABEL: @mulmuladd2(
1102 ; CHECK-NEXT: [[ADD_NEG:%.*]] = sub i32 -16, [[A0:%.*]]
1103 ; CHECK-NEXT: [[MUL1_NEG:%.*]] = mul i32 [[ADD_NEG]], [[A1:%.*]]
1104 ; CHECK-NEXT: [[MUL2:%.*]] = shl i32 [[MUL1_NEG]], 2
1105 ; CHECK-NEXT: ret i32 [[MUL2]]
1107 %add = add i32 %a0, 16
1108 %mul1 = mul i32 %add, %a1
1109 %mul2 = mul i32 %mul1, -4
1112 define i32 @mulmuladd2_extrause0(i32 %a0, i32 %a1) {
1113 ; CHECK-LABEL: @mulmuladd2_extrause0(
1114 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[A0:%.*]], 16
1115 ; CHECK-NEXT: [[MUL1:%.*]] = mul i32 [[ADD]], [[A1:%.*]]
1116 ; CHECK-NEXT: call void @use32(i32 [[MUL1]])
1117 ; CHECK-NEXT: [[MUL2:%.*]] = mul i32 [[MUL1]], -4
1118 ; CHECK-NEXT: ret i32 [[MUL2]]
1120 %add = add i32 %a0, 16
1121 %mul1 = mul i32 %add, %a1
1122 call void @use32(i32 %mul1)
1123 %mul2 = mul i32 %mul1, -4
1126 define i32 @mulmuladd2_extrause1(i32 %a0, i32 %a1) {
1127 ; CHECK-LABEL: @mulmuladd2_extrause1(
1128 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[A0:%.*]], 16
1129 ; CHECK-NEXT: call void @use32(i32 [[ADD]])
1130 ; CHECK-NEXT: [[MUL1:%.*]] = mul i32 [[ADD]], [[A1:%.*]]
1131 ; CHECK-NEXT: [[MUL2:%.*]] = mul i32 [[MUL1]], -4
1132 ; CHECK-NEXT: ret i32 [[MUL2]]
1134 %add = add i32 %a0, 16
1135 call void @use32(i32 %add)
1136 %mul1 = mul i32 %add, %a1
1137 %mul2 = mul i32 %mul1, -4
1140 define i32 @mulmuladd2_extrause2(i32 %a0, i32 %a1) {
1141 ; CHECK-LABEL: @mulmuladd2_extrause2(
1142 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[A0:%.*]], 16
1143 ; CHECK-NEXT: call void @use32(i32 [[ADD]])
1144 ; CHECK-NEXT: [[MUL1:%.*]] = mul i32 [[ADD]], [[A1:%.*]]
1145 ; CHECK-NEXT: call void @use32(i32 [[MUL1]])
1146 ; CHECK-NEXT: [[MUL2:%.*]] = mul i32 [[MUL1]], -4
1147 ; CHECK-NEXT: ret i32 [[MUL2]]
1149 %add = add i32 %a0, 16
1150 call void @use32(i32 %add)
1151 %mul1 = mul i32 %add, %a1
1152 call void @use32(i32 %mul1)
1153 %mul2 = mul i32 %mul1, -4
1157 define i32 @mulnot(i32 %a0) {
1158 ; CHECK-LABEL: @mulnot(
1159 ; CHECK-NEXT: [[ADD_NEG:%.*]] = shl i32 [[A0:%.*]], 2
1160 ; CHECK-NEXT: [[MUL:%.*]] = add i32 [[ADD_NEG]], 4
1161 ; CHECK-NEXT: ret i32 [[MUL]]
1163 %add = xor i32 %a0, -1
1164 %mul = mul i32 %add, -4
1167 define i32 @mulnot_extrause(i32 %a0) {
1168 ; CHECK-LABEL: @mulnot_extrause(
1169 ; CHECK-NEXT: [[NOT:%.*]] = xor i32 [[A0:%.*]], -1
1170 ; CHECK-NEXT: call void @use32(i32 [[NOT]])
1171 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[NOT]], -4
1172 ; CHECK-NEXT: ret i32 [[MUL]]
1174 %not = xor i32 %a0, -1
1175 call void @use32(i32 %not)
1176 %mul = mul i32 %not, -4