[llvm] bfa3551 - [LoongArch] Implement assembler branches pseudo instructions

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 18 00:54:35 PST 2022


Author: wanglei
Date: 2022-11-18T16:54:20+08:00
New Revision: bfa3551dd3ac2d8aba42f2c8cb296ea0494e679a

URL: https://github.com/llvm/llvm-project/commit/bfa3551dd3ac2d8aba42f2c8cb296ea0494e679a
DIFF: https://github.com/llvm/llvm-project/commit/bfa3551dd3ac2d8aba42f2c8cb296ea0494e679a.diff

LOG: [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

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

Modified: 
    llvm/lib/Target/LoongArch/LoongArchInstrInfo.td

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/LoongArch/LoongArchInstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
index 2a8fc40f984ab..885c4d75f0b91 100644
--- a/llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
+++ b/llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
@@ -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
 //===----------------------------------------------------------------------===//

diff  --git a/llvm/test/MC/LoongArch/Macros/aliases-br.s b/llvm/test/MC/LoongArch/Macros/aliases-br.s
new file mode 100644
index 0000000000000..e8d85bdec763b
--- /dev/null
+++ b/llvm/test/MC/LoongArch/Macros/aliases-br.s
@@ -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


        


More information about the llvm-commits mailing list