Skip to content

Commit 33df888

Browse files
authored
[RISCV] Teach RISCVTargetLowering::isFPImmLegal about fli+fneg (#149075)
There was a mismatch between isFPImmlegal and the cases that are handled by lowerConstantFP. isFPImmLegal didn't check for the case where we support `fli` of a negated constant (and so can lower to fli+fneg). This has very minimal impact (42 insertion, 47 deletions across an rv22u64_zfa llvm-test-suite build including SPEC CPU 2017) but is added here for completeness. See the PR thread #149075 for furrther discussion about the degree to which isFPImmLegal and lowerConstantFP are consistent. We ultimately agreed it makes sense to add fli+fneg, but there may be other future cases where it doesn't make sense to match.
1 parent 287b944 commit 33df888

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,6 +2319,10 @@ bool RISCVTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT,
23192319
if (getLegalZfaFPImm(Imm, VT) >= 0)
23202320
return true;
23212321

2322+
// Some constants can be produced by fli+fneg.
2323+
if (Imm.isNegative() && getLegalZfaFPImm(-Imm, VT) >= 0)
2324+
return true;
2325+
23222326
// Cannot create a 64 bit floating-point immediate value for rv32.
23232327
if (Subtarget.getXLen() < VT.getScalarSizeInBits()) {
23242328
// td can handle +0.0 or -0.0 already.

0 commit comments

Comments
 (0)