diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -15149,7 +15149,10 @@ } } - if (LocVT == MVT::f16) { + const RISCVSubtarget &Subtarget = TLI.getSubtarget(); + + if (LocVT == MVT::f16 && + (Subtarget.hasStdExtZfh() || Subtarget.hasStdExtZfhmin())) { static const MCPhysReg FPR16List[] = { RISCV::F10_H, RISCV::F11_H, RISCV::F12_H, RISCV::F13_H, RISCV::F14_H, RISCV::F15_H, RISCV::F16_H, RISCV::F17_H, RISCV::F0_H, RISCV::F1_H, @@ -15161,7 +15164,7 @@ } } - if (LocVT == MVT::f32) { + if (LocVT == MVT::f32 && Subtarget.hasStdExtF()) { static const MCPhysReg FPR32List[] = { RISCV::F10_F, RISCV::F11_F, RISCV::F12_F, RISCV::F13_F, RISCV::F14_F, RISCV::F15_F, RISCV::F16_F, RISCV::F17_F, RISCV::F0_F, RISCV::F1_F, @@ -15173,7 +15176,7 @@ } } - if (LocVT == MVT::f64) { + if (LocVT == MVT::f64 && Subtarget.hasStdExtD()) { static const MCPhysReg FPR64List[] = { RISCV::F10_D, RISCV::F11_D, RISCV::F12_D, RISCV::F13_D, RISCV::F14_D, RISCV::F15_D, RISCV::F16_D, RISCV::F17_D, RISCV::F0_D, RISCV::F1_D, diff --git a/llvm/test/CodeGen/RISCV/fastcc-without-f-reg.ll b/llvm/test/CodeGen/RISCV/fastcc-without-f-reg.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/fastcc-without-f-reg.ll @@ -0,0 +1,48 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2 +; RUN: llc -mtriple=riscv32 -mattr=+zfinx -verify-machineinstrs < %s \ +; RUN: | FileCheck -check-prefix=RV32 %s +; RUN: llc -mtriple=riscv64 -mattr=+zfinx -verify-machineinstrs < %s \ +; RUN: | FileCheck -check-prefix=RV64 %s + +define dso_local float @caller(float noundef %x) local_unnamed_addr { +; RV32-LABEL: caller: +; RV32: # %bb.0: # %entry +; RV32-NEXT: addi sp, sp, -16 +; RV32-NEXT: .cfi_def_cfa_offset 16 +; RV32-NEXT: sw ra, 12(sp) # 4-byte Folded Spill +; RV32-NEXT: .cfi_offset ra, -4 +; RV32-NEXT: sw a0, 0(sp) +; RV32-NEXT: call f +; RV32-NEXT: lw ra, 12(sp) # 4-byte Folded Reload +; RV32-NEXT: addi sp, sp, 16 +; RV32-NEXT: ret +; +; RV64-LABEL: caller: +; RV64: # %bb.0: # %entry +; RV64-NEXT: addi sp, sp, -16 +; RV64-NEXT: .cfi_def_cfa_offset 16 +; RV64-NEXT: sd ra, 8(sp) # 8-byte Folded Spill +; RV64-NEXT: .cfi_offset ra, -8 +; RV64-NEXT: sw a0, 0(sp) +; RV64-NEXT: call f +; RV64-NEXT: ld ra, 8(sp) # 8-byte Folded Reload +; RV64-NEXT: addi sp, sp, 16 +; RV64-NEXT: ret +entry: + %0 = tail call fastcc float @f(float noundef %x) + ret float %0 +} + +define internal fastcc float @f(float noundef %x) unnamed_addr { +; RV32-LABEL: f: +; RV32: # %bb.0: # %entry +; RV32-NEXT: lw a0, 0(sp) +; RV32-NEXT: ret +; +; RV64-LABEL: f: +; RV64: # %bb.0: # %entry +; RV64-NEXT: lw a0, 0(sp) +; RV64-NEXT: ret +entry: + ret float %x +}