[PATCH] D138100: [LoongArch] Implement assembler branches pseudo instructions
wanglei via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 16 00:26:39 PST 2022
wangleiat created this revision.
wangleiat added reviewers: SixWeining, xen0n, xry111, gonglingqin, XiaodongLoong, MaskRay.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
wangleiat requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D138100
Files:
llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
llvm/test/MC/LoongArch/Macros/aliases-br.s
Index: llvm/test/MC/LoongArch/Macros/aliases-br.s
===================================================================
--- /dev/null
+++ 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
Index: llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
===================================================================
--- llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
+++ llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
@@ -1348,6 +1348,28 @@
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
//===----------------------------------------------------------------------===//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138100.475708.patch
Type: text/x-patch
Size: 2420 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221116/735c923c/attachment.bin>
More information about the llvm-commits
mailing list