Skip to content

Commit 6790292

Browse files
wangleiatSixWeining
authored andcommitted
[LoongArch] Modify ParserMethod for the simm26_b operand type
Modify the ParserMethod of `simm26_b` operand type to `parseImmediate`. Before that, for the `simm26_b` operand type, the same ParserMethod was used as `simm26_bl`. When using the internal assembler to process the blockaddress with `asm` instruction, the wrong blockaddress symbol would be generated due to the call to the `getOrCreateSymbol()` interface. Differential Revision: https://reviews.llvm.org/D136073
1 parent befb731 commit 6790292

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

llvm/lib/Target/LoongArch/LoongArchInstrInfo.td

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,24 +202,32 @@ def simm21_lsl2 : Operand<OtherVT> {
202202
let DecoderMethod = "decodeSImmOperand<21, 2>";
203203
}
204204

205-
// TODO: Need split the ParserMethod/PredicateMethod for call/jump/tailcall.
206-
def SImm26Operand: AsmOperandClass {
207-
let Name = "SImm26Operand";
205+
def SImm26OperandB: AsmOperandClass {
206+
let Name = "SImm26OperandB";
207+
let PredicateMethod = "isSImm26Operand";
208208
let RenderMethod = "addImmOperands";
209209
let DiagnosticType = "InvalidSImm26Operand";
210-
let ParserMethod = "parseSImm26Operand";
210+
let ParserMethod = "parseImmediate";
211211
}
212212

213213
// A symbol or an imm used in B/PseudoBR.
214214
def simm26_b : Operand<OtherVT> {
215-
let ParserMatchClass = SImm26Operand;
215+
let ParserMatchClass = SImm26OperandB;
216216
let EncoderMethod = "getImmOpValueAsr2";
217217
let DecoderMethod = "decodeSImmOperand<26, 2>";
218218
}
219219

220+
def SImm26OperandBL: AsmOperandClass {
221+
let Name = "SImm26OperandBL";
222+
let PredicateMethod = "isSImm26Operand";
223+
let RenderMethod = "addImmOperands";
224+
let DiagnosticType = "InvalidSImm26Operand";
225+
let ParserMethod = "parseSImm26Operand";
226+
}
227+
220228
// A symbol or an imm used in BL/PseudoCALL.
221229
def simm26_bl : Operand<GRLenVT> {
222-
let ParserMatchClass = SImm26Operand;
230+
let ParserMatchClass = SImm26OperandBL;
223231
let EncoderMethod = "getImmOpValueAsr2";
224232
let DecoderMethod = "decodeSImmOperand<26, 2>";
225233
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc --mtriple=loongarch32 < %s | FileCheck %s
3+
; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s
4+
; RUN: llc --mtriple=loongarch32 --no-integrated-as < %s | FileCheck %s
5+
; RUN: llc --mtriple=loongarch64 --no-integrated-as < %s | FileCheck %s
6+
7+
;; This regression test is for ensuring the AsmParser does not use the
8+
;; getOrCreateSymbol interface to create blockaddress symbols.
9+
;; Otherwise incorrect symbols will be created:
10+
;; `.Ltmp0` -> `.Ltmp00`.
11+
12+
define void @operand_block_address() nounwind {
13+
; CHECK-LABEL: operand_block_address:
14+
; CHECK: # %bb.0:
15+
; CHECK-NEXT: #APP
16+
; CHECK-NEXT: b .Ltmp0
17+
; CHECK-NEXT: #NO_APP
18+
; CHECK-NEXT: .Ltmp0: # Block address taken
19+
; CHECK-NEXT: # %bb.1: # %bb
20+
; CHECK-NEXT: ret
21+
call void asm sideeffect "b $0", "i"(i8* blockaddress(@operand_block_address, %bb))
22+
br label %bb
23+
bb:
24+
ret void
25+
}

0 commit comments

Comments
 (0)