[binutils-gdb] MIPS/GAS: Discard redundant instruction from DDIV/DREM macros

Maciej W. Rozycki macro@sourceware.org
Sun Sep 15 14:29:19 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c26846ab066fc6e3a2843cbadfe159e0c4a1cc21

commit c26846ab066fc6e3a2843cbadfe159e0c4a1cc21
Author: Maciej W. Rozycki <macro@orcam.me.uk>
Date:   Sun Sep 15 15:28:18 2024 +0100

    MIPS/GAS: Discard redundant instruction from DDIV/DREM macros
    
    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.

Diff:
---
 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(-)

diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c
index 28d3ed839a4..576ef1fb21f 100644
--- a/gas/config/tc-mips.c
+++ b/gas/config/tc-mips.c
@@ -10831,13 +10831,10 @@ macro (struct mips_cl_insn *ip, char *str)
       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
diff --git a/gas/testsuite/gas/mips/div64-trap.d b/gas/testsuite/gas/mips/div64-trap.d
index eab1975dd7a..48e4947b1bc 100644
--- a/gas/testsuite/gas/mips/div64-trap.d
+++ b/gas/testsuite/gas/mips/div64-trap.d
@@ -11,8 +11,7 @@ Disassembly of section \.text:
 [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
diff --git a/gas/testsuite/gas/mips/div64.d b/gas/testsuite/gas/mips/div64.d
index 926cdb69031..2c6b343b694 100644
--- a/gas/testsuite/gas/mips/div64.d
+++ b/gas/testsuite/gas/mips/div64.d
@@ -11,8 +11,7 @@ Disassembly of section \.text:
 [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
diff --git a/gas/testsuite/gas/mips/micromips-compact.d b/gas/testsuite/gas/mips/micromips-compact.d
index 34f61862faa..ca3451b40aa 100644
--- a/gas/testsuite/gas/mips/micromips-compact.d
+++ b/gas/testsuite/gas/mips/micromips-compact.d
@@ -6523,7 +6523,6 @@ Disassembly of section \.text:
 [ 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 @@ Disassembly of section \.text:
 [ 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 @@ Disassembly of section \.text:
 [ 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	.*
diff --git a/gas/testsuite/gas/mips/micromips-insn32.d b/gas/testsuite/gas/mips/micromips-insn32.d
index f4282ffc51f..e7851345080 100644
--- a/gas/testsuite/gas/mips/micromips-insn32.d
+++ b/gas/testsuite/gas/mips/micromips-insn32.d
@@ -6547,7 +6547,6 @@ Disassembly of section \.text:
 [ 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 @@ Disassembly of section \.text:
 [ 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 @@ Disassembly of section \.text:
 [ 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	.*
diff --git a/gas/testsuite/gas/mips/micromips-noinsn32.d b/gas/testsuite/gas/mips/micromips-noinsn32.d
index 75bfaf7db35..3fa9a0613a1 100644
--- a/gas/testsuite/gas/mips/micromips-noinsn32.d
+++ b/gas/testsuite/gas/mips/micromips-noinsn32.d
@@ -6524,7 +6524,6 @@ Disassembly of section \.text:
 [ 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 @@ Disassembly of section \.text:
 [ 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 @@ Disassembly of section \.text:
 [ 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	.*
diff --git a/gas/testsuite/gas/mips/micromips-trap.d b/gas/testsuite/gas/mips/micromips-trap.d
index 68f5a028684..0be6e289848 100644
--- a/gas/testsuite/gas/mips/micromips-trap.d
+++ b/gas/testsuite/gas/mips/micromips-trap.d
@@ -6526,7 +6526,6 @@ Disassembly of section \.text:
 [ 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 @@ Disassembly of section \.text:
 [ 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 @@ Disassembly of section \.text:
 [ 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
 
diff --git a/gas/testsuite/gas/mips/micromips.d b/gas/testsuite/gas/mips/micromips.d
index 86511b94cb4..4d965106321 100644
--- a/gas/testsuite/gas/mips/micromips.d
+++ b/gas/testsuite/gas/mips/micromips.d
@@ -6602,7 +6602,6 @@ Disassembly of section \.text:
 [ 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 @@ Disassembly of section \.text:
 [ 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 @@ Disassembly of section \.text:
 [ 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	.*
diff --git a/gas/testsuite/gas/mips/micromips@div64-trap.d b/gas/testsuite/gas/mips/micromips@div64-trap.d
index e4e5e680b86..6839401d327 100644
--- a/gas/testsuite/gas/mips/micromips@div64-trap.d
+++ b/gas/testsuite/gas/mips/micromips@div64-trap.d
@@ -13,7 +13,6 @@ Disassembly of section \.text:
 [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
diff --git a/gas/testsuite/gas/mips/micromips@div64.d b/gas/testsuite/gas/mips/micromips@div64.d
index 07abe647995..af7fc2c08d4 100644
--- a/gas/testsuite/gas/mips/micromips@div64.d
+++ b/gas/testsuite/gas/mips/micromips@div64.d
@@ -15,7 +15,6 @@ Disassembly of section \.text:
 [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
diff --git a/gas/testsuite/gas/mips/mips3@div64-trap.d b/gas/testsuite/gas/mips/mips3@div64-trap.d
index 568fbd49e5e..33196f3837d 100644
--- a/gas/testsuite/gas/mips/mips3@div64-trap.d
+++ b/gas/testsuite/gas/mips/mips3@div64-trap.d
@@ -11,8 +11,7 @@ Disassembly of section \.text:
 [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
diff --git a/gas/testsuite/gas/mips/mips3@div64.d b/gas/testsuite/gas/mips/mips3@div64.d
index cbb0af49e44..ec0f03ecf18 100644
--- a/gas/testsuite/gas/mips/mips3@div64.d
+++ b/gas/testsuite/gas/mips/mips3@div64.d
@@ -12,8 +12,7 @@ Disassembly of section \.text:
 [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-cvs mailing list