[PATCH] D157287: [LegalizeTypes][RISCV] Correct FP_TO_{S,U}INT expansion when bf16 isn't a legal type
Alex Bradbury via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 8 06:26:40 PDT 2023
asb updated this revision to Diff 548189.
asb added a comment.
Apologies for the noise, the previous versions had a bug in that they were checking the type of Op.getValueType after `Op = GetSoftPromotedHalf(Op)`. The patch now correctly gets the old FP VT before doing that call. This bug was caught by existing tests (I just hadn't seen that half-convert.ll failed) so no further test changes needed.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157287/new/
https://reviews.llvm.org/D157287
Files:
llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
llvm/test/CodeGen/RISCV/bfloat-convert.ll
Index: llvm/test/CodeGen/RISCV/bfloat-convert.ll
===================================================================
--- llvm/test/CodeGen/RISCV/bfloat-convert.ll
+++ llvm/test/CodeGen/RISCV/bfloat-convert.ll
@@ -431,9 +431,6 @@
}
declare i32 @llvm.fptoui.sat.i32.bf16(bfloat)
-; TODO: An f16 libcall is incorrectly produced for RV32ID in the following
-; test.
-
define i64 @fcvt_l_bf16(bfloat %a) nounwind {
; CHECK32ZFBFMIN-LABEL: fcvt_l_bf16:
; CHECK32ZFBFMIN: # %bb.0:
@@ -449,7 +446,9 @@
; RV32ID: # %bb.0:
; RV32ID-NEXT: addi sp, sp, -16
; RV32ID-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
-; RV32ID-NEXT: call __extendhfsf2 at plt
+; RV32ID-NEXT: fmv.x.w a0, fa0
+; RV32ID-NEXT: slli a0, a0, 16
+; RV32ID-NEXT: fmv.w.x fa0, a0
; RV32ID-NEXT: call __fixsfdi at plt
; RV32ID-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
; RV32ID-NEXT: addi sp, sp, 16
@@ -623,9 +622,6 @@
}
declare i64 @llvm.fptosi.sat.i64.bf16(bfloat)
-; TODO: An f16 libcall is incorrectly produced for RV32ID in the following
-; test.
-
define i64 @fcvt_lu_bf16(bfloat %a) nounwind {
; CHECK32ZFBFMIN-LABEL: fcvt_lu_bf16:
; CHECK32ZFBFMIN: # %bb.0:
@@ -641,7 +637,9 @@
; RV32ID: # %bb.0:
; RV32ID-NEXT: addi sp, sp, -16
; RV32ID-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
-; RV32ID-NEXT: call __extendhfsf2 at plt
+; RV32ID-NEXT: fmv.x.w a0, fa0
+; RV32ID-NEXT: slli a0, a0, 16
+; RV32ID-NEXT: fmv.w.x fa0, a0
; RV32ID-NEXT: call __fixunssfdi at plt
; RV32ID-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
; RV32ID-NEXT: addi sp, sp, 16
Index: llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -3614,9 +3614,11 @@
Op = GetPromotedFloat(Op);
if (getTypeAction(Op.getValueType()) == TargetLowering::TypeSoftPromoteHalf) {
- EVT NFPVT = TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType());
+ EVT OFPVT = Op.getValueType();
+ EVT NFPVT = TLI.getTypeToTransformTo(*DAG.getContext(), OFPVT);
Op = GetSoftPromotedHalf(Op);
- Op = DAG.getNode(ISD::FP16_TO_FP, dl, NFPVT, Op);
+ Op = DAG.getNode(OFPVT == MVT::f16 ? ISD::FP16_TO_FP : ISD::BF16_TO_FP, dl,
+ NFPVT, Op);
Op = DAG.getNode(ISD::FP_TO_SINT, dl, VT, Op);
SplitInteger(Op, Lo, Hi);
return;
@@ -3651,9 +3653,11 @@
Op = GetPromotedFloat(Op);
if (getTypeAction(Op.getValueType()) == TargetLowering::TypeSoftPromoteHalf) {
- EVT NFPVT = TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType());
+ EVT OFPVT = Op.getValueType();
+ EVT NFPVT = TLI.getTypeToTransformTo(*DAG.getContext(), OFPVT);
Op = GetSoftPromotedHalf(Op);
- Op = DAG.getNode(ISD::FP16_TO_FP, dl, NFPVT, Op);
+ Op = DAG.getNode(OFPVT == MVT::f16 ? ISD::FP16_TO_FP : ISD::BF16_TO_FP, dl,
+ NFPVT, Op);
Op = DAG.getNode(ISD::FP_TO_UINT, dl, VT, Op);
SplitInteger(Op, Lo, Hi);
return;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157287.548189.patch
Type: text/x-patch
Size: 3096 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230808/9f3b3ac0/attachment.bin>
More information about the llvm-commits
mailing list