Skip to content

Commit 2afce71

Browse files
committed
[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.
1 parent cf2942a commit 2afce71

File tree

3 files changed

+17
-44
lines changed

3 files changed

+17
-44
lines changed

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

+13-24
Original file line numberDiff line numberDiff line change
@@ -1603,36 +1603,25 @@ OperandMatchResultTy RISCVAsmParser::parseFPImm(OperandVector &Operands) {
16031603
bool IsNegative = parseOptionalToken(AsmToken::Minus);
16041604

16051605
const AsmToken &Tok = getTok();
1606-
if (!Tok.is(AsmToken::Real) && !Tok.is(AsmToken::Integer)) {
1606+
if (!Tok.is(AsmToken::Real)) {
16071607
TokError("invalid floating point immediate");
16081608
return MatchOperand_ParseFail;
16091609
}
16101610

1611-
if (Tok.is(AsmToken::Integer)) {
1612-
// Parse integer representation.
1613-
if (Tok.getIntVal() > 31 || IsNegative) {
1614-
TokError("encoded floating point value out of range");
1615-
return MatchOperand_ParseFail;
1616-
}
1617-
Operands.push_back(RISCVOperand::createImm(
1618-
MCConstantExpr::create(Tok.getIntVal(), getContext()), S,
1619-
Tok.getEndLoc(), isRV64()));
1620-
} else {
1621-
// Parse FP representation.
1622-
APFloat RealVal(APFloat::IEEEsingle());
1623-
auto StatusOrErr =
1624-
RealVal.convertFromString(Tok.getString(), APFloat::rmTowardZero);
1625-
if (errorToBool(StatusOrErr.takeError())) {
1626-
TokError("invalid floating point representation");
1627-
return MatchOperand_ParseFail;
1628-
}
1611+
// Parse FP representation.
1612+
APFloat RealVal(APFloat::IEEEsingle());
1613+
auto StatusOrErr =
1614+
RealVal.convertFromString(Tok.getString(), APFloat::rmTowardZero);
1615+
if (errorToBool(StatusOrErr.takeError())) {
1616+
TokError("invalid floating point representation");
1617+
return MatchOperand_ParseFail;
1618+
}
16291619

1630-
if (IsNegative)
1631-
RealVal.changeSign();
1620+
if (IsNegative)
1621+
RealVal.changeSign();
16321622

1633-
Operands.push_back(RISCVOperand::createFPImm(
1634-
RealVal.bitcastToAPInt().getZExtValue(), S));
1635-
}
1623+
Operands.push_back(RISCVOperand::createFPImm(
1624+
RealVal.bitcastToAPInt().getZExtValue(), S));
16361625

16371626
Lex(); // Eat the token.
16381627

llvm/test/MC/RISCV/zfa-invalid.s

+4
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,7 @@ fli.d ft1, 1.1754943508222875079687365372222456778186655567720875215087517062784
7272
# CHECK-NO-RV32: error: operand must be a valid floating-point constant
7373
fli.h ft1, 1.1754943508222875079687365372222456778186655567720875215087517062784172594547271728515625e-38
7474

75+
# Don't accept integers.
76+
# CHECK-NO-RV32: error: invalid floating point immediate
77+
# CHECK-NO-RV64: error: invalid floating point immediate
78+
fli.s ft1, 1

llvm/test/MC/RISCV/zfa-valid.s

-20
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,6 @@ fli.s ft1, 3.276800e+04
166166
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
167167
fli.s ft1, 6.553600e+04
168168

169-
# CHECK-ASM-AND-OBJ: fli.s ft1, 6.553600e+04
170-
# CHECK-ASM: encoding: [0xd3,0x80,0x1e,0xf0]
171-
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
172-
fli.s ft1, 29
173-
174169
# CHECK-ASM-AND-OBJ: fli.s ft1, inf
175170
# CHECK-ASM: encoding: [0xd3,0x00,0x1f,0xf0]
176171
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
@@ -226,11 +221,6 @@ fli.d ft1, 1.250000e-01
226221
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
227222
fli.d ft1, 2.500000e-01
228223

229-
# CHECK-ASM-AND-OBJ: fli.d ft1, 2.500000e-01
230-
# CHECK-ASM: encoding: [0xd3,0x00,0x14,0xf2]
231-
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
232-
fli.d ft1, 8
233-
234224
# CHECK-ASM-AND-OBJ: fli.d ft1, 3.125000e-01
235225
# CHECK-ASM: encoding: [0xd3,0x80,0x14,0xf2]
236226
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
@@ -336,11 +326,6 @@ fli.d ft1, 3.276800e+04
336326
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
337327
fli.d ft1, 6.553600e+04
338328

339-
# CHECK-ASM-AND-OBJ: fli.d ft1, 6.553600e+04
340-
# CHECK-ASM: encoding: [0xd3,0x80,0x1e,0xf2]
341-
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
342-
fli.d ft1, 29
343-
344329
# CHECK-ASM-AND-OBJ: fli.d ft1, inf
345330
# CHECK-ASM: encoding: [0xd3,0x00,0x1f,0xf2]
346331
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
@@ -501,11 +486,6 @@ fli.h ft1, 3.276800e+04
501486
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
502487
fli.h ft1, 6.553600e+04
503488

504-
# CHECK-ASM-AND-OBJ: fli.h ft1, 6.553600e+04
505-
# CHECK-ASM: encoding: [0xd3,0x80,0x1e,0xf4]
506-
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
507-
fli.h ft1, 29
508-
509489
# CHECK-ASM-AND-OBJ: fli.h ft1, inf
510490
# CHECK-ASM: encoding: [0xd3,0x00,0x1f,0xf4]
511491
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}

0 commit comments

Comments
 (0)