Skip to content

Commit

Permalink
[RISCV] Only enable combineROTR_ROTL_RORW_ROLW with Zbp.
Browse files Browse the repository at this point in the history
I think the immediate values we check for on the GREV nodes already
protect this, but better to be explicit.
  • Loading branch information
topperc committed Feb 28, 2022
1 parent 89080b8 commit e83db8c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Expand Up @@ -1031,8 +1031,10 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
setTargetDAGCombine(ISD::AND);
setTargetDAGCombine(ISD::OR);
setTargetDAGCombine(ISD::XOR);
setTargetDAGCombine(ISD::ROTL);
setTargetDAGCombine(ISD::ROTR);
if (Subtarget.hasStdExtZbp()) {
setTargetDAGCombine(ISD::ROTL);
setTargetDAGCombine(ISD::ROTR);
}
setTargetDAGCombine(ISD::ANY_EXTEND);
setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN);
if (Subtarget.hasStdExtZfh())
Expand Down Expand Up @@ -7305,7 +7307,8 @@ static SDValue transformAddShlImm(SDNode *N, SelectionDAG &DAG,
// ROTL ((GREV x, 24), 16) -> (GREVI x, 8)
// RORW ((GREVW x, 24), 16) -> (GREVIW x, 8)
// ROLW ((GREVW x, 24), 16) -> (GREVIW x, 8)
static SDValue combineROTR_ROTL_RORW_ROLW(SDNode *N, SelectionDAG &DAG) {
static SDValue combineROTR_ROTL_RORW_ROLW(SDNode *N, SelectionDAG &DAG,
const RISCVSubtarget &Subtarget) {
assert((N->getOpcode() == ISD::ROTR || N->getOpcode() == ISD::ROTL ||
N->getOpcode() == RISCVISD::RORW ||
N->getOpcode() == RISCVISD::ROLW) &&
Expand All @@ -7314,6 +7317,9 @@ static SDValue combineROTR_ROTL_RORW_ROLW(SDNode *N, SelectionDAG &DAG) {
SDLoc DL(N);
unsigned Opc;

if (!Subtarget.hasStdExtZbp())
return SDValue();

if ((N->getOpcode() == ISD::ROTR || N->getOpcode() == ISD::ROTL) &&
Src.getOpcode() == RISCVISD::GREV)
Opc = RISCVISD::GREV;
Expand Down Expand Up @@ -8081,7 +8087,7 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
return SDValue(N, 0);
}

return combineROTR_ROTL_RORW_ROLW(N, DAG);
return combineROTR_ROTL_RORW_ROLW(N, DAG, Subtarget);
}
case RISCVISD::CLZW:
case RISCVISD::CTZW: {
Expand Down

0 comments on commit e83db8c

Please sign in to comment.