diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp @@ -2609,9 +2609,9 @@ case ISD::CTTZ: ExpandIntRes_CTTZ(N, Lo, Hi); break; case ISD::GET_ROUNDING:ExpandIntRes_GET_ROUNDING(N, Lo, Hi); break; case ISD::STRICT_FP_TO_SINT: - case ISD::FP_TO_SINT: ExpandIntRes_FP_TO_SINT(N, Lo, Hi); break; + case ISD::FP_TO_SINT: case ISD::STRICT_FP_TO_UINT: - case ISD::FP_TO_UINT: ExpandIntRes_FP_TO_UINT(N, Lo, Hi); break; + case ISD::FP_TO_UINT: ExpandIntRes_FP_TO_XINT(N, Lo, Hi); break; case ISD::FP_TO_SINT_SAT: case ISD::FP_TO_UINT_SAT: ExpandIntRes_FP_TO_XINT_SAT(N, Lo, Hi); break; case ISD::STRICT_LROUND: @@ -3699,11 +3699,13 @@ return DAG.getNode(ISD::FP_EXTEND, DL, VT, Op); } -void DAGTypeLegalizer::ExpandIntRes_FP_TO_SINT(SDNode *N, SDValue &Lo, +void DAGTypeLegalizer::ExpandIntRes_FP_TO_XINT(SDNode *N, SDValue &Lo, SDValue &Hi) { SDLoc dl(N); EVT VT = N->getValueType(0); + bool IsSigned = N->getOpcode() == ISD::FP_TO_SINT || + N->getOpcode() == ISD::STRICT_FP_TO_SINT; bool IsStrict = N->isStrictFPOpcode(); SDValue Chain = IsStrict ? N->getOperand(0) : SDValue(); SDValue Op = N->getOperand(IsStrict ? 1 : 0); @@ -3716,7 +3718,7 @@ Op = GetSoftPromotedHalf(Op); Op = DAG.getNode(OFPVT == MVT::f16 ? ISD::FP16_TO_FP : ISD::BF16_TO_FP, dl, NFPVT, Op); - Op = DAG.getNode(ISD::FP_TO_SINT, dl, VT, Op); + Op = DAG.getNode(IsSigned ? ISD::FP_TO_SINT : ISD::FP_TO_UINT, dl, VT, Op); SplitInteger(Op, Lo, Hi); return; } @@ -3726,8 +3728,9 @@ Op = fpExtendHelper(Op, Chain, IsStrict, MVT::f32, dl, DAG); } - RTLIB::Libcall LC = RTLIB::getFPTOSINT(Op.getValueType(), VT); - assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected fp-to-sint conversion!"); + RTLIB::Libcall LC = IsSigned ? RTLIB::getFPTOSINT(Op.getValueType(), VT) + : RTLIB::getFPTOUINT(Op.getValueType(), VT); + assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected fp-to-xint conversion!"); TargetLowering::MakeLibCallOptions CallOptions; CallOptions.setSExt(true); std::pair Tmp = TLI.makeLibCall(DAG, LC, VT, Op, @@ -3738,44 +3741,6 @@ ReplaceValueWith(SDValue(N, 1), Tmp.second); } -void DAGTypeLegalizer::ExpandIntRes_FP_TO_UINT(SDNode *N, SDValue &Lo, - SDValue &Hi) { - SDLoc dl(N); - EVT VT = N->getValueType(0); - - bool IsStrict = N->isStrictFPOpcode(); - SDValue Chain = IsStrict ? N->getOperand(0) : SDValue(); - SDValue Op = N->getOperand(IsStrict ? 1 : 0); - if (getTypeAction(Op.getValueType()) == TargetLowering::TypePromoteFloat) - Op = GetPromotedFloat(Op); - - if (getTypeAction(Op.getValueType()) == TargetLowering::TypeSoftPromoteHalf) { - EVT OFPVT = Op.getValueType(); - EVT NFPVT = TLI.getTypeToTransformTo(*DAG.getContext(), OFPVT); - Op = GetSoftPromotedHalf(Op); - Op = DAG.getNode(OFPVT == MVT::f16 ? ISD::FP16_TO_FP : ISD::BF16_TO_FP, dl, - NFPVT, Op); - Op = DAG.getNode(ISD::FP_TO_UINT, dl, VT, Op); - SplitInteger(Op, Lo, Hi); - return; - } - - if (Op.getValueType() == MVT::bf16) { - // Extend to f32 as there is no bf16 libcall. - Op = fpExtendHelper(Op, Chain, IsStrict, MVT::f32, dl, DAG); - } - - RTLIB::Libcall LC = RTLIB::getFPTOUINT(Op.getValueType(), VT); - assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected fp-to-uint conversion!"); - TargetLowering::MakeLibCallOptions CallOptions; - std::pair Tmp = TLI.makeLibCall(DAG, LC, VT, Op, - CallOptions, dl, Chain); - SplitInteger(Tmp.first, Lo, Hi); - - if (IsStrict) - ReplaceValueWith(SDValue(N, 1), Tmp.second); -} - void DAGTypeLegalizer::ExpandIntRes_FP_TO_XINT_SAT(SDNode *N, SDValue &Lo, SDValue &Hi) { SDValue Res = TLI.expandFP_TO_INT_SAT(N, DAG); diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h @@ -443,8 +443,7 @@ void ExpandIntRes_TRUNCATE (SDNode *N, SDValue &Lo, SDValue &Hi); void ExpandIntRes_ZERO_EXTEND (SDNode *N, SDValue &Lo, SDValue &Hi); void ExpandIntRes_GET_ROUNDING (SDNode *N, SDValue &Lo, SDValue &Hi); - void ExpandIntRes_FP_TO_SINT (SDNode *N, SDValue &Lo, SDValue &Hi); - void ExpandIntRes_FP_TO_UINT (SDNode *N, SDValue &Lo, SDValue &Hi); + void ExpandIntRes_FP_TO_XINT (SDNode *N, SDValue &Lo, SDValue &Hi); void ExpandIntRes_FP_TO_XINT_SAT (SDNode *N, SDValue &Lo, SDValue &Hi); void ExpandIntRes_XROUND_XRINT (SDNode *N, SDValue &Lo, SDValue &Hi);