]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
MIPS/GAS: Omit LI 0 for condition trap
authorYunQiang Su <syq@gcc.gnu.org>
Wed, 19 Jun 2024 16:52:25 +0000 (00:52 +0800)
committerYunQiang Su <syq@debian.org>
Fri, 12 Jul 2024 10:19:35 +0000 (18:19 +0800)
MIPSr6 removes condition trap instructions with imm, so we expand
the instruction like "tne $2,IMM" to
li $at,IMM
tne $2,$at
While if IMM is 0, we can use
tne $2,$zero
only.

gas/config/tc-mips.c
gas/testsuite/gas/mips/cond-trap-imm-zero.d [new file with mode: 0644]
gas/testsuite/gas/mips/cond-trap-imm-zero.s [new file with mode: 0644]
gas/testsuite/gas/mips/mips.exp

index 8f54cb8937af379e07a83ab431d5c1239dbe148c..863f56d5f8cfb0b961f5e90e5b9fd3ef58ed8313 100644 (file)
@@ -13815,9 +13815,14 @@ macro (struct mips_cl_insn *ip, char *str)
     case M_TNE_I:
       s = "tne";
     trap:
-      used_at = 1;
-      load_register (AT, &imm_expr, GPR_SIZE == 64);
-      macro_build (NULL, s, "s,t", op[0], AT);
+      if (imm_expr.X_add_number != 0)
+       {
+         used_at = 1;
+         load_register (AT, &imm_expr, GPR_SIZE == 64);
+         macro_build (NULL, s, "s,t", op[0], AT);
+       }
+      else
+         macro_build (NULL, s, "s,t", op[0], ZERO);
       break;
 
     case M_TRUNCWS:
diff --git a/gas/testsuite/gas/mips/cond-trap-imm-zero.d b/gas/testsuite/gas/mips/cond-trap-imm-zero.d
new file mode 100644 (file)
index 0000000..39d4c96
--- /dev/null
@@ -0,0 +1,16 @@
+#objdump: -dr
+#name: Condition Trap convert IMM0 to REG0 (MIPSr6)
+#as: -32
+
+.*: +file format .*
+
+Disassembly of section \.text:
+
+00000000 <f>:
+   0:  00c00034        teq     a2,zero
+   4:  00c00030        tge     a2,zero
+   8:  00c00031        tgeu    a2,zero
+   c:  00c00032        tlt     a2,zero
+  10:  00c00033        tltu    a2,zero
+  14:  00c00036        tne     a2,zero
+       \.\.\.
diff --git a/gas/testsuite/gas/mips/cond-trap-imm-zero.s b/gas/testsuite/gas/mips/cond-trap-imm-zero.s
new file mode 100644 (file)
index 0000000..84cc7f1
--- /dev/null
@@ -0,0 +1,9 @@
+        .set    noreorder
+        .set    nomacro
+f:
+        teq    $6,0
+        tge    $6,0
+        tgeu   $6,0
+       tlt     $6,0
+       tltu    $6,0
+        tne    $6,0
index acb7fb8c2a6fa9a0d247b86e32fbed0a4f01d05a..c5d74538bd63a27c4b25b7c119fdca38ffa7c21a 100644 (file)
@@ -2180,4 +2180,6 @@ if { [istarget mips*-*-vxworks*] } {
     if [istarget *-*-irix*] {
       run_dump_test "irix-no-pdr"
     }
+
+    run_dump_test_arches "cond-trap-imm-zero" [mips_arch_list_matching mips32r6]
 }