From d4ba11ae3261bb0dc805d33fbe15e9591e926a33 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sat, 16 Nov 2019 19:27:43 -0800 Subject: [PATCH] [LegalizeTypes] Merge ExpandIntRes_LLROUND and ExpandIntRes_LLRINT into one function that handles both. NFC These too functions are were the same except for which libcall gets emitted. Just merge them into one. This is prep work for some other work including strict fp support. --- .../SelectionDAG/LegalizeIntegerTypes.cpp | 72 ++++++++----------- llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h | 3 +- 2 files changed, 31 insertions(+), 44 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp index 28031e757dac..295a32326f70 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp @@ -1698,8 +1698,8 @@ void DAGTypeLegalizer::ExpandIntegerResult(SDNode *N, unsigned ResNo) { case ISD::FLT_ROUNDS_: ExpandIntRes_FLT_ROUNDS(N, Lo, Hi); break; case ISD::FP_TO_SINT: ExpandIntRes_FP_TO_SINT(N, Lo, Hi); break; case ISD::FP_TO_UINT: ExpandIntRes_FP_TO_UINT(N, Lo, Hi); break; - case ISD::LLROUND: ExpandIntRes_LLROUND(N, Lo, Hi); break; - case ISD::LLRINT: ExpandIntRes_LLRINT(N, Lo, Hi); break; + case ISD::LLROUND: + case ISD::LLRINT: ExpandIntRes_LLROUND_LLRINT(N, Lo, Hi); break; case ISD::LOAD: ExpandIntRes_LOAD(cast(N), Lo, Hi); break; case ISD::MUL: ExpandIntRes_MUL(N, Lo, Hi); break; case ISD::READCYCLECOUNTER: ExpandIntRes_READCYCLECOUNTER(N, Lo, Hi); break; @@ -2584,49 +2584,37 @@ void DAGTypeLegalizer::ExpandIntRes_FP_TO_UINT(SDNode *N, SDValue &Lo, Lo, Hi); } -void DAGTypeLegalizer::ExpandIntRes_LLROUND(SDNode *N, SDValue &Lo, - SDValue &Hi) { - RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; +void DAGTypeLegalizer::ExpandIntRes_LLROUND_LLRINT(SDNode *N, SDValue &Lo, + SDValue &Hi) { EVT VT = N->getOperand(0).getValueType().getSimpleVT().SimpleTy; - if (VT == MVT::f32) - LC = RTLIB::LLROUND_F32; - else if (VT == MVT::f64) - LC = RTLIB::LLROUND_F64; - else if (VT == MVT::f80) - LC = RTLIB::LLROUND_F80; - else if (VT == MVT::f128) - LC = RTLIB::LLROUND_F128; - else if (VT == MVT::ppcf128) - LC = RTLIB::LLROUND_PPCF128; - assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected llround input type!"); - SDValue Op = N->getOperand(0); - if (getTypeAction(Op.getValueType()) == TargetLowering::TypePromoteFloat) - Op = GetPromotedFloat(Op); - - SDLoc dl(N); - EVT RetVT = N->getValueType(0); - TargetLowering::MakeLibCallOptions CallOptions; - CallOptions.setSExt(true); - SplitInteger(TLI.makeLibCall(DAG, LC, RetVT, Op, CallOptions, dl).first, - Lo, Hi); -} - -void DAGTypeLegalizer::ExpandIntRes_LLRINT(SDNode *N, SDValue &Lo, - SDValue &Hi) { RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; - EVT VT = N->getOperand(0).getValueType().getSimpleVT().SimpleTy; - if (VT == MVT::f32) - LC = RTLIB::LLRINT_F32; - else if (VT == MVT::f64) - LC = RTLIB::LLRINT_F64; - else if (VT == MVT::f80) - LC = RTLIB::LLRINT_F80; - else if (VT == MVT::f128) - LC = RTLIB::LLRINT_F128; - else if (VT == MVT::ppcf128) - LC = RTLIB::LLRINT_PPCF128; - assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected llrint input type!"); + if (N->getOpcode() == ISD::LLROUND) { + if (VT == MVT::f32) + LC = RTLIB::LLROUND_F32; + else if (VT == MVT::f64) + LC = RTLIB::LLROUND_F64; + else if (VT == MVT::f80) + LC = RTLIB::LLROUND_F80; + else if (VT == MVT::f128) + LC = RTLIB::LLROUND_F128; + else if (VT == MVT::ppcf128) + LC = RTLIB::LLROUND_PPCF128; + assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected llround input type!"); + } else if (N->getOpcode() == ISD::LLRINT) { + if (VT == MVT::f32) + LC = RTLIB::LLRINT_F32; + else if (VT == MVT::f64) + LC = RTLIB::LLRINT_F64; + else if (VT == MVT::f80) + LC = RTLIB::LLRINT_F80; + else if (VT == MVT::f128) + LC = RTLIB::LLRINT_F128; + else if (VT == MVT::ppcf128) + LC = RTLIB::LLRINT_PPCF128; + assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected llrint input type!"); + } else + llvm_unreachable("Unexpected opcode!"); SDValue Op = N->getOperand(0); if (getTypeAction(Op.getValueType()) == TargetLowering::TypePromoteFloat) diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h index 77216647efb9..da966ea55dc2 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h @@ -411,8 +411,7 @@ private: void ExpandIntRes_FLT_ROUNDS (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_LLROUND (SDNode *N, SDValue &Lo, SDValue &Hi); - void ExpandIntRes_LLRINT (SDNode *N, SDValue &Lo, SDValue &Hi); + void ExpandIntRes_LLROUND_LLRINT (SDNode *N, SDValue &Lo, SDValue &Hi); void ExpandIntRes_Logical (SDNode *N, SDValue &Lo, SDValue &Hi); void ExpandIntRes_ADDSUB (SDNode *N, SDValue &Lo, SDValue &Hi);