[PATCH] D80526: [RISCV64] emit correct lib call for fp(double) to ui/si
kamlesh kumar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 25 09:38:12 PDT 2020
kamleshbhalui created this revision.
kamleshbhalui added reviewers: asb, lenary, luismarques.
Herald added subscribers: llvm-commits, evandro, apazos, sameer.abuasal, pzheng, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, MaskRay, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya.
Herald added a project: LLVM.
since i32 is not legal in riscv64.
It always promoted to i64 before emitting lib call and
for conversions like double to int and double to unsigned int.
wrong lib call is emitted.
This patch corrects that.
https://reviews.llvm.org/D80526
Files:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/rv64i-single-softfloat.ll
Index: llvm/test/CodeGen/RISCV/rv64i-single-softfloat.ll
===================================================================
--- llvm/test/CodeGen/RISCV/rv64i-single-softfloat.ll
+++ llvm/test/CodeGen/RISCV/rv64i-single-softfloat.ll
@@ -174,7 +174,9 @@
; RV64I: # %bb.0:
; RV64I-NEXT: addi sp, sp, -16
; RV64I-NEXT: sd ra, 8(sp)
-; RV64I-NEXT: call __fixsfdi
+; RV64I-NEXT: slli a0, a0, 32
+; RV64I-NEXT: srli a0, a0, 32
+; RV64I-NEXT: call __fixsfsi
; RV64I-NEXT: ld ra, 8(sp)
; RV64I-NEXT: addi sp, sp, 16
; RV64I-NEXT: ret
@@ -187,7 +189,9 @@
; RV64I: # %bb.0:
; RV64I-NEXT: addi sp, sp, -16
; RV64I-NEXT: sd ra, 8(sp)
-; RV64I-NEXT: call __fixunssfdi
+; RV64I-NEXT: slli a0, a0, 32
+; RV64I-NEXT: srli a0, a0, 32
+; RV64I-NEXT: call __fixunssfsi
; RV64I-NEXT: ld ra, 8(sp)
; RV64I-NEXT: addi sp, sp, 16
; RV64I-NEXT: ret
@@ -710,3 +714,29 @@
%conv = fptrunc double %a to float
ret float %conv
}
+
+define i32 @fp_to_si(double %a) nounwind {
+; RV64I-LABEL: fp_to_si:
+; RV64I: # %bb.0:
+; RV64I-NEXT: addi sp, sp, -16
+; RV64I-NEXT: sd ra, 8(sp)
+; RV64I-NEXT: call __fixdfsi
+; RV64I-NEXT: ld ra, 8(sp)
+; RV64I-NEXT: addi sp, sp, 16
+; RV64I-NEXT: ret
+ %conv = fptosi double %a to i32
+ ret i32 %conv
+}
+
+define i32 @fp_to_ui(double %a) nounwind {
+; RV64I-LABEL: fp_to_ui:
+; RV64I: # %bb.0:
+; RV64I-NEXT: addi sp, sp, -16
+; RV64I-NEXT: sd ra, 8(sp)
+; RV64I-NEXT: call __fixunsdfsi
+; RV64I-NEXT: ld ra, 8(sp)
+; RV64I-NEXT: addi sp, sp, 16
+; RV64I-NEXT: ret
+ %conv = fptoui double %a to i32
+ ret i32 %conv
+}
Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -197,6 +197,12 @@
setTruncStoreAction(MVT::f64, MVT::f16, Expand);
}
+ if (Subtarget.is64Bit() && !(Subtarget.hasStdExtD()
+ || Subtarget.hasStdExtF())) {
+ setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom);
+ setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom);
+ }
+
setOperationAction(ISD::GlobalAddress, XLenVT, Custom);
setOperationAction(ISD::BlockAddress, XLenVT, Custom);
setOperationAction(ISD::ConstantPool, XLenVT, Custom);
@@ -904,6 +910,26 @@
switch (N->getOpcode()) {
default:
llvm_unreachable("Don't know how to custom type legalize this operation!");
+ case ISD::FP_TO_SINT:
+ case ISD::FP_TO_UINT: {
+ assert(N->getValueType(0) == MVT::i32 && Subtarget.is64Bit() &&
+ "Unexpected custom legalisation");
+ SDValue Op0 = N->getOperand(0);
+ RTLIB::Libcall LC;
+ if (N->getOpcode() == ISD::FP_TO_SINT)
+ LC = RTLIB::getFPTOSINT(Op0.getValueType(),
+ N->getValueType(0));
+ else
+ LC = RTLIB::getFPTOUINT(Op0.getValueType(),
+ N->getValueType(0));
+ MakeLibCallOptions CallOptions;
+ SDValue Chain = SDValue();
+ SDValue Result;
+ std::tie(Result, Chain) = makeLibCall(DAG, LC, N->getValueType(0), Op0,
+ CallOptions, DL, Chain);
+ Results.push_back(Result);
+ break;
+ }
case ISD::READCYCLECOUNTER: {
assert(!Subtarget.is64Bit() &&
"READCYCLECOUNTER only has custom type legalization on riscv32");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80526.266038.patch
Type: text/x-patch
Size: 3421 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200525/e922603c/attachment-0001.bin>
More information about the llvm-commits
mailing list