[llvm] 078aaf1 - [LoongArch] Add diagnostics for PseudoLI_D instruction (#85742)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 19 04:37:04 PDT 2024
Author: wanglei
Date: 2024-03-19T19:36:59+08:00
New Revision: 078aaf1f78e5df55618b71f1fe75993e4ccb6a72
URL: https://github.com/llvm/llvm-project/commit/078aaf1f78e5df55618b71f1fe75993e4ccb6a72
DIFF: https://github.com/llvm/llvm-project/commit/078aaf1f78e5df55618b71f1fe75993e4ccb6a72.diff
LOG: [LoongArch] Add diagnostics for PseudoLI_D instruction (#85742)
Simultaneously improved diagnostic testing for the `PseudoLI_W`
instruction.
Added:
Modified:
llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp
llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
llvm/test/MC/LoongArch/Macros/macros-li-bad.s
Removed:
################################################################################
diff --git a/llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp b/llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp
index 46f63a4103f9f9..cf163e4e12001c 100644
--- a/llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp
+++ b/llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp
@@ -453,6 +453,14 @@ class LoongArchOperand : public MCParsedAsmOperand {
}
bool isImm32() const { return isSImm<32>() || isUImm<32>(); }
+ bool isImm64() const {
+ if (!isImm())
+ return false;
+ int64_t Imm;
+ LoongArchMCExpr::VariantKind VK = LoongArchMCExpr::VK_LoongArch_None;
+ bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
+ return IsConstantImm && VK == LoongArchMCExpr::VK_LoongArch_None;
+ }
/// Gets location of the first token of this operand.
SMLoc getStartLoc() const override { return StartLoc; }
@@ -1514,6 +1522,10 @@ bool LoongArchAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
SMLoc ErrorLoc = ((LoongArchOperand &)*Operands[ErrorInfo]).getStartLoc();
return Error(ErrorLoc, "operand must be a 32 bit immediate");
}
+ case Match_InvalidImm64: {
+ SMLoc ErrorLoc = ((LoongArchOperand &)*Operands[ErrorInfo]).getStartLoc();
+ return Error(ErrorLoc, "operand must be a 64 bit immediate");
+ }
case Match_InvalidBareSymbol: {
SMLoc ErrorLoc = ((LoongArchOperand &)*Operands[ErrorInfo]).getStartLoc();
return Error(ErrorLoc, "operand must be a bare symbol name");
diff --git a/llvm/lib/Target/LoongArch/LoongArchInstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
index fcfff08d1a9f54..80429bc45be14c 100644
--- a/llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
+++ b/llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
@@ -219,6 +219,9 @@ def grlenimm : Operand<GRLenVT>;
def imm32 : Operand<GRLenVT> {
let ParserMatchClass = ImmAsmOperand<"", 32, "">;
}
+def imm64 : Operand<i64> {
+ let ParserMatchClass = ImmAsmOperand<"", 64, "">;
+}
def uimm1 : Operand<GRLenVT>, ImmLeaf<GRLenVT, [{return isUInt<1>(Imm);}]>{
let ParserMatchClass = UImmAsmOperand<1>;
@@ -2179,7 +2182,7 @@ let hasSideEffects = 0, mayLoad = 0, mayStore = 0, isCodeGenOnly = 0,
isAsmParserOnly = 1 in {
def PseudoLI_W : Pseudo<(outs GPR:$rd), (ins imm32:$imm), [],
"li.w", "$rd, $imm">;
-def PseudoLI_D : Pseudo<(outs GPR:$rd), (ins grlenimm:$imm), [],
+def PseudoLI_D : Pseudo<(outs GPR:$rd), (ins imm64:$imm), [],
"li.d", "$rd, $imm">, Requires<[IsLA64]>;
}
diff --git a/llvm/test/MC/LoongArch/Macros/macros-li-bad.s b/llvm/test/MC/LoongArch/Macros/macros-li-bad.s
index 194b86bfed2733..c880a01020059b 100644
--- a/llvm/test/MC/LoongArch/Macros/macros-li-bad.s
+++ b/llvm/test/MC/LoongArch/Macros/macros-li-bad.s
@@ -5,3 +5,9 @@ li.w $a0, 0x100000000
li.d $a0, 0x10000000000000000
# CHECK: :[[#@LINE-1]]:11: error: unknown operand
+
+li.w $a0, non_const_val
+# CHECK: :[[#@LINE-1]]:11: error: operand must be a 32 bit immediate
+
+li.d $a0, non_const_val
+# CHECK: :[[#@LINE-1]]:11: error: operand must be a 64 bit immediate
More information about the llvm-commits
mailing list