@@ -433,6 +433,8 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
433433 if (Subtarget.hasStdExtP() ||
434434 (Subtarget.hasVendorXCValu() && !Subtarget.is64Bit())) {
435435 setOperationAction(ISD::ABS, XLenVT, Legal);
436+ if (Subtarget.is64Bit())
437+ setOperationAction(ISD::ABS, MVT::i32, Custom);
436438 } else if (Subtarget.hasShortForwardBranchOpt()) {
437439 // We can use PseudoCCSUB to implement ABS.
438440 setOperationAction(ISD::ABS, XLenVT, Legal);
@@ -14816,8 +14818,16 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
1481614818 assert(N->getValueType(0) == MVT::i32 && Subtarget.is64Bit() &&
1481714819 "Unexpected custom legalisation");
1481814820
14821+ if (Subtarget.hasStdExtP()) {
14822+ SDValue Src =
14823+ DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, N->getOperand(0));
14824+ SDValue Abs = DAG.getNode(RISCVISD::ABSW, DL, MVT::i64, Src);
14825+ Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, Abs));
14826+ return;
14827+ }
14828+
1481914829 if (Subtarget.hasStdExtZbb()) {
14820- // Emit a special ABSW node that will be expanded to NEGW+MAX at isel.
14830+ // Emit a special node that will be expanded to NEGW+MAX at isel.
1482114831 // This allows us to remember that the result is sign extended. Expanding
1482214832 // to NEGW+MAX here requires a Freeze which breaks ComputeNumSignBits.
1482314833 SDValue Src = DAG.getNode(ISD::SIGN_EXTEND, DL, MVT::i64,
@@ -20290,6 +20300,7 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
2029020300
2029120301 break;
2029220302 }
20303+ case RISCVISD::ABSW:
2029320304 case RISCVISD::CLZW:
2029420305 case RISCVISD::CTZW: {
2029520306 // Only the lower 32 bits of the first operand are read
@@ -21862,6 +21873,7 @@ unsigned RISCVTargetLowering::ComputeNumSignBitsForTargetNode(
2186221873 case RISCVISD::REMUW:
2186321874 case RISCVISD::ROLW:
2186421875 case RISCVISD::RORW:
21876+ case RISCVISD::ABSW:
2186521877 case RISCVISD::FCVT_W_RV64:
2186621878 case RISCVISD::FCVT_WU_RV64:
2186721879 case RISCVISD::STRICT_FCVT_W_RV64:
0 commit comments