[RISCV] Remove support for integers in RISCVAsmParser::parseFPImm.

Integers are ambiguous as to whether it's an index or an FP value
without a decimal.

Looks like maybe AArch64 equivalent treates integers in hex as
index and any other integer as a FP value without a decimal. We
need to work with the RVI community to decide what we should do.
This commit is contained in:
Craig Topper 2023-03-08 12:39:30 -08:00
parent cf2942a12f
commit 2afce71fcf
3 changed files with 18 additions and 45 deletions

View File

@ -1603,37 +1603,26 @@ OperandMatchResultTy RISCVAsmParser::parseFPImm(OperandVector &Operands) {
bool IsNegative = parseOptionalToken(AsmToken::Minus);
const AsmToken &Tok = getTok();
if (!Tok.is(AsmToken::Real) && !Tok.is(AsmToken::Integer)) {
if (!Tok.is(AsmToken::Real)) {
TokError("invalid floating point immediate");
return MatchOperand_ParseFail;
}
if (Tok.is(AsmToken::Integer)) {
// Parse integer representation.
if (Tok.getIntVal() > 31 || IsNegative) {
TokError("encoded floating point value out of range");
return MatchOperand_ParseFail;
}
Operands.push_back(RISCVOperand::createImm(
MCConstantExpr::create(Tok.getIntVal(), getContext()), S,
Tok.getEndLoc(), isRV64()));
} else {
// Parse FP representation.
APFloat RealVal(APFloat::IEEEsingle());
auto StatusOrErr =
RealVal.convertFromString(Tok.getString(), APFloat::rmTowardZero);
if (errorToBool(StatusOrErr.takeError())) {
TokError("invalid floating point representation");
return MatchOperand_ParseFail;
}
if (IsNegative)
RealVal.changeSign();
Operands.push_back(RISCVOperand::createFPImm(
RealVal.bitcastToAPInt().getZExtValue(), S));
// Parse FP representation.
APFloat RealVal(APFloat::IEEEsingle());
auto StatusOrErr =
RealVal.convertFromString(Tok.getString(), APFloat::rmTowardZero);
if (errorToBool(StatusOrErr.takeError())) {
TokError("invalid floating point representation");
return MatchOperand_ParseFail;
}
if (IsNegative)
RealVal.changeSign();
Operands.push_back(RISCVOperand::createFPImm(
RealVal.bitcastToAPInt().getZExtValue(), S));
Lex(); // Eat the token.
return MatchOperand_Success;

View File

@ -72,3 +72,7 @@ fli.d ft1, 1.1754943508222875079687365372222456778186655567720875215087517062784
# CHECK-NO-RV32: error: operand must be a valid floating-point constant
fli.h ft1, 1.1754943508222875079687365372222456778186655567720875215087517062784172594547271728515625e-38
# Don't accept integers.
# CHECK-NO-RV32: error: invalid floating point immediate
# CHECK-NO-RV64: error: invalid floating point immediate
fli.s ft1, 1

View File

@ -166,11 +166,6 @@ fli.s ft1, 3.276800e+04
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
fli.s ft1, 6.553600e+04
# CHECK-ASM-AND-OBJ: fli.s ft1, 6.553600e+04
# CHECK-ASM: encoding: [0xd3,0x80,0x1e,0xf0]
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
fli.s ft1, 29
# CHECK-ASM-AND-OBJ: fli.s ft1, inf
# CHECK-ASM: encoding: [0xd3,0x00,0x1f,0xf0]
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
@ -226,11 +221,6 @@ fli.d ft1, 1.250000e-01
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
fli.d ft1, 2.500000e-01
# CHECK-ASM-AND-OBJ: fli.d ft1, 2.500000e-01
# CHECK-ASM: encoding: [0xd3,0x00,0x14,0xf2]
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
fli.d ft1, 8
# CHECK-ASM-AND-OBJ: fli.d ft1, 3.125000e-01
# CHECK-ASM: encoding: [0xd3,0x80,0x14,0xf2]
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
@ -336,11 +326,6 @@ fli.d ft1, 3.276800e+04
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
fli.d ft1, 6.553600e+04
# CHECK-ASM-AND-OBJ: fli.d ft1, 6.553600e+04
# CHECK-ASM: encoding: [0xd3,0x80,0x1e,0xf2]
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
fli.d ft1, 29
# CHECK-ASM-AND-OBJ: fli.d ft1, inf
# CHECK-ASM: encoding: [0xd3,0x00,0x1f,0xf2]
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
@ -501,11 +486,6 @@ fli.h ft1, 3.276800e+04
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
fli.h ft1, 6.553600e+04
# CHECK-ASM-AND-OBJ: fli.h ft1, 6.553600e+04
# CHECK-ASM: encoding: [0xd3,0x80,0x1e,0xf4]
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
fli.h ft1, 29
# CHECK-ASM-AND-OBJ: fli.h ft1, inf
# CHECK-ASM: encoding: [0xd3,0x00,0x1f,0xf4]
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}