[PATCH] D145535: [RISCV] Store fli min/nan/inf in index form in RISCVOperand.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 7 20:03:23 PST 2023
craig.topper updated this revision to Diff 503216.
craig.topper added a comment.
Add an assert to getFPImm now that we no longer use it for min/inf/nan. Since it
isn't type aware its dangerous to use for those values.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D145535/new/
https://reviews.llvm.org/D145535
Files:
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
===================================================================
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
@@ -376,6 +376,7 @@
namespace RISCVLoadFPImm {
inline static uint32_t getFPImm(unsigned Imm) {
+ assert(Imm != 1 && Imm != 30 && Imm != 31 && "Unsupported immediate");
uint8_t Sign;
uint8_t Exp;
uint8_t Mantissa;
Index: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
===================================================================
--- llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -492,6 +492,8 @@
/// Return true if the operand is a valid fli.s floating-point immediate.
bool isLoadFPImm() const {
+ if (isImm())
+ return isUImm5();
return Kind == KindTy::FPImmediate &&
RISCVLoadFPImm::getLoadFP32Imm(APInt(32, getFPConst())) != -1;
}
@@ -973,6 +975,11 @@
void addFPImmOperands(MCInst &Inst, unsigned N) const {
assert(N == 1 && "Invalid number of operands!");
+ if (isImm()) {
+ addExpr(Inst, getImm(), isRV64Imm());
+ return;
+ }
+
int Imm = RISCVLoadFPImm::getLoadFP32Imm(APInt(32, getFPConst()));
Inst.addOperand(MCOperand::createImm(Imm));
}
@@ -1567,16 +1574,17 @@
if (getTok().is(AsmToken::Identifier)) {
StringRef Identifier = getTok().getIdentifier();
if (Identifier.compare_insensitive("inf") == 0) {
- APFloat SpecialVal = APFloat::getInf(APFloat::IEEEsingle());
- Operands.push_back(RISCVOperand::createFPImm(
- SpecialVal.bitcastToAPInt().getZExtValue(), S));
+ Operands.push_back(
+ RISCVOperand::createImm(MCConstantExpr::create(30, getContext()), S,
+ getTok().getEndLoc(), isRV64()));
} else if (Identifier.compare_insensitive("nan") == 0) {
- APFloat SpecialVal = APFloat::getNaN(APFloat::IEEEsingle());
- Operands.push_back(RISCVOperand::createFPImm(
- SpecialVal.bitcastToAPInt().getZExtValue(), S));
+ Operands.push_back(
+ RISCVOperand::createImm(MCConstantExpr::create(31, getContext()), S,
+ getTok().getEndLoc(), isRV64()));
} else if (Identifier.compare_insensitive("min") == 0) {
- unsigned SpecialVal = RISCVLoadFPImm::getFPImm(1);
- Operands.push_back(RISCVOperand::createFPImm(SpecialVal, S));
+ Operands.push_back(
+ RISCVOperand::createImm(MCConstantExpr::create(1, getContext()), S,
+ getTok().getEndLoc(), isRV64()));
} else {
TokError("invalid floating point literal");
return MatchOperand_ParseFail;
@@ -1602,8 +1610,9 @@
TokError("encoded floating point value out of range");
return MatchOperand_ParseFail;
}
- unsigned F = RISCVLoadFPImm::getFPImm(Tok.getIntVal());
- Operands.push_back(RISCVOperand::createFPImm(F, S));
+ Operands.push_back(RISCVOperand::createImm(
+ MCConstantExpr::create(Tok.getIntVal(), getContext()), S,
+ Tok.getEndLoc(), isRV64()));
} else {
// Parse FP representation.
APFloat RealVal(APFloat::IEEEsingle());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145535.503216.patch
Type: text/x-patch
Size: 3257 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230308/03bda275/attachment.bin>
More information about the llvm-commits
mailing list