Skip to content

Commit de6d0d2

Browse files
authored
[RISCV][GISel] Add FCLASS to onlyUsesFP for register bank selection (#118021)
Bug fix FCLASS instruction in RISCV. The bug is due the fact that FCLASS has an input float register and output GPR this caused reg bank select regression.
1 parent 1f2aeef commit de6d0d2

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ bool RISCVRegisterBankInfo::onlyUsesFP(const MachineInstr &MI,
151151
switch (MI.getOpcode()) {
152152
case RISCV::G_FCVT_W_RV64:
153153
case RISCV::G_FCVT_WU_RV64:
154+
case RISCV::G_FCLASS:
154155
case TargetOpcode::G_FPTOSI:
155156
case TargetOpcode::G_FPTOUI:
156157
case TargetOpcode::G_FCMP:
@@ -326,19 +327,21 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
326327
// Use FPR64 for s64 loads on rv32.
327328
if (GPRSize == 32 && Size.getFixedValue() == 64) {
328329
assert(MF.getSubtarget<RISCVSubtarget>().hasStdExtD());
329-
OpdsMapping[0] = getFPValueMapping(Ty.getSizeInBits());
330+
OpdsMapping[0] = getFPValueMapping(Size);
330331
break;
331332
}
332333

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

343346
break;
344347
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
3+
; RUN: llc -mtriple=riscv32 -mattr=+f -global-isel \
4+
; RUN: < %s | FileCheck %s --check-prefixes=CHECK
5+
; RUN: llc -mtriple=riscv64 -mattr=+f -global-isel \
6+
; RUN: < %s | FileCheck %s --check-prefixes=CHECK
7+
8+
define i1 @fpclass(ptr %x) {
9+
; CHECK-LABEL: fpclass:
10+
; CHECK: # %bb.0:
11+
; CHECK-NEXT: flw fa5, 0(a0)
12+
; CHECK-NEXT: fclass.s a0, fa5
13+
; CHECK-NEXT: andi a0, a0, 927
14+
; CHECK-NEXT: snez a0, a0
15+
; CHECK-NEXT: ret
16+
%a = load float, ptr %x
17+
%cmp = call i1 @llvm.is.fpclass.f32(float %a, i32 639)
18+
ret i1 %cmp
19+
}

0 commit comments

Comments
 (0)