Skip to content

Commit 4b45295

Browse files
committed
[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.
1 parent daacf57 commit 4b45295

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,14 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_FP_EXTEND(SDNode *N) {
466466

467467
SDValue Chain = IsStrict ? N->getOperand(0) : SDValue();
468468

469+
if (getTypeAction(Op.getValueType()) == TargetLowering::TypePromoteFloat) {
470+
Op = GetPromotedFloat(Op);
471+
// If the promotion did the FP_EXTEND to the destination type for us,
472+
// there's nothing left to do here.
473+
if (Op.getValueType() == N->getValueType(0))
474+
return BitConvertToInteger(Op);
475+
}
476+
469477
// There's only a libcall for f16 -> f32, so proceed in two stages. Also, it's
470478
// entirely possible for both f16 and f32 to be legal, so use the fully
471479
// hard-float FP_EXTEND rather than FP16_TO_FP.
@@ -479,15 +487,6 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_FP_EXTEND(SDNode *N) {
479487
}
480488
}
481489

482-
if (getTypeAction(Op.getValueType()) == TargetLowering::TypePromoteFloat) {
483-
Op = GetPromotedFloat(Op);
484-
// If the promotion did the FP_EXTEND to the destination type for us,
485-
// there's nothing left to do here.
486-
if (Op.getValueType() == N->getValueType(0)) {
487-
return BitConvertToInteger(Op);
488-
}
489-
}
490-
491490
RTLIB::Libcall LC = RTLIB::getFPEXT(Op.getValueType(), N->getValueType(0));
492491
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_EXTEND!");
493492
TargetLowering::MakeLibCallOptions CallOptions;

0 commit comments

Comments
 (0)