Skip to content

[RISCV][GISel] Add FCLASS to onlyUsesFP for register bank selection #118021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ bool RISCVRegisterBankInfo::onlyUsesFP(const MachineInstr &MI,
switch (MI.getOpcode()) {
case RISCV::G_FCVT_W_RV64:
case RISCV::G_FCVT_WU_RV64:
case RISCV::G_FCLASS:
case TargetOpcode::G_FPTOSI:
case TargetOpcode::G_FPTOUI:
case TargetOpcode::G_FCMP:
Expand Down Expand Up @@ -326,19 +327,21 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
// Use FPR64 for s64 loads on rv32.
if (GPRSize == 32 && Size.getFixedValue() == 64) {
assert(MF.getSubtarget<RISCVSubtarget>().hasStdExtD());
OpdsMapping[0] = getFPValueMapping(Ty.getSizeInBits());
OpdsMapping[0] = getFPValueMapping(Size);
break;
}

// Check if that load feeds fp instructions.
// In that case, we want the default mapping to be on FPR
// instead of blind map every scalar to GPR.
if (anyUseOnlyUseFP(MI.getOperand(0).getReg(), MRI, TRI))
if (anyUseOnlyUseFP(MI.getOperand(0).getReg(), MRI, TRI)) {
// If we have at least one direct use in a FP instruction,
// assume this was a floating point load in the IR. If it was
// not, we would have had a bitcast before reaching that
// instruction.
OpdsMapping[0] = getFPValueMapping(Ty.getSizeInBits());
OpdsMapping[0] = getFPValueMapping(Size);
break;
}

break;
}
Expand Down
19 changes: 19 additions & 0 deletions llvm/test/CodeGen/RISCV/GlobalISel/float-fclass.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5

; RUN: llc -mtriple=riscv32 -mattr=+f -global-isel \
; RUN: < %s | FileCheck %s --check-prefixes=CHECK
; RUN: llc -mtriple=riscv64 -mattr=+f -global-isel \
; RUN: < %s | FileCheck %s --check-prefixes=CHECK

define i1 @fpclass(ptr %x) {
; CHECK-LABEL: fpclass:
; CHECK: # %bb.0:
; CHECK-NEXT: flw fa5, 0(a0)
; CHECK-NEXT: fclass.s a0, fa5
; CHECK-NEXT: andi a0, a0, 927
; CHECK-NEXT: snez a0, a0
; CHECK-NEXT: ret
%a = load float, ptr %x
%cmp = call i1 @llvm.is.fpclass.f32(float %a, i32 639)
ret i1 %cmp
}
Loading