[llvm] r345262 - [RISCV] Use PatFrags for variable shift patterns

Alex Bradbury via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 25 05:45:21 PDT 2018


Author: asb
Date: Thu Oct 25 05:45:20 2018
New Revision: 345262

URL: http://llvm.org/viewvc/llvm-project?rev=345262&view=rev
Log:
[RISCV] Use PatFrags for variable shift patterns

This follows SystemZ and I think is cleaner vs the multiclass.

Modified:
    llvm/trunk/lib/Target/RISCV/RISCVInstrInfo.td

Modified: llvm/trunk/lib/Target/RISCV/RISCVInstrInfo.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/RISCV/RISCVInstrInfo.td?rev=345262&r1=345261&r2=345262&view=diff
==============================================================================
--- llvm/trunk/lib/Target/RISCV/RISCVInstrInfo.td (original)
+++ llvm/trunk/lib/Target/RISCV/RISCVInstrInfo.td Thu Oct 25 05:45:20 2018
@@ -206,7 +206,7 @@ def ixlenimm : Operand<XLenVT> {
 def simm32     : ImmLeaf<XLenVT, [{return isInt<32>(Imm);}]>;
 def simm32hi20 : ImmLeaf<XLenVT, [{return isShiftedInt<20, 12>(Imm);}]>;
 // A mask value that won't affect significant shift bits.
-def immshiftxlen : ImmLeaf<XLenVT, [{
+def immbottomxlenset : ImmLeaf<XLenVT, [{
   if (Subtarget->is64Bit())
     return countTrailingOnes<uint64_t>(Imm) >= 6;
   return countTrailingOnes<uint64_t>(Imm) >= 5;
@@ -660,15 +660,14 @@ def : PatGprUimmLog2XLen<sra, SRAI>;
 // typically introduced when the legalizer promotes the shift amount and
 // zero-extends it). For RISC-V, the mask is unnecessary as shifts in the base
 // ISA only read the least significant 5 bits (RV32I) or 6 bits (RV64I).
-multiclass VarShiftXLenPat<PatFrag ShiftOp, RVInst Inst> {
-  def : Pat<(ShiftOp GPR:$rs1, GPR:$rs2), (Inst GPR:$rs1, GPR:$rs2)>;
-  def : Pat<(ShiftOp GPR:$rs1, (and GPR:$rs2, immshiftxlen)),
-            (Inst GPR:$rs1, GPR:$rs2)>;
-}
-
-defm : VarShiftXLenPat<shl, SLL>;
-defm : VarShiftXLenPat<srl, SRL>;
-defm : VarShiftXLenPat<sra, SRA>;
+class shiftop<SDPatternOperator operator>
+    : PatFrags<(ops node:$val, node:$count),
+               [(operator node:$val, node:$count),
+                (operator node:$val, (and node:$count, immbottomxlenset))]>;
+
+def : PatGprGpr<shiftop<shl>, SLL>;
+def : PatGprGpr<shiftop<srl>, SRL>;
+def : PatGprGpr<shiftop<sra>, SRA>;
 
 /// FrameIndex calculations
 




More information about the llvm-commits mailing list