Skip to content

Commit 9a8d95b

Browse files
committed
[LoongArch] Allow recognition of b{lt,gt,le,ge}z in disassembly
This behavior is implemented for GNU Binutils since 2.41, and benefits the readability of the disassembly output. Do the same for LLVM by removing the zero weight from the alias definitions respectively.
1 parent 206b42c commit 9a8d95b

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

llvm/lib/Target/LoongArch/LoongArchInstrInfo.td

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,10 +2295,13 @@ def : InstAlias<"ret", (JIRL R0, R1, 0)>;
22952295
def : InstAlias<"jr $rj", (JIRL R0, GPR:$rj, 0)>;
22962296

22972297
// Branches implemented with alias.
2298-
// Always output the canonical mnemonic for the pseudo branch instructions.
2299-
// The GNU tools emit the canonical mnemonic for the branch pseudo instructions
2300-
// as well (e.g. "bgt" will be recognised by the assembler but never printed by
2301-
// objdump). Match this behaviour by setting a zero weight.
2298+
// Disassemble branch instructions not having a $zero operand to the
2299+
// canonical mnemonics respectively, but disassemble BLT/BGE with a $zero
2300+
// operand to the corresponding pseudo-instruction.
2301+
// GNU Binutils behave like this since 2.41, e.g. "bgt" will be recognised
2302+
// by the assembler but never printed by objdump.
2303+
// Match this behaviour by setting a zero weight for the b{gt,le}{,u}
2304+
// patterns.
23022305
def : InstAlias<"bgt $rj, $rd, $imm16",
23032306
(BLT GPR:$rd, GPR:$rj, simm16_lsl2_br:$imm16), 0>;
23042307
def : InstAlias<"bgtu $rj, $rd, $imm16",
@@ -2308,13 +2311,13 @@ def : InstAlias<"ble $rj, $rd, $imm16",
23082311
def : InstAlias<"bleu $rj, $rd, $imm16",
23092312
(BGEU GPR:$rd, GPR:$rj, simm16_lsl2_br:$imm16), 0>;
23102313
def : InstAlias<"bltz $rd, $imm16",
2311-
(BLT GPR:$rd, R0, simm16_lsl2_br:$imm16), 0>;
2314+
(BLT GPR:$rd, R0, simm16_lsl2_br:$imm16)>;
23122315
def : InstAlias<"bgtz $rj, $imm16",
2313-
(BLT R0, GPR:$rj, simm16_lsl2_br:$imm16), 0>;
2316+
(BLT R0, GPR:$rj, simm16_lsl2_br:$imm16)>;
23142317
def : InstAlias<"blez $rj, $imm16",
2315-
(BGE R0, GPR:$rj, simm16_lsl2_br:$imm16), 0>;
2318+
(BGE R0, GPR:$rj, simm16_lsl2_br:$imm16)>;
23162319
def : InstAlias<"bgez $rd, $imm16",
2317-
(BGE GPR:$rd, R0, simm16_lsl2_br:$imm16), 0>;
2320+
(BGE GPR:$rd, R0, simm16_lsl2_br:$imm16)>;
23182321

23192322
// Load immediate.
23202323
let hasSideEffects = 0, mayLoad = 0, mayStore = 0, isCodeGenOnly = 0,

llvm/test/MC/LoongArch/Macros/aliases-br.s

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ ble $a1, $a0, 16
99
bleu $a1, $a0, 16
1010
# CHECK-NEXT: bgeu $a0, $a1, 16
1111
bltz $a0, 16
12-
# CHECK-NEXT: blt $a0, $zero, 16
12+
# CHECK-NEXT: bltz $a0, 16
1313
bgtz $a0, 16
14-
# CHECK-NEXT: blt $zero, $a0, 16
14+
# CHECK-NEXT: bgtz $a0, 16
1515
blez $a0, 16
16-
# CHECK-NEXT: bge $zero, $a0, 16
16+
# CHECK-NEXT: blez $a0, 16
1717
bgez $a0, 16
18-
# CHECK-NEXT: bge $a0, $zero, 16
18+
# CHECK-NEXT: bgez $a0, 16

0 commit comments

Comments
 (0)