[LoongArch] Implement assembler branches pseudo instructions

These instructions always output the canonical mnemonic. The GNU tools
emit the canonical mnemonic for the branch pseudo instructions as well
(e.g. "bgt" will be recognised by the assembler but never printed by
objdump).

Reviewed By: xen0n

Differential Revision: https://reviews.llvm.org/D138100
This commit is contained in:
wanglei 2022-11-18 16:33:49 +08:00
parent 3f63889d58
commit bfa3551dd3
2 changed files with 40 additions and 0 deletions

View File

@ -1348,6 +1348,28 @@ def : InstAlias<"move $dst, $src", (OR GPR:$dst, GPR:$src, R0)>;
def : InstAlias<"ret", (JIRL R0, R1, 0)>;
def : InstAlias<"jr $rj", (JIRL R0, GPR:$rj, 0)>;
// Branches implemented with alias.
// Always output the canonical mnemonic for the pseudo branch instructions.
// The GNU tools emit the canonical mnemonic for the branch pseudo instructions
// as well (e.g. "bgt" will be recognised by the assembler but never printed by
// objdump). Match this behaviour by setting a zero weight.
def : InstAlias<"bgt $rj, $rd, $imm16",
(BLT GPR:$rd, GPR:$rj, simm16_lsl2_br:$imm16), 0>;
def : InstAlias<"bgtu $rj, $rd, $imm16",
(BLTU GPR:$rd, GPR:$rj, simm16_lsl2_br:$imm16), 0>;
def : InstAlias<"ble $rj, $rd, $imm16",
(BGE GPR:$rd, GPR:$rj, simm16_lsl2_br:$imm16), 0>;
def : InstAlias<"bleu $rj, $rd, $imm16",
(BGEU GPR:$rd, GPR:$rj, simm16_lsl2_br:$imm16), 0>;
def : InstAlias<"bltz $rd, $imm16",
(BLT GPR:$rd, R0, simm16_lsl2_br:$imm16), 0>;
def : InstAlias<"bgtz $rj, $imm16",
(BLT R0, GPR:$rj, simm16_lsl2_br:$imm16), 0>;
def : InstAlias<"blez $rj, $imm16",
(BGE R0, GPR:$rj, simm16_lsl2_br:$imm16), 0>;
def : InstAlias<"bgez $rd, $imm16",
(BGE GPR:$rd, R0, simm16_lsl2_br:$imm16), 0>;
//===----------------------------------------------------------------------===//
// Basic Floating-Point Instructions
//===----------------------------------------------------------------------===//

View File

@ -0,0 +1,18 @@
# RUN: llvm-mc --triple=loongarch64 %s | FileCheck %s
bgt $a1, $a0, 16
# CHECK: blt $a0, $a1, 16
bgtu $a1, $a0, 16
# CHECK-NEXT: bltu $a0, $a1, 16
ble $a1, $a0, 16
# CHECK-NEXT: bge $a0, $a1, 16
bleu $a1, $a0, 16
# CHECK-NEXT: bgeu $a0, $a1, 16
bltz $a0, 16
# CHECK-NEXT: blt $a0, $zero, 16
bgtz $a0, 16
# CHECK-NEXT: blt $zero, $a0, 16
blez $a0, 16
# CHECK-NEXT: bge $zero, $a0, 16
bgez $a0, 16
# CHECK-NEXT: bge $a0, $zero, 16