@@ -1489,6 +1489,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
1489
1489
ISD::INTRINSIC_WO_CHAIN, ISD::ADD, ISD::SUB, ISD::MUL,
1490
1490
ISD::AND, ISD::OR, ISD::XOR, ISD::SETCC, ISD::SELECT});
1491
1491
setTargetDAGCombine(ISD::SRA);
1492
+ setTargetDAGCombine(ISD::SIGN_EXTEND_INREG);
1492
1493
1493
1494
if (Subtarget.hasStdExtFOrZfinx())
1494
1495
setTargetDAGCombine({ISD::FADD, ISD::FMAXNUM, ISD::FMINNUM, ISD::FMUL});
@@ -1502,8 +1503,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
1502
1503
1503
1504
if (Subtarget.hasStdExtZbkb())
1504
1505
setTargetDAGCombine(ISD::BITREVERSE);
1505
- if (Subtarget.hasStdExtZfhminOrZhinxmin())
1506
- setTargetDAGCombine(ISD::SIGN_EXTEND_INREG);
1506
+
1507
1507
if (Subtarget.hasStdExtFOrZfinx())
1508
1508
setTargetDAGCombine({ISD::ZERO_EXTEND, ISD::FP_TO_SINT, ISD::FP_TO_UINT,
1509
1509
ISD::FP_TO_SINT_SAT, ISD::FP_TO_UINT_SAT});
@@ -14456,15 +14456,23 @@ performSIGN_EXTEND_INREGCombine(SDNode *N, SelectionDAG &DAG,
14456
14456
const RISCVSubtarget &Subtarget) {
14457
14457
SDValue Src = N->getOperand(0);
14458
14458
EVT VT = N->getValueType(0);
14459
+ EVT SrcVT = cast<VTSDNode>(N->getOperand(1))->getVT();
14460
+ unsigned Opc = Src.getOpcode();
14459
14461
14460
14462
// Fold (sext_inreg (fmv_x_anyexth X), i16) -> (fmv_x_signexth X)
14461
14463
// Don't do this with Zhinx. We need to explicitly sign extend the GPR.
14462
- if (Src.getOpcode() == RISCVISD::FMV_X_ANYEXTH &&
14463
- cast<VTSDNode>(N->getOperand(1))->getVT().bitsGE(MVT::i16) &&
14464
+ if (Opc == RISCVISD::FMV_X_ANYEXTH && SrcVT.bitsGE(MVT::i16) &&
14464
14465
Subtarget.hasStdExtZfhmin())
14465
14466
return DAG.getNode(RISCVISD::FMV_X_SIGNEXTH, SDLoc(N), VT,
14466
14467
Src.getOperand(0));
14467
14468
14469
+ // Fold (sext_inreg (shl X, Y), i32) -> (sllw X, Y) iff Y u< 32
14470
+ if (Opc == ISD::SHL && Subtarget.is64Bit() && SrcVT == MVT::i32 &&
14471
+ VT == MVT::i64 && !isa<ConstantSDNode>(Src.getOperand(1)) &&
14472
+ DAG.computeKnownBits(Src.getOperand(1)).countMaxActiveBits() <= 5)
14473
+ return DAG.getNode(RISCVISD::SLLW, SDLoc(N), VT, Src.getOperand(0),
14474
+ Src.getOperand(1));
14475
+
14468
14476
return SDValue();
14469
14477
}
14470
14478
0 commit comments