@@ -604,3 +604,97 @@ define <2 x i8> @ashr_known_pos_exact_vec(<2 x i8> %x, <2 x i8> %y) {
604
604
%r = ashr exact <2 x i8 > %p , %y
605
605
ret <2 x i8 > %r
606
606
}
607
+
608
+ define i32 @ashr_mul_times_3_div_2 (i32 %0 ) {
609
+ ; CHECK-LABEL: @ashr_mul_times_3_div_2(
610
+ ; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i32 [[TMP0:%.*]], 3
611
+ ; CHECK-NEXT: [[ASHR:%.*]] = ashr i32 [[MUL]], 1
612
+ ; CHECK-NEXT: ret i32 [[ASHR]]
613
+ ;
614
+ %mul = mul nsw nuw i32 %0 , 3
615
+ %ashr = ashr i32 %mul , 1
616
+ ret i32 %ashr
617
+ }
618
+
619
+ define i32 @ashr_mul_times_3_div_2_exact (i32 %x ) {
620
+ ; CHECK-LABEL: @ashr_mul_times_3_div_2_exact(
621
+ ; CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[X:%.*]], 3
622
+ ; CHECK-NEXT: [[ASHR:%.*]] = ashr exact i32 [[MUL]], 1
623
+ ; CHECK-NEXT: ret i32 [[ASHR]]
624
+ ;
625
+ %mul = mul nsw i32 %x , 3
626
+ %ashr = ashr exact i32 %mul , 1
627
+ ret i32 %ashr
628
+ }
629
+
630
+ define i32 @mul_times_3_div_2_multiuse (i32 %x ) {
631
+ ; CHECK-LABEL: @mul_times_3_div_2_multiuse(
632
+ ; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[X:%.*]], 3
633
+ ; CHECK-NEXT: [[RES:%.*]] = ashr i32 [[MUL]], 1
634
+ ; CHECK-NEXT: call void @use(i32 [[MUL]])
635
+ ; CHECK-NEXT: ret i32 [[RES]]
636
+ ;
637
+ %mul = mul nuw i32 %x , 3
638
+ %res = ashr i32 %mul , 1
639
+ call void @use (i32 %mul )
640
+ ret i32 %res
641
+ }
642
+
643
+ define i32 @ashr_mul_times_3_div_2_exact_2 (i32 %x ) {
644
+ ; CHECK-LABEL: @ashr_mul_times_3_div_2_exact_2(
645
+ ; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[X:%.*]], 3
646
+ ; CHECK-NEXT: [[ASHR:%.*]] = ashr exact i32 [[MUL]], 1
647
+ ; CHECK-NEXT: ret i32 [[ASHR]]
648
+ ;
649
+ %mul = mul nuw i32 %x , 3
650
+ %ashr = ashr exact i32 %mul , 1
651
+ ret i32 %ashr
652
+ }
653
+
654
+ define i32 @lshr_mul_times_3_div_2 (i32 %0 ) {
655
+ ; CHECK-LABEL: @lshr_mul_times_3_div_2(
656
+ ; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i32 [[TMP0:%.*]], 3
657
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[MUL]], 1
658
+ ; CHECK-NEXT: ret i32 [[LSHR]]
659
+ ;
660
+ %mul = mul nsw nuw i32 %0 , 3
661
+ %lshr = lshr i32 %mul , 1
662
+ ret i32 %lshr
663
+ }
664
+
665
+ define i32 @lshr_mul_times_3_div_2_exact (i32 %x ) {
666
+ ; CHECK-LABEL: @lshr_mul_times_3_div_2_exact(
667
+ ; CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[X:%.*]], 3
668
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[MUL]], 1
669
+ ; CHECK-NEXT: ret i32 [[LSHR]]
670
+ ;
671
+ %mul = mul nsw i32 %x , 3
672
+ %lshr = lshr exact i32 %mul , 1
673
+ ret i32 %lshr
674
+ }
675
+
676
+ define i32 @mul_times_3_div_2_multiuse_lshr (i32 %x ) {
677
+ ; CHECK-LABEL: @mul_times_3_div_2_multiuse_lshr(
678
+ ; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[X:%.*]], 3
679
+ ; CHECK-NEXT: [[RES:%.*]] = lshr i32 [[MUL]], 1
680
+ ; CHECK-NEXT: call void @use(i32 [[MUL]])
681
+ ; CHECK-NEXT: ret i32 [[RES]]
682
+ ;
683
+ %mul = mul nuw i32 %x , 3
684
+ %res = lshr i32 %mul , 1
685
+ call void @use (i32 %mul )
686
+ ret i32 %res
687
+ }
688
+
689
+ define i32 @lshr_mul_times_3_div_2_exact_2 (i32 %x ) {
690
+ ; CHECK-LABEL: @lshr_mul_times_3_div_2_exact_2(
691
+ ; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[X:%.*]], 3
692
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[MUL]], 1
693
+ ; CHECK-NEXT: ret i32 [[LSHR]]
694
+ ;
695
+ %mul = mul nuw i32 %x , 3
696
+ %lshr = lshr exact i32 %mul , 1
697
+ ret i32 %lshr
698
+ }
699
+
700
+ declare void @use (i32 )
0 commit comments