[llvm] 2afce71 - [RISCV] Remove support for integers in RISCVAsmParser::parseFPImm.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 8 12:39:44 PST 2023


Author: Craig Topper
Date: 2023-03-08T12:39:36-08:00
New Revision: 2afce71fcfeca96ce14109000973cd4b2f5797c2

URL: https://github.com/llvm/llvm-project/commit/2afce71fcfeca96ce14109000973cd4b2f5797c2
DIFF: https://github.com/llvm/llvm-project/commit/2afce71fcfeca96ce14109000973cd4b2f5797c2.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
    llvm/test/MC/RISCV/zfa-invalid.s
    llvm/test/MC/RISCV/zfa-valid.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 4a472e9d0f7e4..7040035d8ec4f 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -1603,36 +1603,25 @@ 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;
-    }
+  // 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();
+  if (IsNegative)
+    RealVal.changeSign();
 
-    Operands.push_back(RISCVOperand::createFPImm(
-        RealVal.bitcastToAPInt().getZExtValue(), S));
-  }
+  Operands.push_back(RISCVOperand::createFPImm(
+      RealVal.bitcastToAPInt().getZExtValue(), S));
 
   Lex(); // Eat the token.
 

diff  --git a/llvm/test/MC/RISCV/zfa-invalid.s b/llvm/test/MC/RISCV/zfa-invalid.s
index f565c96a06885..e48618506626b 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 21d5d9276102d..21204b9f366bc 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){{$}}


        


More information about the llvm-commits mailing list