Skip to content

Commit aae37a2

Browse files
authored
[LoongArch] Allow recognition of b{lt,gt,le,ge}z in disassembly (#132620)
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 40815be commit aae37a2

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

llvm/lib/Target/LoongArch/LoongArchInstrInfo.td

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,11 +2294,15 @@ def : InstAlias<"move $dst, $src", (OR GPR:$dst, GPR:$src, R0)>;
22942294
def : InstAlias<"ret", (JIRL R0, R1, 0)>;
22952295
def : InstAlias<"jr $rj", (JIRL R0, GPR:$rj, 0)>;
22962296

2297-
// 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.
2297+
// Branches implemented with aliases.
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 always disassembles as "blt" by objdump, while "bgtz"
2303+
// will come back intact.
2304+
// Match this behaviour by setting a zero weight for the b{gt,le}{,u}
2305+
// patterns only.
23022306
def : InstAlias<"bgt $rj, $rd, $imm16",
23032307
(BLT GPR:$rd, GPR:$rj, simm16_lsl2_br:$imm16), 0>;
23042308
def : InstAlias<"bgtu $rj, $rd, $imm16",
@@ -2308,13 +2312,13 @@ def : InstAlias<"ble $rj, $rd, $imm16",
23082312
def : InstAlias<"bleu $rj, $rd, $imm16",
23092313
(BGEU GPR:$rd, GPR:$rj, simm16_lsl2_br:$imm16), 0>;
23102314
def : InstAlias<"bltz $rd, $imm16",
2311-
(BLT GPR:$rd, R0, simm16_lsl2_br:$imm16), 0>;
2315+
(BLT GPR:$rd, R0, simm16_lsl2_br:$imm16)>;
23122316
def : InstAlias<"bgtz $rj, $imm16",
2313-
(BLT R0, GPR:$rj, simm16_lsl2_br:$imm16), 0>;
2317+
(BLT R0, GPR:$rj, simm16_lsl2_br:$imm16)>;
23142318
def : InstAlias<"blez $rj, $imm16",
2315-
(BGE R0, GPR:$rj, simm16_lsl2_br:$imm16), 0>;
2319+
(BGE R0, GPR:$rj, simm16_lsl2_br:$imm16)>;
23162320
def : InstAlias<"bgez $rd, $imm16",
2317-
(BGE GPR:$rd, R0, simm16_lsl2_br:$imm16), 0>;
2321+
(BGE GPR:$rd, R0, simm16_lsl2_br:$imm16)>;
23182322

23192323
// Load immediate.
23202324
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)