Skip to content

Commit 415b9f5

Browse files
committed
Recommit "[RISCV] Use selectShiftMaskXLen ComplexPattern for isel of rotates."
This reverts commit dfe513a. Tests have been changed to avoid the type legalization bug being fixed in D126036. Original commit message: This will remove masks on the shift amount. We usually get this with SimplifyDemandedBits in DAGCombine, but that's restricted to cases where the AND has a single use. selectShiftMaskXLen does not have that restriction.
1 parent cddeb78 commit 415b9f5

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoZb.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,8 @@ def : Pat<(xor GPR:$rs1, (not GPR:$rs2)), (XNOR GPR:$rs1, GPR:$rs2)>;
817817
} // Predicates = [HasStdExtZbbOrZbpOrZbkb]
818818

819819
let Predicates = [HasStdExtZbbOrZbpOrZbkb] in {
820-
def : PatGprGpr<rotl, ROL>;
821-
def : PatGprGpr<rotr, ROR>;
820+
def : PatGprGpr<shiftop<rotl>, ROL>;
821+
def : PatGprGpr<shiftop<rotr>, ROR>;
822822

823823
def : PatGprImm<rotr, RORI, uimmlog2xlen>;
824824
// There's no encoding for roli in the the 'B' extension as it can be
@@ -828,8 +828,8 @@ def : Pat<(rotl GPR:$rs1, uimmlog2xlen:$shamt),
828828
} // Predicates = [HasStdExtZbbOrZbpOrZbkb]
829829

830830
let Predicates = [HasStdExtZbbOrZbpOrZbkb, IsRV64] in {
831-
def : PatGprGpr<riscv_rolw, ROLW>;
832-
def : PatGprGpr<riscv_rorw, RORW>;
831+
def : PatGprGpr<shiftopw<riscv_rolw>, ROLW>;
832+
def : PatGprGpr<shiftopw<riscv_rorw>, RORW>;
833833
def : PatGprImm<riscv_rorw, RORIW, uimm5>;
834834
def : Pat<(riscv_rolw GPR:$rs1, uimm5:$rs2),
835835
(RORIW GPR:$rs1, (ImmSubFrom32 uimm5:$rs2))>;

llvm/test/CodeGen/RISCV/rotl-rotr.ll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,7 @@ define signext i32 @rotl_32_mask_shared(i32 signext %a, i32 signext %b, i32 sign
576576
;
577577
; RV32ZBB-LABEL: rotl_32_mask_shared:
578578
; RV32ZBB: # %bb.0:
579-
; RV32ZBB-NEXT: andi a3, a2, 31
580-
; RV32ZBB-NEXT: rol a0, a0, a3
579+
; RV32ZBB-NEXT: rol a0, a0, a2
581580
; RV32ZBB-NEXT: sll a1, a1, a2
582581
; RV32ZBB-NEXT: add a0, a0, a1
583582
; RV32ZBB-NEXT: ret
@@ -695,8 +694,7 @@ define signext i64 @rotl_64_mask_shared(i64 signext %a, i64 signext %b, i64 sign
695694
;
696695
; RV64ZBB-LABEL: rotl_64_mask_shared:
697696
; RV64ZBB: # %bb.0:
698-
; RV64ZBB-NEXT: andi a3, a2, 63
699-
; RV64ZBB-NEXT: rol a0, a0, a3
697+
; RV64ZBB-NEXT: rol a0, a0, a2
700698
; RV64ZBB-NEXT: sll a1, a1, a2
701699
; RV64ZBB-NEXT: add a0, a0, a1
702700
; RV64ZBB-NEXT: ret
@@ -731,8 +729,7 @@ define signext i32 @rotr_32_mask_shared(i32 signext %a, i32 signext %b, i32 sign
731729
;
732730
; RV32ZBB-LABEL: rotr_32_mask_shared:
733731
; RV32ZBB: # %bb.0:
734-
; RV32ZBB-NEXT: andi a3, a2, 31
735-
; RV32ZBB-NEXT: ror a0, a0, a3
732+
; RV32ZBB-NEXT: ror a0, a0, a2
736733
; RV32ZBB-NEXT: sll a1, a1, a2
737734
; RV32ZBB-NEXT: add a0, a0, a1
738735
; RV32ZBB-NEXT: ret
@@ -848,8 +845,7 @@ define signext i64 @rotr_64_mask_shared(i64 signext %a, i64 signext %b, i64 sign
848845
;
849846
; RV64ZBB-LABEL: rotr_64_mask_shared:
850847
; RV64ZBB: # %bb.0:
851-
; RV64ZBB-NEXT: andi a3, a2, 63
852-
; RV64ZBB-NEXT: ror a0, a0, a3
848+
; RV64ZBB-NEXT: ror a0, a0, a2
853849
; RV64ZBB-NEXT: sll a1, a1, a2
854850
; RV64ZBB-NEXT: add a0, a0, a1
855851
; RV64ZBB-NEXT: ret

0 commit comments

Comments
 (0)