[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:02:37 PDT 2023
asb updated this revision to Diff 548179.
asb added a comment.
1. Rebase (all dependent patches are now committed)
2. Remove TODO comments that are fixed by this patch
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
@@ -3616,7 +3616,9 @@
if (getTypeAction(Op.getValueType()) == TargetLowering::TypeSoftPromoteHalf) {
EVT NFPVT = TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType());
Op = GetSoftPromotedHalf(Op);
- Op = DAG.getNode(ISD::FP16_TO_FP, dl, NFPVT, Op);
+ Op = DAG.getNode(Op.getValueType() == 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;
@@ -3653,7 +3655,9 @@
if (getTypeAction(Op.getValueType()) == TargetLowering::TypeSoftPromoteHalf) {
EVT NFPVT = TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType());
Op = GetSoftPromotedHalf(Op);
- Op = DAG.getNode(ISD::FP16_TO_FP, dl, NFPVT, Op);
+ Op = DAG.getNode(Op.getValueType() == 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.548179.patch
Type: text/x-patch
Size: 2944 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230808/361c3a09/attachment.bin>
More information about the llvm-commits
mailing list