Skip to content

Commit

Permalink
Recommit "[RISCV] Use selectShiftMaskXLen ComplexPattern for isel of …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
topperc committed May 24, 2022
1 parent cddeb78 commit 415b9f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
8 changes: 4 additions & 4 deletions llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
Expand Up @@ -817,8 +817,8 @@ def : Pat<(xor GPR:$rs1, (not GPR:$rs2)), (XNOR GPR:$rs1, GPR:$rs2)>;
} // Predicates = [HasStdExtZbbOrZbpOrZbkb]

let Predicates = [HasStdExtZbbOrZbpOrZbkb] in {
def : PatGprGpr<rotl, ROL>;
def : PatGprGpr<rotr, ROR>;
def : PatGprGpr<shiftop<rotl>, ROL>;
def : PatGprGpr<shiftop<rotr>, ROR>;

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

let Predicates = [HasStdExtZbbOrZbpOrZbkb, IsRV64] in {
def : PatGprGpr<riscv_rolw, ROLW>;
def : PatGprGpr<riscv_rorw, RORW>;
def : PatGprGpr<shiftopw<riscv_rolw>, ROLW>;
def : PatGprGpr<shiftopw<riscv_rorw>, RORW>;
def : PatGprImm<riscv_rorw, RORIW, uimm5>;
def : Pat<(riscv_rolw GPR:$rs1, uimm5:$rs2),
(RORIW GPR:$rs1, (ImmSubFrom32 uimm5:$rs2))>;
Expand Down
12 changes: 4 additions & 8 deletions llvm/test/CodeGen/RISCV/rotl-rotr.ll
Expand Up @@ -576,8 +576,7 @@ define signext i32 @rotl_32_mask_shared(i32 signext %a, i32 signext %b, i32 sign
;
; RV32ZBB-LABEL: rotl_32_mask_shared:
; RV32ZBB: # %bb.0:
; RV32ZBB-NEXT: andi a3, a2, 31
; RV32ZBB-NEXT: rol a0, a0, a3
; RV32ZBB-NEXT: rol a0, a0, a2
; RV32ZBB-NEXT: sll a1, a1, a2
; RV32ZBB-NEXT: add a0, a0, a1
; RV32ZBB-NEXT: ret
Expand Down Expand Up @@ -695,8 +694,7 @@ define signext i64 @rotl_64_mask_shared(i64 signext %a, i64 signext %b, i64 sign
;
; RV64ZBB-LABEL: rotl_64_mask_shared:
; RV64ZBB: # %bb.0:
; RV64ZBB-NEXT: andi a3, a2, 63
; RV64ZBB-NEXT: rol a0, a0, a3
; RV64ZBB-NEXT: rol a0, a0, a2
; RV64ZBB-NEXT: sll a1, a1, a2
; RV64ZBB-NEXT: add a0, a0, a1
; RV64ZBB-NEXT: ret
Expand Down Expand Up @@ -731,8 +729,7 @@ define signext i32 @rotr_32_mask_shared(i32 signext %a, i32 signext %b, i32 sign
;
; RV32ZBB-LABEL: rotr_32_mask_shared:
; RV32ZBB: # %bb.0:
; RV32ZBB-NEXT: andi a3, a2, 31
; RV32ZBB-NEXT: ror a0, a0, a3
; RV32ZBB-NEXT: ror a0, a0, a2
; RV32ZBB-NEXT: sll a1, a1, a2
; RV32ZBB-NEXT: add a0, a0, a1
; RV32ZBB-NEXT: ret
Expand Down Expand Up @@ -848,8 +845,7 @@ define signext i64 @rotr_64_mask_shared(i64 signext %a, i64 signext %b, i64 sign
;
; RV64ZBB-LABEL: rotr_64_mask_shared:
; RV64ZBB: # %bb.0:
; RV64ZBB-NEXT: andi a3, a2, 63
; RV64ZBB-NEXT: ror a0, a0, a3
; RV64ZBB-NEXT: ror a0, a0, a2
; RV64ZBB-NEXT: sll a1, a1, a2
; RV64ZBB-NEXT: add a0, a0, a1
; RV64ZBB-NEXT: ret
Expand Down

0 comments on commit 415b9f5

Please sign in to comment.