Skip to content

Commit 078aaf1

Browse files
authored
[LoongArch] Add diagnostics for PseudoLI_D instruction (#85742)
Simultaneously improved diagnostic testing for the `PseudoLI_W` instruction.
1 parent 7edfbf2 commit 078aaf1

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,14 @@ class LoongArchOperand : public MCParsedAsmOperand {
453453
}
454454

455455
bool isImm32() const { return isSImm<32>() || isUImm<32>(); }
456+
bool isImm64() const {
457+
if (!isImm())
458+
return false;
459+
int64_t Imm;
460+
LoongArchMCExpr::VariantKind VK = LoongArchMCExpr::VK_LoongArch_None;
461+
bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
462+
return IsConstantImm && VK == LoongArchMCExpr::VK_LoongArch_None;
463+
}
456464

457465
/// Gets location of the first token of this operand.
458466
SMLoc getStartLoc() const override { return StartLoc; }
@@ -1514,6 +1522,10 @@ bool LoongArchAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
15141522
SMLoc ErrorLoc = ((LoongArchOperand &)*Operands[ErrorInfo]).getStartLoc();
15151523
return Error(ErrorLoc, "operand must be a 32 bit immediate");
15161524
}
1525+
case Match_InvalidImm64: {
1526+
SMLoc ErrorLoc = ((LoongArchOperand &)*Operands[ErrorInfo]).getStartLoc();
1527+
return Error(ErrorLoc, "operand must be a 64 bit immediate");
1528+
}
15171529
case Match_InvalidBareSymbol: {
15181530
SMLoc ErrorLoc = ((LoongArchOperand &)*Operands[ErrorInfo]).getStartLoc();
15191531
return Error(ErrorLoc, "operand must be a bare symbol name");

llvm/lib/Target/LoongArch/LoongArchInstrInfo.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ def grlenimm : Operand<GRLenVT>;
219219
def imm32 : Operand<GRLenVT> {
220220
let ParserMatchClass = ImmAsmOperand<"", 32, "">;
221221
}
222+
def imm64 : Operand<i64> {
223+
let ParserMatchClass = ImmAsmOperand<"", 64, "">;
224+
}
222225

223226
def uimm1 : Operand<GRLenVT>, ImmLeaf<GRLenVT, [{return isUInt<1>(Imm);}]>{
224227
let ParserMatchClass = UImmAsmOperand<1>;
@@ -2179,7 +2182,7 @@ let hasSideEffects = 0, mayLoad = 0, mayStore = 0, isCodeGenOnly = 0,
21792182
isAsmParserOnly = 1 in {
21802183
def PseudoLI_W : Pseudo<(outs GPR:$rd), (ins imm32:$imm), [],
21812184
"li.w", "$rd, $imm">;
2182-
def PseudoLI_D : Pseudo<(outs GPR:$rd), (ins grlenimm:$imm), [],
2185+
def PseudoLI_D : Pseudo<(outs GPR:$rd), (ins imm64:$imm), [],
21832186
"li.d", "$rd, $imm">, Requires<[IsLA64]>;
21842187
}
21852188

llvm/test/MC/LoongArch/Macros/macros-li-bad.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ li.w $a0, 0x100000000
55

66
li.d $a0, 0x10000000000000000
77
# CHECK: :[[#@LINE-1]]:11: error: unknown operand
8+
9+
li.w $a0, non_const_val
10+
# CHECK: :[[#@LINE-1]]:11: error: operand must be a 32 bit immediate
11+
12+
li.d $a0, non_const_val
13+
# CHECK: :[[#@LINE-1]]:11: error: operand must be a 64 bit immediate

0 commit comments

Comments
 (0)