@@ -360,8 +360,65 @@ define <3 x i14> @mul_splat_fold_vec(<3 x i14> %x) {
360
360
ret <3 x i14 > %t
361
361
}
362
362
363
+ define i32 @mul_times_3_div_2 (i32 %x ) {
364
+ ; CHECK-LABEL: @mul_times_3_div_2(
365
+ ; CHECK-NEXT: [[TMP1:%.*]] = mul nuw nsw i32 [[X:%.*]], 3
366
+ ; CHECK-NEXT: [[TMP2:%.*]] = lshr i32 [[TMP1]], 1
367
+ ; CHECK-NEXT: ret i32 [[TMP2]]
368
+ ;
369
+ %2 = mul nsw nuw i32 %x , 3
370
+ %3 = lshr i32 %2 , 1
371
+ ret i32 %3
372
+ }
373
+
374
+ define i32 @shl_add_lshr (i32 %x , i32 %c , i32 %y ) {
375
+ ; CHECK-LABEL: @shl_add_lshr(
376
+ ; CHECK-NEXT: [[TMP1:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
377
+ ; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i32 [[TMP1]], [[Y:%.*]]
378
+ ; CHECK-NEXT: [[TMP3:%.*]] = lshr exact i32 [[TMP2]], [[C]]
379
+ ; CHECK-NEXT: ret i32 [[TMP3]]
380
+ ;
381
+ %2 = shl nuw i32 %x , %c
382
+ %3 = add nsw nuw i32 %2 , %y
383
+ %4 = lshr exact i32 %3 , %c
384
+ ret i32 %4
385
+ }
386
+
387
+ define i32 @ashr_mul_times_3_div_2 (i32 %0 ) {
388
+ ; CHECK-LABEL: @ashr_mul_times_3_div_2(
389
+ ; CHECK-NEXT: [[TMP2:%.*]] = mul nuw nsw i32 [[TMP0:%.*]], 3
390
+ ; CHECK-NEXT: [[TMP3:%.*]] = ashr i32 [[TMP2]], 1
391
+ ; CHECK-NEXT: ret i32 [[TMP3]]
392
+ ;
393
+ %2 = mul nsw nuw i32 %0 , 3
394
+ %3 = ashr i32 %2 , 1
395
+ ret i32 %3
396
+ }
397
+
398
+ define i32 @ashr_mul_times_3_div_2_exact (i32 %0 ) {
399
+ ; CHECK-LABEL: @ashr_mul_times_3_div_2_exact(
400
+ ; CHECK-NEXT: [[TMP2:%.*]] = mul nsw i32 [[TMP0:%.*]], 3
401
+ ; CHECK-NEXT: [[TMP3:%.*]] = ashr exact i32 [[TMP2]], 1
402
+ ; CHECK-NEXT: ret i32 [[TMP3]]
403
+ ;
404
+ %2 = mul nsw i32 %0 , 3
405
+ %3 = ashr exact i32 %2 , 1
406
+ ret i32 %3
407
+ }
408
+
363
409
; Negative test
364
410
411
+ define i32 @mul_times_3_div_2_no_nsw (i32 %x ) {
412
+ ; CHECK-LABEL: @mul_times_3_div_2_no_nsw(
413
+ ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[X:%.*]], 3
414
+ ; CHECK-NEXT: [[TMP2:%.*]] = lshr i32 [[TMP1]], 1
415
+ ; CHECK-NEXT: ret i32 [[TMP2]]
416
+ ;
417
+ %2 = mul i32 %x , 3
418
+ %3 = lshr i32 %2 , 1
419
+ ret i32 %3
420
+ }
421
+
365
422
define i32 @mul_splat_fold_wrong_mul_const (i32 %x ) {
366
423
; CHECK-LABEL: @mul_splat_fold_wrong_mul_const(
367
424
; CHECK-NEXT: [[M:%.*]] = mul nuw i32 [[X:%.*]], 65538
0 commit comments