diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp --- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp @@ -141,20 +141,6 @@ return; } } - // Match (srl (shl val, 32), imm). - if (Op0->getOpcode() == ISD::SHL && - isa(Op0->getOperand(1)) && - isa(Node->getOperand(1))) { - uint64_t ShlAmt = Op0->getConstantOperandVal(1); - uint64_t SrlAmt = Node->getConstantOperandVal(1); - if (ShlAmt == 32 && SrlAmt > 32) { - SDValue SrlAmtSub32Val = - CurDAG->getTargetConstant(SrlAmt - 32, SDLoc(Node), XLenVT); - CurDAG->SelectNodeTo(Node, RISCV::SRLIW, XLenVT, Op0->getOperand(0), - SrlAmtSub32Val); - return; - } - } break; } case RISCVISD::READ_CYCLE_WIDE: diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td @@ -290,6 +290,10 @@ return countTrailingOnes(Imm) >= 6; return countTrailingOnes(Imm) >= 5; }]>; +// A 6-bit constant greater than 32. +def uimm6gt32 : ImmLeaf(Imm) && Imm > 32; +}]>; // Addressing modes. // Necessary because a frameindex can't be matched directly in a pattern. @@ -316,6 +320,12 @@ N->getValueType(0)); }]>; +// Return an immediate value minus 32. +def ImmSub32 : SDNodeXFormgetTargetConstant(N->getSExtValue() - 32, SDLoc(N), + N->getValueType(0)); +}]>; + //===----------------------------------------------------------------------===// // Instruction Formats //===----------------------------------------------------------------------===// @@ -1128,6 +1138,8 @@ (SLLIW GPR:$rs1, uimm5:$shamt)>; // (srl (zexti32 ...), uimm5:$shamt) is matched with custom code due to the // need to undo manipulation of the mask value performed by DAGCombine. +def : Pat<(srl (shl GPR:$rs1, (i64 32)), uimm6gt32:$shamt), + (SRLIW GPR:$rs1, (ImmSub32 uimm6gt32:$shamt))>; def : Pat<(sra (sext_inreg GPR:$rs1, i32), uimm5:$shamt), (SRAIW GPR:$rs1, uimm5:$shamt)>; diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoB.td b/llvm/lib/Target/RISCV/RISCVInstrInfoB.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoB.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoB.td @@ -40,12 +40,6 @@ }]; } -// Return an immediate value minus 32. -def ImmSub32 : SDNodeXFormgetTargetConstant(N->getSExtValue() - 32, SDLoc(N), - N->getValueType(0)); -}]>; - //===----------------------------------------------------------------------===// // Instruction class templates //===----------------------------------------------------------------------===// @@ -1036,9 +1030,9 @@ (FSRW GPR:$rs1, GPR:$rs2, GPR:$rs3)>; def : Pat<(sext_inreg (fshr (assertsexti32 GPR:$rs1), (shl (assertsexti32 GPR:$rs2), (i64 32)), - uimmlog2xlen:$shamt), + uimm6gt32:$shamt), i32), - (FSRIW GPR:$rs1, GPR:$rs2, (ImmSub32 uimm5:$shamt))>; + (FSRIW GPR:$rs1, GPR:$rs2, (ImmSub32 uimm6gt32:$shamt))>; } // Predicates = [HasStdExtZbt, IsRV64] let Predicates = [HasStdExtZbb, IsRV64] in {