[LegalizeTypes] In SoftenFloatRes_FP_EXTEND, move the check for input already being...
authorCraig Topper <craig.topper@intel.com>
Wed, 11 Dec 2019 20:45:54 +0000 (12:45 -0800)
committerCraig Topper <craig.topper@intel.com>
Wed, 11 Dec 2019 20:48:08 +0000 (12:48 -0800)
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

index 686bdbe..4bea871 100644 (file)
@@ -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;