Skip to content

Commit 96861b7

Browse files
toppercLukacma
authored andcommitted
[RISCV] Remove shiftop/shiftopw PatFrags. NFC (llvm#164050)
Replace with PatGprShiftMaskXLen/PatGprShiftMask32 or using the ShiftMaskXLen/ShiftMask32 ComplexPattern direclty in patterns. This avoids various casts that were need to make a ComplexPattern work inside of a PatFrag.
1 parent 89d8d98 commit 96861b7

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,16 +1511,16 @@ def GIShiftMask32 :
15111511
GIComplexOperandMatcher<s64, "selectShiftMask32">,
15121512
GIComplexPatternEquiv<shiftMask32>;
15131513

1514-
class shiftop<SDPatternOperator operator>
1515-
: PatFrag<(ops node:$val, node:$count),
1516-
(operator node:$val, (XLenVT (shiftMaskXLen node:$count)))>;
1517-
class shiftopw<SDPatternOperator operator>
1518-
: PatFrag<(ops node:$val, node:$count),
1519-
(operator node:$val, (i64 (shiftMask32 node:$count)))>;
1514+
class PatGprShiftMaskXLen<SDPatternOperator OpNode, RVInst Inst>
1515+
: Pat<(OpNode GPR:$rs1, shiftMaskXLen:$rs2),
1516+
(Inst GPR:$rs1, shiftMaskXLen:$rs2)>;
1517+
class PatGprShiftMask32<SDPatternOperator OpNode, RVInst Inst>
1518+
: Pat<(OpNode GPR:$rs1, shiftMask32:$rs2),
1519+
(Inst GPR:$rs1, shiftMask32:$rs2)>;
15201520

1521-
def : PatGprGpr<shiftop<shl>, SLL>;
1522-
def : PatGprGpr<shiftop<srl>, SRL>;
1523-
def : PatGprGpr<shiftop<sra>, SRA>;
1521+
def : PatGprShiftMaskXLen<shl, SLL>;
1522+
def : PatGprShiftMaskXLen<srl, SRL>;
1523+
def : PatGprShiftMaskXLen<sra, SRA>;
15241524

15251525
// This is a special case of the ADD instruction used to facilitate the use of a
15261526
// fourth operand to emit a relocation on a symbol relating to this instruction.
@@ -2203,9 +2203,9 @@ def : Pat<(sra (sext_inreg GPR:$rs1, i32), uimm5:$shamt),
22032203
def : Pat<(i64 (sra (shl GPR:$rs1, (i64 32)), uimm6gt32:$shamt)),
22042204
(SRAIW GPR:$rs1, (ImmSub32 uimm6gt32:$shamt))>;
22052205

2206-
def : PatGprGpr<shiftopw<riscv_sllw>, SLLW>;
2207-
def : PatGprGpr<shiftopw<riscv_srlw>, SRLW>;
2208-
def : PatGprGpr<shiftopw<riscv_sraw>, SRAW>;
2206+
def : PatGprShiftMask32<riscv_sllw, SLLW>;
2207+
def : PatGprShiftMask32<riscv_srlw, SRLW>;
2208+
def : PatGprShiftMask32<riscv_sraw, SRAW>;
22092209

22102210
// Select W instructions if only the lower 32 bits of the result are used.
22112211
def : PatGprGpr<binop_allwusers<add>, ADDW>;

llvm/lib/Target/RISCV/RISCVInstrInfoZb.td

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,8 @@ def : Pat<(XLenVT (xor GPR:$rs1, invLogicImm:$rs2)), (XNOR GPR:$rs1, invLogicImm
506506
} // Predicates = [HasStdExtZbbOrZbkb]
507507

508508
let Predicates = [HasStdExtZbbOrZbkb] in {
509-
def : PatGprGpr<shiftop<rotl>, ROL>;
510-
def : PatGprGpr<shiftop<rotr>, ROR>;
509+
def : PatGprShiftMaskXLen<rotl, ROL>;
510+
def : PatGprShiftMaskXLen<rotr, ROR>;
511511

512512
def : PatGprImm<rotr, RORI, uimmlog2xlen>;
513513
// There's no encoding for roli in the the 'B' extension as it can be
@@ -517,29 +517,29 @@ def : Pat<(XLenVT (rotl GPR:$rs1, uimmlog2xlen:$shamt)),
517517
} // Predicates = [HasStdExtZbbOrZbkb]
518518

519519
let Predicates = [HasStdExtZbbOrZbkb, IsRV64] in {
520-
def : PatGprGpr<shiftopw<riscv_rolw>, ROLW>;
521-
def : PatGprGpr<shiftopw<riscv_rorw>, RORW>;
520+
def : PatGprShiftMask32<riscv_rolw, ROLW>;
521+
def : PatGprShiftMask32<riscv_rorw, RORW>;
522522
def : PatGprImm<riscv_rorw, RORIW, uimm5>;
523523
def : Pat<(riscv_rolw GPR:$rs1, uimm5:$rs2),
524524
(RORIW GPR:$rs1, (ImmSubFrom32 uimm5:$rs2))>;
525525
} // Predicates = [HasStdExtZbbOrZbkb, IsRV64]
526526

527527
let Predicates = [HasStdExtZbs] in {
528-
def : Pat<(XLenVT (and (not (shiftop<shl> 1, (XLenVT GPR:$rs2))), GPR:$rs1)),
529-
(BCLR GPR:$rs1, GPR:$rs2)>;
528+
def : Pat<(XLenVT (and (not (shl 1, shiftMaskXLen:$rs2)), GPR:$rs1)),
529+
(BCLR GPR:$rs1, shiftMaskXLen:$rs2)>;
530530
def : Pat<(XLenVT (and (rotl -2, (XLenVT GPR:$rs2)), GPR:$rs1)),
531531
(BCLR GPR:$rs1, GPR:$rs2)>;
532-
def : Pat<(XLenVT (or (shiftop<shl> 1, (XLenVT GPR:$rs2)), GPR:$rs1)),
533-
(BSET GPR:$rs1, GPR:$rs2)>;
534-
def : Pat<(XLenVT (xor (shiftop<shl> 1, (XLenVT GPR:$rs2)), GPR:$rs1)),
535-
(BINV GPR:$rs1, GPR:$rs2)>;
536-
def : Pat<(XLenVT (and (shiftop<srl> GPR:$rs1, (XLenVT GPR:$rs2)), 1)),
537-
(BEXT GPR:$rs1, GPR:$rs2)>;
538-
539-
def : Pat<(XLenVT (shiftop<shl> 1, (XLenVT GPR:$rs2))),
540-
(BSET (XLenVT X0), GPR:$rs2)>;
541-
def : Pat<(XLenVT (not (shiftop<shl> -1, (XLenVT GPR:$rs2)))),
542-
(ADDI (XLenVT (BSET (XLenVT X0), GPR:$rs2)), -1)>;
532+
def : Pat<(XLenVT (or (shl 1, shiftMaskXLen:$rs2), GPR:$rs1)),
533+
(BSET GPR:$rs1, shiftMaskXLen:$rs2)>;
534+
def : Pat<(XLenVT (xor (shl 1, shiftMaskXLen:$rs2), GPR:$rs1)),
535+
(BINV GPR:$rs1, shiftMaskXLen:$rs2)>;
536+
def : Pat<(XLenVT (and (srl GPR:$rs1, shiftMaskXLen:$rs2), 1)),
537+
(BEXT GPR:$rs1, shiftMaskXLen:$rs2)>;
538+
539+
def : Pat<(XLenVT (shl 1, shiftMaskXLen:$rs2)),
540+
(BSET (XLenVT X0), shiftMaskXLen:$rs2)>;
541+
def : Pat<(XLenVT (not (shl -1, shiftMaskXLen:$rs2))),
542+
(ADDI (XLenVT (BSET (XLenVT X0), shiftMaskXLen:$rs2)), -1)>;
543543

544544
def : Pat<(XLenVT (and GPR:$rs1, BCLRMask:$mask)),
545545
(BCLRI GPR:$rs1, BCLRMask:$mask)>;

0 commit comments

Comments
 (0)