Skip to content

Commit 8c05515

Browse files
authored
[LegalizeIntegerTypes] Simplify ExpandIntRes_FP_TO_XINT when operand needs to be SoftPromoted. (#107634)
Create an FP_EXTEND instead of handling the soft promote directly. This FP_EXTEND will be visited and soft promoted itself. This removes a zero extend from the generated code when the f32 type is itself softened. Previously we softened it as an fp16_to_fp which sees the operand as an integer type so we extend it. When we soften the result as an fp_extend we see the source as f16 and don't extend. It only becomes an integer inside call lowering not by type legalization. If this extend is really necessary, then we have an issue when an f16->f32 fp_extend exists in the source and f32 needs to be softened. This simplifies part of #102503.
1 parent bd8d432 commit 8c05515

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3952,19 +3952,9 @@ void DAGTypeLegalizer::ExpandIntRes_FP_TO_XINT(SDNode *N, SDValue &Lo,
39523952
if (getTypeAction(Op.getValueType()) == TargetLowering::TypePromoteFloat)
39533953
Op = GetPromotedFloat(Op);
39543954

3955-
if (getTypeAction(Op.getValueType()) == TargetLowering::TypeSoftPromoteHalf) {
3956-
EVT OFPVT = Op.getValueType();
3957-
EVT NFPVT = TLI.getTypeToTransformTo(*DAG.getContext(), OFPVT);
3958-
Op = GetSoftPromotedHalf(Op);
3959-
Op = DAG.getNode(OFPVT == MVT::f16 ? ISD::FP16_TO_FP : ISD::BF16_TO_FP, dl,
3960-
NFPVT, Op);
3961-
Op = DAG.getNode(IsSigned ? ISD::FP_TO_SINT : ISD::FP_TO_UINT, dl, VT, Op);
3962-
SplitInteger(Op, Lo, Hi);
3963-
return;
3964-
}
3965-
3966-
if (Op.getValueType() == MVT::bf16) {
3967-
// Extend to f32 as there is no bf16 libcall.
3955+
// If the input is bf16 or needs to be soft promoted, extend to f32.
3956+
if (getTypeAction(Op.getValueType()) == TargetLowering::TypeSoftPromoteHalf ||
3957+
Op.getValueType() == MVT::bf16) {
39683958
Op = fpExtendHelper(Op, Chain, IsStrict, MVT::f32, dl, DAG);
39693959
}
39703960

llvm/test/CodeGen/RISCV/half-convert.ll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,8 +2033,6 @@ define i64 @fcvt_l_h(half %a) nounwind {
20332033
; RV32I: # %bb.0:
20342034
; RV32I-NEXT: addi sp, sp, -16
20352035
; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
2036-
; RV32I-NEXT: slli a0, a0, 16
2037-
; RV32I-NEXT: srli a0, a0, 16
20382036
; RV32I-NEXT: call __extendhfsf2
20392037
; RV32I-NEXT: call __fixsfdi
20402038
; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
@@ -2792,8 +2790,6 @@ define i64 @fcvt_lu_h(half %a) nounwind {
27922790
; RV32I: # %bb.0:
27932791
; RV32I-NEXT: addi sp, sp, -16
27942792
; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
2795-
; RV32I-NEXT: slli a0, a0, 16
2796-
; RV32I-NEXT: srli a0, a0, 16
27972793
; RV32I-NEXT: call __extendhfsf2
27982794
; RV32I-NEXT: call __fixunssfdi
27992795
; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload

0 commit comments

Comments
 (0)