From 2afce71fcfeca96ce14109000973cd4b2f5797c2 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Wed, 8 Mar 2023 12:39:30 -0800 Subject: [PATCH] [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. --- .../Target/RISCV/AsmParser/RISCVAsmParser.cpp | 39 +++++++------------ llvm/test/MC/RISCV/zfa-invalid.s | 4 ++ llvm/test/MC/RISCV/zfa-valid.s | 20 ---------- 3 files changed, 18 insertions(+), 45 deletions(-) diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp index 4a472e9d0f7e..7040035d8ec4 100644 --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -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; diff --git a/llvm/test/MC/RISCV/zfa-invalid.s b/llvm/test/MC/RISCV/zfa-invalid.s index f565c96a0688..e48618506626 100644 --- a/llvm/test/MC/RISCV/zfa-invalid.s +++ b/llvm/test/MC/RISCV/zfa-invalid.s @@ -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 diff --git a/llvm/test/MC/RISCV/zfa-valid.s b/llvm/test/MC/RISCV/zfa-valid.s index 21d5d9276102..21204b9f366b 100644 --- a/llvm/test/MC/RISCV/zfa-valid.s +++ b/llvm/test/MC/RISCV/zfa-valid.s @@ -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){{$}}