From 4b452952fed75b87c6768bfc1f558d312c645b02 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Wed, 11 Dec 2019 12:45:54 -0800 Subject: [PATCH] [LegalizeTypes] In SoftenFloatRes_FP_EXTEND, move the check for input already being promoted above the check for fp16 converting to something other than fp32. The fp16 to larger than fp32 inserts an extend that need to re-legalized if fp16 is promoted. But if we check for fp16 promotion first, then we can avoid emiting the fp_extend all together. --- llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp index 686bdbe..4bea871 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp @@ -466,6 +466,14 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_FP_EXTEND(SDNode *N) { SDValue Chain = IsStrict ? N->getOperand(0) : SDValue(); + if (getTypeAction(Op.getValueType()) == TargetLowering::TypePromoteFloat) { + Op = GetPromotedFloat(Op); + // If the promotion did the FP_EXTEND to the destination type for us, + // there's nothing left to do here. + if (Op.getValueType() == N->getValueType(0)) + return BitConvertToInteger(Op); + } + // There's only a libcall for f16 -> f32, so proceed in two stages. Also, it's // entirely possible for both f16 and f32 to be legal, so use the fully // hard-float FP_EXTEND rather than FP16_TO_FP. @@ -479,15 +487,6 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_FP_EXTEND(SDNode *N) { } } - if (getTypeAction(Op.getValueType()) == TargetLowering::TypePromoteFloat) { - Op = GetPromotedFloat(Op); - // If the promotion did the FP_EXTEND to the destination type for us, - // there's nothing left to do here. - if (Op.getValueType() == N->getValueType(0)) { - return BitConvertToInteger(Op); - } - } - RTLIB::Libcall LC = RTLIB::getFPEXT(Op.getValueType(), N->getValueType(0)); assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_EXTEND!"); TargetLowering::MakeLibCallOptions CallOptions; -- 2.7.4