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"); 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 +}