[llvm] 8c05515 - [LegalizeIntegerTypes] Simplify ExpandIntRes_FP_TO_XINT when operand needs to be SoftPromoted. (#107634)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 12 08:28:10 PDT 2024
Author: Craig Topper
Date: 2024-09-12T08:28:06-07:00
New Revision: 8c0551503219b8e1da7dd6c24de1d9e79cb7cae6
URL: https://github.com/llvm/llvm-project/commit/8c0551503219b8e1da7dd6c24de1d9e79cb7cae6
DIFF: https://github.com/llvm/llvm-project/commit/8c0551503219b8e1da7dd6c24de1d9e79cb7cae6.diff
LOG: [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.
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
llvm/test/CodeGen/RISCV/half-convert.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index 2fa9e46eae506a..c622b2abedeacf 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -3952,19 +3952,9 @@ void DAGTypeLegalizer::ExpandIntRes_FP_TO_XINT(SDNode *N, SDValue &Lo,
if (getTypeAction(Op.getValueType()) == TargetLowering::TypePromoteFloat)
Op = GetPromotedFloat(Op);
- if (getTypeAction(Op.getValueType()) == TargetLowering::TypeSoftPromoteHalf) {
- EVT OFPVT = Op.getValueType();
- EVT NFPVT = TLI.getTypeToTransformTo(*DAG.getContext(), OFPVT);
- Op = GetSoftPromotedHalf(Op);
- Op = DAG.getNode(OFPVT == MVT::f16 ? ISD::FP16_TO_FP : ISD::BF16_TO_FP, dl,
- NFPVT, Op);
- Op = DAG.getNode(IsSigned ? ISD::FP_TO_SINT : ISD::FP_TO_UINT, dl, VT, Op);
- SplitInteger(Op, Lo, Hi);
- return;
- }
-
- if (Op.getValueType() == MVT::bf16) {
- // Extend to f32 as there is no bf16 libcall.
+ // If the input is bf16 or needs to be soft promoted, extend to f32.
+ if (getTypeAction(Op.getValueType()) == TargetLowering::TypeSoftPromoteHalf ||
+ Op.getValueType() == MVT::bf16) {
Op = fpExtendHelper(Op, Chain, IsStrict, MVT::f32, dl, DAG);
}
diff --git a/llvm/test/CodeGen/RISCV/half-convert.ll b/llvm/test/CodeGen/RISCV/half-convert.ll
index 4c5097b0a53cc2..e5585661ce79a0 100644
--- a/llvm/test/CodeGen/RISCV/half-convert.ll
+++ b/llvm/test/CodeGen/RISCV/half-convert.ll
@@ -2033,8 +2033,6 @@ define i64 @fcvt_l_h(half %a) nounwind {
; RV32I: # %bb.0:
; RV32I-NEXT: addi sp, sp, -16
; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
-; RV32I-NEXT: slli a0, a0, 16
-; RV32I-NEXT: srli a0, a0, 16
; RV32I-NEXT: call __extendhfsf2
; RV32I-NEXT: call __fixsfdi
; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
@@ -2792,8 +2790,6 @@ define i64 @fcvt_lu_h(half %a) nounwind {
; RV32I: # %bb.0:
; RV32I-NEXT: addi sp, sp, -16
; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
-; RV32I-NEXT: slli a0, a0, 16
-; RV32I-NEXT: srli a0, a0, 16
; RV32I-NEXT: call __extendhfsf2
; RV32I-NEXT: call __fixunssfdi
; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
More information about the llvm-commits
mailing list