[committed 2/2] MIPS/GAS: Discard redundant instruction from DDIV/DREM macros
Maciej W. Rozycki
macro@orcam.me.uk
Sun Sep 15 14:29:33 GMT 2024
A sequence such as:
li at,-1
bne xx,at,0f
li at,1
dsll32 at,at,0x1f
is produced in the expansion of the DDIV and DREM assembly macros, where
a redundant `li at,1' instruction is used to load an intermediate value
of 1 into $at, which is then left-shifted by 63 with `dsll32 at,at,0x1f'
yielding 0x8000000000000000. However this value likewise results from
left-shifting the value of -1, already present in $at at this point.
Remove the extraneous instruction then, shortening the sequence emitted.
Adjust dumps in the testsuite accordingly.
---
gas/config/tc-mips.c | 5 +----
gas/testsuite/gas/mips/div64-trap.d | 3 +--
gas/testsuite/gas/mips/div64.d | 3 +--
gas/testsuite/gas/mips/micromips-compact.d | 3 ---
gas/testsuite/gas/mips/micromips-insn32.d | 3 ---
gas/testsuite/gas/mips/micromips-noinsn32.d | 3 ---
gas/testsuite/gas/mips/micromips-trap.d | 3 ---
gas/testsuite/gas/mips/micromips.d | 3 ---
gas/testsuite/gas/mips/micromips@div64-trap.d | 1 -
gas/testsuite/gas/mips/micromips@div64.d | 1 -
gas/testsuite/gas/mips/mips3@div64-trap.d | 3 +--
gas/testsuite/gas/mips/mips3@div64.d | 3 +--
12 files changed, 5 insertions(+), 29 deletions(-)
binutils-mips-gas-ddiv-drem-overflow.diff
Index: binutils-gdb/gas/config/tc-mips.c
===================================================================
--- binutils-gdb.orig/gas/config/tc-mips.c
+++ binutils-gdb/gas/config/tc-mips.c
@@ -10831,13 +10831,10 @@ macro (struct mips_cl_insn *ip, char *st
if (mips_opts.micromips)
micromips_label_expr (&label_expr);
else
- label_expr.X_add_number = (mips_use_trap ()
- ? (dbl ? 12 : 8) : (dbl ? 20 : 16));
+ label_expr.X_add_number = mips_use_trap () ? 8 : 16;
macro_build (&label_expr, "bne", "s,t,p", op[2], AT);
if (dbl)
{
- expr1.X_add_number = 1;
- load_register (AT, &expr1, dbl);
macro_build (NULL, "dsll32", SHFT_FMT, AT, AT, 31);
}
else
Index: binutils-gdb/gas/testsuite/gas/mips/div64-trap.d
===================================================================
--- binutils-gdb.orig/gas/testsuite/gas/mips/div64-trap.d
+++ binutils-gdb/gas/testsuite/gas/mips/div64-trap.d
@@ -11,8 +11,7 @@
[0-9a-f]+ <[^>]*> 00c001f4 teq a2,zero,0x7
[0-9a-f]+ <[^>]*> 00a6001e ddiv zero,a1,a2
[0-9a-f]+ <[^>]*> 2401ffff li at,-1
-[0-9a-f]+ <[^>]*> 14c10003 bne a2,at,[0-9a-f]+ <[^>]*>
-[0-9a-f]+ <[^>]*> 24010001 li at,1
+[0-9a-f]+ <[^>]*> 14c10002 bne a2,at,[0-9a-f]+ <[^>]*>
[0-9a-f]+ <[^>]*> 00010ffc dsll32 at,at,0x1f
[0-9a-f]+ <[^>]*> 00a101b4 teq a1,at,0x6
[0-9a-f]+ <[^>]*> 00002012 mflo a0
Index: binutils-gdb/gas/testsuite/gas/mips/div64.d
===================================================================
--- binutils-gdb.orig/gas/testsuite/gas/mips/div64.d
+++ binutils-gdb/gas/testsuite/gas/mips/div64.d
@@ -11,8 +11,7 @@
[0-9a-f]+ <[^>]*> 00a6001e ddiv zero,a1,a2
[0-9a-f]+ <[^>]*> 0007000d break 0x7
[0-9a-f]+ <[^>]*> 2401ffff li at,-1
-[0-9a-f]+ <[^>]*> 14c10005 bne a2,at,[0-9a-f]+ <[^>]*>
-[0-9a-f]+ <[^>]*> 24010001 li at,1
+[0-9a-f]+ <[^>]*> 14c10004 bne a2,at,[0-9a-f]+ <[^>]*>
[0-9a-f]+ <[^>]*> 00010ffc dsll32 at,at,0x1f
[0-9a-f]+ <[^>]*> 14a10002 bne a1,at,[0-9a-f]+ <[^>]*>
[0-9a-f]+ <[^>]*> 00000000 nop
Index: binutils-gdb/gas/testsuite/gas/mips/micromips-compact.d
===================================================================
--- binutils-gdb.orig/gas/testsuite/gas/mips/micromips-compact.d
+++ binutils-gdb/gas/testsuite/gas/mips/micromips-compact.d
@@ -6523,7 +6523,6 @@
[ 0-9a-f]+: 3020 ffff li at,-1
[ 0-9a-f]+: b424 fffe bne a0,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
-[ 0-9a-f]+: 3020 0001 li at,1
[ 0-9a-f]+: 5821 f808 dsll32 at,at,0x1f
[ 0-9a-f]+: b423 fffe bne v1,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
@@ -6960,7 +6959,6 @@
[ 0-9a-f]+: 3020 ffff li at,-1
[ 0-9a-f]+: b423 fffe bne v1,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
-[ 0-9a-f]+: 3020 0001 li at,1
[ 0-9a-f]+: 5821 f808 dsll32 at,at,0x1f
[ 0-9a-f]+: b420 fffe bne zero,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
@@ -6978,7 +6976,6 @@
[ 0-9a-f]+: 3020 ffff li at,-1
[ 0-9a-f]+: b43f fffe bne ra,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
-[ 0-9a-f]+: 3020 0001 li at,1
[ 0-9a-f]+: 5821 f808 dsll32 at,at,0x1f
[ 0-9a-f]+: b420 fffe bne zero,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
Index: binutils-gdb/gas/testsuite/gas/mips/micromips-insn32.d
===================================================================
--- binutils-gdb.orig/gas/testsuite/gas/mips/micromips-insn32.d
+++ binutils-gdb/gas/testsuite/gas/mips/micromips-insn32.d
@@ -6547,7 +6547,6 @@
[ 0-9a-f]+: 3020 ffff li at,-1
[ 0-9a-f]+: b424 fffe bne a0,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
-[ 0-9a-f]+: 3020 0001 li at,1
[ 0-9a-f]+: 5821 f808 dsll32 at,at,0x1f
[ 0-9a-f]+: b423 fffe bne v1,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
@@ -6984,7 +6983,6 @@
[ 0-9a-f]+: 3020 ffff li at,-1
[ 0-9a-f]+: b423 fffe bne v1,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
-[ 0-9a-f]+: 3020 0001 li at,1
[ 0-9a-f]+: 5821 f808 dsll32 at,at,0x1f
[ 0-9a-f]+: b420 fffe bne zero,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
@@ -7002,7 +7000,6 @@
[ 0-9a-f]+: 3020 ffff li at,-1
[ 0-9a-f]+: b43f fffe bne ra,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
-[ 0-9a-f]+: 3020 0001 li at,1
[ 0-9a-f]+: 5821 f808 dsll32 at,at,0x1f
[ 0-9a-f]+: b420 fffe bne zero,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
Index: binutils-gdb/gas/testsuite/gas/mips/micromips-noinsn32.d
===================================================================
--- binutils-gdb.orig/gas/testsuite/gas/mips/micromips-noinsn32.d
+++ binutils-gdb/gas/testsuite/gas/mips/micromips-noinsn32.d
@@ -6524,7 +6524,6 @@
[ 0-9a-f]+: 3020 ffff li at,-1
[ 0-9a-f]+: b424 fffe bne a0,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
-[ 0-9a-f]+: 3020 0001 li at,1
[ 0-9a-f]+: 5821 f808 dsll32 at,at,0x1f
[ 0-9a-f]+: b423 fffe bne v1,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
@@ -6961,7 +6960,6 @@
[ 0-9a-f]+: 3020 ffff li at,-1
[ 0-9a-f]+: b423 fffe bne v1,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
-[ 0-9a-f]+: 3020 0001 li at,1
[ 0-9a-f]+: 5821 f808 dsll32 at,at,0x1f
[ 0-9a-f]+: b420 fffe bne zero,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
@@ -6979,7 +6977,6 @@
[ 0-9a-f]+: 3020 ffff li at,-1
[ 0-9a-f]+: b43f fffe bne ra,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
-[ 0-9a-f]+: 3020 0001 li at,1
[ 0-9a-f]+: 5821 f808 dsll32 at,at,0x1f
[ 0-9a-f]+: b420 fffe bne zero,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
Index: binutils-gdb/gas/testsuite/gas/mips/micromips-trap.d
===================================================================
--- binutils-gdb.orig/gas/testsuite/gas/mips/micromips-trap.d
+++ binutils-gdb/gas/testsuite/gas/mips/micromips-trap.d
@@ -6526,7 +6526,6 @@
[ 0-9a-f]+: 3020 ffff li at,-1
[ 0-9a-f]+: b424 fffe bne a0,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
-[ 0-9a-f]+: 3020 0001 li at,1
[ 0-9a-f]+: 5821 f808 dsll32 at,at,0x1f
[ 0-9a-f]+: 0023 603c teq v1,at,0x6
@@ -6928,7 +6927,6 @@
[ 0-9a-f]+: 3020 ffff li at,-1
[ 0-9a-f]+: b423 fffe bne v1,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
-[ 0-9a-f]+: 3020 0001 li at,1
[ 0-9a-f]+: 5821 f808 dsll32 at,at,0x1f
[ 0-9a-f]+: 0020 603c teq zero,at,0x6
@@ -6939,7 +6937,6 @@
[ 0-9a-f]+: 3020 ffff li at,-1
[ 0-9a-f]+: b43f fffe bne ra,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
-[ 0-9a-f]+: 3020 0001 li at,1
[ 0-9a-f]+: 5821 f808 dsll32 at,at,0x1f
[ 0-9a-f]+: 0020 603c teq zero,at,0x6
Index: binutils-gdb/gas/testsuite/gas/mips/micromips.d
===================================================================
--- binutils-gdb.orig/gas/testsuite/gas/mips/micromips.d
+++ binutils-gdb/gas/testsuite/gas/mips/micromips.d
@@ -6602,7 +6602,6 @@
[ 0-9a-f]+: 3020 ffff li at,-1
[ 0-9a-f]+: b424 fffe bne a0,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
-[ 0-9a-f]+: 3020 0001 li at,1
[ 0-9a-f]+: 5821 f808 dsll32 at,at,0x1f
[ 0-9a-f]+: b423 fffe bne v1,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
@@ -7039,7 +7038,6 @@
[ 0-9a-f]+: 3020 ffff li at,-1
[ 0-9a-f]+: b423 fffe bne v1,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
-[ 0-9a-f]+: 3020 0001 li at,1
[ 0-9a-f]+: 5821 f808 dsll32 at,at,0x1f
[ 0-9a-f]+: b420 fffe bne zero,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
@@ -7057,7 +7055,6 @@
[ 0-9a-f]+: 3020 ffff li at,-1
[ 0-9a-f]+: b43f fffe bne ra,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
-[ 0-9a-f]+: 3020 0001 li at,1
[ 0-9a-f]+: 5821 f808 dsll32 at,at,0x1f
[ 0-9a-f]+: b420 fffe bne zero,at,[0-9a-f]+ <.*\+0x[0-9a-f]+>
[ ]*[0-9a-f]+: R_MICROMIPS_PC16_S1 .*
Index: binutils-gdb/gas/testsuite/gas/mips/micromips@div64-trap.d
===================================================================
--- binutils-gdb.orig/gas/testsuite/gas/mips/micromips@div64-trap.d
+++ binutils-gdb/gas/testsuite/gas/mips/micromips@div64-trap.d
@@ -13,7 +13,6 @@
[0-9a-f]+ <[^>]*> 3020 ffff li at,-1
[0-9a-f]+ <[^>]*> b426 fffe bne a2,at,[0-9a-f]+ <[^>]*>
[0-9a-f]+: R_MICROMIPS_PC16_S1 \.L\^_0
-[0-9a-f]+ <[^>]*> 3020 0001 li at,1
[0-9a-f]+ <[^>]*> 5821 f808 dsll32 at,at,0x1f
[0-9a-f]+ <[^>]*> 0025 603c teq a1,at,0x6
[0-9a-f]+ <\.L\^_0> 4644 mflo a0
Index: binutils-gdb/gas/testsuite/gas/mips/micromips@div64.d
===================================================================
--- binutils-gdb.orig/gas/testsuite/gas/mips/micromips@div64.d
+++ binutils-gdb/gas/testsuite/gas/mips/micromips@div64.d
@@ -15,7 +15,6 @@
[0-9a-f]+ <\.L\^_0> 3020 ffff li at,-1
[0-9a-f]+ <[^>]*> b426 fffe bne a2,at,[0-9a-f]+ <[^>]*>
[0-9a-f]+: R_MICROMIPS_PC16_S1 \.L\^_1
-[0-9a-f]+ <[^>]*> 3020 0001 li at,1
[0-9a-f]+ <[^>]*> 5821 f808 dsll32 at,at,0x1f
[0-9a-f]+ <[^>]*> b425 fffe bne a1,at,[0-9a-f]+ <[^>]*>
[0-9a-f]+: R_MICROMIPS_PC16_S1 \.L\^_1
Index: binutils-gdb/gas/testsuite/gas/mips/mips3@div64-trap.d
===================================================================
--- binutils-gdb.orig/gas/testsuite/gas/mips/mips3@div64-trap.d
+++ binutils-gdb/gas/testsuite/gas/mips/mips3@div64-trap.d
@@ -11,8 +11,7 @@
[0-9a-f]+ <[^>]*> 00c001f4 teq a2,zero,0x7
[0-9a-f]+ <[^>]*> 00a6001e ddiv zero,a1,a2
[0-9a-f]+ <[^>]*> 2401ffff li at,-1
-[0-9a-f]+ <[^>]*> 14c10003 bne a2,at,[0-9a-f]+ <[^>]*>
-[0-9a-f]+ <[^>]*> 24010001 li at,1
+[0-9a-f]+ <[^>]*> 14c10002 bne a2,at,[0-9a-f]+ <[^>]*>
[0-9a-f]+ <[^>]*> 00010ffc dsll32 at,at,0x1f
[0-9a-f]+ <[^>]*> 00a101b4 teq a1,at,0x6
[0-9a-f]+ <[^>]*> 00002012 mflo a0
Index: binutils-gdb/gas/testsuite/gas/mips/mips3@div64.d
===================================================================
--- binutils-gdb.orig/gas/testsuite/gas/mips/mips3@div64.d
+++ binutils-gdb/gas/testsuite/gas/mips/mips3@div64.d
@@ -12,8 +12,7 @@
[0-9a-f]+ <[^>]*> 00a6001e ddiv zero,a1,a2
[0-9a-f]+ <[^>]*> 0007000d break 0x7
[0-9a-f]+ <[^>]*> 2401ffff li at,-1
-[0-9a-f]+ <[^>]*> 14c10005 bne a2,at,[0-9a-f]+ <[^>]*>
-[0-9a-f]+ <[^>]*> 24010001 li at,1
+[0-9a-f]+ <[^>]*> 14c10004 bne a2,at,[0-9a-f]+ <[^>]*>
[0-9a-f]+ <[^>]*> 00010ffc dsll32 at,at,0x1f
[0-9a-f]+ <[^>]*> 14a10002 bne a1,at,[0-9a-f]+ <[^>]*>
[0-9a-f]+ <[^>]*> 00000000 nop
More information about the Binutils
mailing list