[llvm] f33db99 - [RISCV] Parse Zfa fli instructions using double precision.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 8 14:16:45 PST 2023


Author: Craig Topper
Date: 2023-03-08T14:16:06-08:00
New Revision: f33db99a3c11ba0b910782b3d93ef3fdd111b6f9

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

LOG: [RISCV] Parse Zfa fli instructions using double precision.

Makes it harder to write an inexact constant that gets parsed as
a valid constant.

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
    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 7040035d8ec4..9698c992b3f1 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -496,7 +496,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
       return isUImm5();
     if (Kind != KindTy::FPImmediate)
       return false;
-    int Idx = RISCVLoadFPImm::getLoadFP32Imm(APInt(32, getFPConst()));
+    int Idx = RISCVLoadFPImm::getLoadFP64Imm(APInt(64, getFPConst()));
     // Don't allow decimal version of the minimum value. It is a 
diff erent value
     // for each supported data type.
     return Idx >= 0 && Idx != 1;
@@ -984,7 +984,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
       return;
     }
 
-    int Imm = RISCVLoadFPImm::getLoadFP32Imm(APInt(32, getFPConst()));
+    int Imm = RISCVLoadFPImm::getLoadFP64Imm(APInt(64, getFPConst()));
     Inst.addOperand(MCOperand::createImm(Imm));
   }
 
@@ -1609,7 +1609,7 @@ OperandMatchResultTy RISCVAsmParser::parseFPImm(OperandVector &Operands) {
   }
 
   // Parse FP representation.
-  APFloat RealVal(APFloat::IEEEsingle());
+  APFloat RealVal(APFloat::IEEEdouble());
   auto StatusOrErr =
       RealVal.convertFromString(Tok.getString(), APFloat::rmTowardZero);
   if (errorToBool(StatusOrErr.takeError())) {

diff  --git a/llvm/test/MC/RISCV/zfa-valid.s b/llvm/test/MC/RISCV/zfa-valid.s
index 21204b9f366b..3ee736cd507f 100644
--- a/llvm/test/MC/RISCV/zfa-valid.s
+++ b/llvm/test/MC/RISCV/zfa-valid.s
@@ -29,12 +29,12 @@ fli.s ft1, min
 # CHECK-ASM-AND-OBJ: fli.s ft1, 1.525879e-05
 # CHECK-ASM: encoding: [0xd3,0x00,0x11,0xf0]
 # CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
-fli.s ft1, 1.525879e-05
+fli.s ft1, 1.52587890625e-05
 
 # CHECK-ASM-AND-OBJ: fli.s ft1, 3.051758e-05
 # CHECK-ASM: encoding: [0xd3,0x80,0x11,0xf0]
 # CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
-fli.s ft1, 3.051758e-05
+fli.s ft1, 3.0517578125e-05
 
 # CHECK-ASM-AND-OBJ: fli.s ft1, 3.906250e-03
 # CHECK-ASM: encoding: [0xd3,0x00,0x12,0xf0]
@@ -189,12 +189,12 @@ fli.d ft1, min
 # CHECK-ASM-AND-OBJ: fli.d ft1, 1.525879e-05
 # CHECK-ASM: encoding: [0xd3,0x00,0x11,0xf2]
 # CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
-fli.d ft1, 1.525879e-05
+fli.d ft1, 1.52587890625e-05
 
 # CHECK-ASM-AND-OBJ: fli.d ft1, 3.051758e-05
 # CHECK-ASM: encoding: [0xd3,0x80,0x11,0xf2]
 # CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
-fli.d ft1, 3.051758e-05
+fli.d ft1, 3.0517578125e-05
 
 # CHECK-ASM-AND-OBJ: fli.d ft1, 3.906250e-03
 # CHECK-ASM: encoding: [0xd3,0x00,0x12,0xf2]
@@ -349,12 +349,12 @@ fli.h ft1, min
 # CHECK-ASM-AND-OBJ: fli.h ft1, 1.525879e-05
 # CHECK-ASM: encoding: [0xd3,0x00,0x11,0xf4]
 # CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
-fli.h ft1, 1.525879e-05
+fli.h ft1, 1.52587890625e-05
 
 # CHECK-ASM-AND-OBJ: fli.h ft1, 3.051758e-05
 # CHECK-ASM: encoding: [0xd3,0x80,0x11,0xf4]
 # CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
-fli.h ft1, 3.051758e-05
+fli.h ft1, 3.0517578125e-05
 
 # CHECK-ASM-AND-OBJ: fli.h ft1, 3.906250e-03
 # CHECK-ASM: encoding: [0xd3,0x00,0x12,0xf4]


        


More information about the llvm-commits mailing list