Skip to content

Commit 98b6f90

Browse files
committed
[InstCombine] Pre-commit tests (NFC)
1 parent 224116a commit 98b6f90

File tree

2 files changed

+138
-1
lines changed

2 files changed

+138
-1
lines changed

llvm/test/Transforms/InstCombine/ashr-lshr.ll

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,3 +604,127 @@ define <2 x i8> @ashr_known_pos_exact_vec(<2 x i8> %x, <2 x i8> %y) {
604604
%r = ashr exact <2 x i8> %p, %y
605605
ret <2 x i8> %r
606606
}
607+
608+
define i32 @lshr_mul_times_3_div_2(i32 %0) {
609+
; CHECK-LABEL: @lshr_mul_times_3_div_2(
610+
; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i32 [[TMP0:%.*]], 3
611+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[MUL]], 1
612+
; CHECK-NEXT: ret i32 [[LSHR]]
613+
;
614+
%mul = mul nsw nuw i32 %0, 3
615+
%lshr = lshr i32 %mul, 1
616+
ret i32 %lshr
617+
}
618+
619+
define i32 @lshr_mul_times_3_div_2_exact(i32 %x) {
620+
; CHECK-LABEL: @lshr_mul_times_3_div_2_exact(
621+
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[X:%.*]], 3
622+
; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[MUL]], 1
623+
; CHECK-NEXT: ret i32 [[LSHR]]
624+
;
625+
%mul = mul nsw i32 %x, 3
626+
%lshr = lshr exact i32 %mul, 1
627+
ret i32 %lshr
628+
}
629+
630+
; Negative test
631+
632+
define i32 @lshr_mul_times_3_div_2_no_flags(i32 %0) {
633+
; CHECK-LABEL: @lshr_mul_times_3_div_2_no_flags(
634+
; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[TMP0:%.*]], 3
635+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[MUL]], 1
636+
; CHECK-NEXT: ret i32 [[LSHR]]
637+
;
638+
%mul = mul i32 %0, 3
639+
%lshr = lshr i32 %mul, 1
640+
ret i32 %lshr
641+
}
642+
643+
; Negative test
644+
645+
define i32 @mul_times_3_div_2_multiuse_lshr(i32 %x) {
646+
; CHECK-LABEL: @mul_times_3_div_2_multiuse_lshr(
647+
; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[X:%.*]], 3
648+
; CHECK-NEXT: [[RES:%.*]] = lshr i32 [[MUL]], 1
649+
; CHECK-NEXT: call void @use(i32 [[MUL]])
650+
; CHECK-NEXT: ret i32 [[RES]]
651+
;
652+
%mul = mul nuw i32 %x, 3
653+
%res = lshr i32 %mul, 1
654+
call void @use(i32 %mul)
655+
ret i32 %res
656+
}
657+
658+
define i32 @lshr_mul_times_3_div_2_exact_2(i32 %x) {
659+
; CHECK-LABEL: @lshr_mul_times_3_div_2_exact_2(
660+
; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[X:%.*]], 3
661+
; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[MUL]], 1
662+
; CHECK-NEXT: ret i32 [[LSHR]]
663+
;
664+
%mul = mul nuw i32 %x, 3
665+
%lshr = lshr exact i32 %mul, 1
666+
ret i32 %lshr
667+
}
668+
669+
define i32 @lshr_mul_times_5_div_4(i32 %0) {
670+
; CHECK-LABEL: @lshr_mul_times_5_div_4(
671+
; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i32 [[TMP0:%.*]], 5
672+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[MUL]], 2
673+
; CHECK-NEXT: ret i32 [[LSHR]]
674+
;
675+
%mul = mul nsw nuw i32 %0, 5
676+
%lshr = lshr i32 %mul, 2
677+
ret i32 %lshr
678+
}
679+
680+
define i32 @lshr_mul_times_5_div_4_exact(i32 %x) {
681+
; CHECK-LABEL: @lshr_mul_times_5_div_4_exact(
682+
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[X:%.*]], 5
683+
; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[MUL]], 2
684+
; CHECK-NEXT: ret i32 [[LSHR]]
685+
;
686+
%mul = mul nsw i32 %x, 5
687+
%lshr = lshr exact i32 %mul, 2
688+
ret i32 %lshr
689+
}
690+
691+
; Negative test
692+
693+
define i32 @lshr_mul_times_5_div_4_no_flags(i32 %0) {
694+
; CHECK-LABEL: @lshr_mul_times_5_div_4_no_flags(
695+
; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[TMP0:%.*]], 5
696+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[MUL]], 2
697+
; CHECK-NEXT: ret i32 [[LSHR]]
698+
;
699+
%mul = mul i32 %0, 5
700+
%lshr = lshr i32 %mul, 2
701+
ret i32 %lshr
702+
}
703+
704+
; Negative test
705+
706+
define i32 @mul_times_5_div_4_multiuse_lshr(i32 %x) {
707+
; CHECK-LABEL: @mul_times_5_div_4_multiuse_lshr(
708+
; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[X:%.*]], 5
709+
; CHECK-NEXT: [[RES:%.*]] = lshr i32 [[MUL]], 2
710+
; CHECK-NEXT: call void @use(i32 [[MUL]])
711+
; CHECK-NEXT: ret i32 [[RES]]
712+
;
713+
%mul = mul nuw i32 %x, 5
714+
%res = lshr i32 %mul, 2
715+
call void @use(i32 %mul)
716+
ret i32 %res
717+
}
718+
719+
define i32 @lshr_mul_times_5_div_4_exact_2(i32 %x) {
720+
; CHECK-LABEL: @lshr_mul_times_5_div_4_exact_2(
721+
; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[X:%.*]], 5
722+
; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[MUL]], 2
723+
; CHECK-NEXT: ret i32 [[LSHR]]
724+
;
725+
%mul = mul nuw i32 %x, 5
726+
%lshr = lshr exact i32 %mul, 2
727+
ret i32 %lshr
728+
}
729+
730+
declare void @use(i32)

llvm/test/Transforms/InstCombine/lshr.ll

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ define i32 @mul_splat_fold_wrong_lshr_const(i32 %x) {
628628
ret i32 %t
629629
}
630630

631-
; Negative test
631+
; Negative test (but simplifies into a different transform)
632632

633633
define i32 @mul_splat_fold_no_nuw(i32 %x) {
634634
; CHECK-LABEL: @mul_splat_fold_no_nuw(
@@ -641,6 +641,19 @@ define i32 @mul_splat_fold_no_nuw(i32 %x) {
641641
ret i32 %t
642642
}
643643

644+
; Negative test
645+
646+
define i32 @mul_splat_fold_no_flags(i32 %x) {
647+
; CHECK-LABEL: @mul_splat_fold_no_flags(
648+
; CHECK-NEXT: [[M:%.*]] = mul i32 [[X:%.*]], 65537
649+
; CHECK-NEXT: [[T:%.*]] = lshr i32 [[M]], 16
650+
; CHECK-NEXT: ret i32 [[T]]
651+
;
652+
%m = mul i32 %x, 65537
653+
%t = lshr i32 %m, 16
654+
ret i32 %t
655+
}
656+
644657
; Negative test (but simplifies before we reach the mul_splat transform)- need more than 2 bits
645658

646659
define i2 @mul_splat_fold_too_narrow(i2 %x) {

0 commit comments

Comments
 (0)