@@ -675,6 +675,61 @@ define i9 @rotateleft_9_neg_mask_wide_amount_commute(i9 %v, i33 %shamt) {
675
675
ret i9 %ret
676
676
}
677
677
678
+ ; Fold or(shl(v,x),lshr(v,bw-x)) iff x < bw
679
+
680
+ define i64 @rotl_sub_mask (i64 %0 , i64 %1 ) {
681
+ ; CHECK-LABEL: @rotl_sub_mask(
682
+ ; CHECK-NEXT: [[TMP3:%.*]] = and i64 [[TMP1:%.*]], 63
683
+ ; CHECK-NEXT: [[TMP4:%.*]] = shl i64 [[TMP0:%.*]], [[TMP3]]
684
+ ; CHECK-NEXT: [[TMP5:%.*]] = sub nuw nsw i64 64, [[TMP3]]
685
+ ; CHECK-NEXT: [[TMP6:%.*]] = lshr i64 [[TMP0]], [[TMP5]]
686
+ ; CHECK-NEXT: [[TMP7:%.*]] = or i64 [[TMP6]], [[TMP4]]
687
+ ; CHECK-NEXT: ret i64 [[TMP7]]
688
+ ;
689
+ %3 = and i64 %1 , 63
690
+ %4 = shl i64 %0 , %3
691
+ %5 = sub nuw nsw i64 64 , %3
692
+ %6 = lshr i64 %0 , %5
693
+ %7 = or i64 %6 , %4
694
+ ret i64 %7
695
+ }
696
+
697
+ ; Fold or(lshr(v,x),shl(v,bw-x)) iff x < bw
698
+
699
+ define i64 @rotr_sub_mask (i64 %0 , i64 %1 ) {
700
+ ; CHECK-LABEL: @rotr_sub_mask(
701
+ ; CHECK-NEXT: [[TMP3:%.*]] = and i64 [[TMP1:%.*]], 63
702
+ ; CHECK-NEXT: [[TMP4:%.*]] = lshr i64 [[TMP0:%.*]], [[TMP3]]
703
+ ; CHECK-NEXT: [[TMP5:%.*]] = sub nuw nsw i64 64, [[TMP3]]
704
+ ; CHECK-NEXT: [[TMP6:%.*]] = shl i64 [[TMP0]], [[TMP5]]
705
+ ; CHECK-NEXT: [[TMP7:%.*]] = or i64 [[TMP6]], [[TMP4]]
706
+ ; CHECK-NEXT: ret i64 [[TMP7]]
707
+ ;
708
+ %3 = and i64 %1 , 63
709
+ %4 = lshr i64 %0 , %3
710
+ %5 = sub nuw nsw i64 64 , %3
711
+ %6 = shl i64 %0 , %5
712
+ %7 = or i64 %6 , %4
713
+ ret i64 %7
714
+ }
715
+
716
+ define <2 x i64 > @rotr_sub_mask_vector (<2 x i64 > %0 , <2 x i64 > %1 ) {
717
+ ; CHECK-LABEL: @rotr_sub_mask_vector(
718
+ ; CHECK-NEXT: [[TMP3:%.*]] = and <2 x i64> [[TMP1:%.*]], <i64 63, i64 63>
719
+ ; CHECK-NEXT: [[TMP4:%.*]] = lshr <2 x i64> [[TMP0:%.*]], [[TMP3]]
720
+ ; CHECK-NEXT: [[TMP5:%.*]] = sub nuw nsw <2 x i64> <i64 64, i64 64>, [[TMP3]]
721
+ ; CHECK-NEXT: [[TMP6:%.*]] = shl <2 x i64> [[TMP0]], [[TMP5]]
722
+ ; CHECK-NEXT: [[TMP7:%.*]] = or <2 x i64> [[TMP6]], [[TMP4]]
723
+ ; CHECK-NEXT: ret <2 x i64> [[TMP7]]
724
+ ;
725
+ %3 = and <2 x i64 > %1 , <i64 63 , i64 63 >
726
+ %4 = lshr <2 x i64 > %0 , %3
727
+ %5 = sub nuw nsw <2 x i64 > <i64 64 , i64 64 >, %3
728
+ %6 = shl <2 x i64 > %0 , %5
729
+ %7 = or <2 x i64 > %6 , %4
730
+ ret <2 x i64 > %7
731
+ }
732
+
678
733
; Convert select pattern to masked shift that ends in 'or'.
679
734
680
735
define i32 @rotr_select (i32 %x , i32 %shamt ) {
0 commit comments