This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] MIPS/GAS: Don't use $zero for address calculation
- From: "Maciej W. Rozycki" <macro at codesourcery dot com>
- To: <binutils at sourceware dot org>
- Cc: Richard Sandiford <rdsandiford at googlemail dot com>
- Date: Tue, 28 May 2013 19:29:59 +0100
- Subject: [PATCH] MIPS/GAS: Don't use $zero for address calculation
Hi,
Here's a fix to make GAS refrain from using $zero for address calculation
in macros like:
lw $0, 0x12345678($2)
that expand to code like:
lui $0, 0x1234
addu $0, $2
lw $0, 22136($0)
that is not functionally equivalent. With the change applied:
lui $1, 0x1234
addu $1, $2
lw $0, 22136($1)
is produced instead (subject to the usual .set at rules). This is covered
for the various macros affected by the test cases included. Some variants
are used to handle the overloaded LD macro in its 64-bit rather than
32-bit mode that is inferred from the ABI on ELF targets and the ISA on
ECOFF targets.
No regressions in testing for the usual MIPS targets, OK to apply?
2013-05-28 Chao-ying Fu <Chao-ying.Fu@imgtec.com>
gas/
* config/tc-mips.c (macro) <ld>: Don't use $zero for address
calculation.
2013-05-28 Maciej W. Rozycki <macro@codesourcery.com>
gas/testsuite/
* gas/mips/ld-zero.d: New test.
* gas/mips/ld-zero-2.d: New test.
* gas/mips/ld-zero-3.d: New test.
* gas/mips/ld-zero-q.d: New test.
* gas/mips/ld-zero-u.d: New test.
* gas/mips/ecoff@ld-zero-3.d: New test.
* gas/mips/micromips@ld-zero-2.d: New test.
* gas/mips/micromips@ld-zero-3.d: New test.
* gas/mips/ld-zero.s: New test source.
* gas/mips/ld-zero-2.s: New test source.
* gas/mips/ld-zero-3.s: New test source.
* gas/mips/ld-zero-q.s: New test source.
* gas/mips/ld-zero-u.s: New test source.
* gas/mips/mips.exp: Run the new tests.
Maciej
binutils-mips-gas-tempreg-zero.diff
Index: binutils-fsf-trunk-quilt/gas/config/tc-mips.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/config/tc-mips.c 2013-05-26 13:50:08.000000000 +0100
+++ binutils-fsf-trunk-quilt/gas/config/tc-mips.c 2013-05-28 17:17:00.903796118 +0100
@@ -8286,7 +8286,8 @@ macro (struct mips_cl_insn *ip)
goto ld_st;
ld:
- if (breg == treg + lp)
+ /* We don't want to use $0 as tempreg. */
+ if ((breg == treg + lp) || (treg + lp == ZERO))
goto ld_st;
else
tempreg = treg + lp;
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ecoff@ld-zero-3.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ecoff@ld-zero-3.d 2013-05-28 17:04:54.312748324 +0100
@@ -0,0 +1,4 @@
+#objdump: -dr --prefix-addresses
+#name: MIPS III load $zero
+#source: ld-zero-3.s
+#dump: ld-zero-3.d
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero-2.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero-2.d 2013-05-28 17:04:54.312748324 +0100
@@ -0,0 +1,11 @@
+#objdump: -dr --prefix-addresses
+#as: -32
+#name: MIPS II load $zero
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+[0-9a-f]+ <[^>]*> lui at,0x1234
+[0-9a-f]+ <[^>]*> addu at,at,v0
+[0-9a-f]+ <[^>]*> ll zero,22136\(at\)
+ \.\.\.
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero-2.s
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero-2.s 2013-05-28 17:04:54.312748324 +0100
@@ -0,0 +1,7 @@
+ .text
+foo:
+ ll $0, 0x12345678($2)
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+ .align 4, 0
+ .space 16
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero-3.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero-3.d 2013-05-28 17:04:54.312748324 +0100
@@ -0,0 +1,17 @@
+#objdump: -dr --prefix-addresses
+#as: -mabi=o64
+#name: MIPS III load $zero
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+[0-9a-f]+ <[^>]*> lui at,0x1234
+[0-9a-f]+ <[^>]*> addu at,at,v0
+[0-9a-f]+ <[^>]*> lwu zero,22136\(at\)
+[0-9a-f]+ <[^>]*> lui at,0x1234
+[0-9a-f]+ <[^>]*> addu at,at,v0
+[0-9a-f]+ <[^>]*> ld zero,22136\(at\)
+[0-9a-f]+ <[^>]*> lui at,0x1234
+[0-9a-f]+ <[^>]*> addu at,at,v0
+[0-9a-f]+ <[^>]*> lld zero,22136\(at\)
+ \.\.\.
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero-3.s
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero-3.s 2013-05-28 17:04:54.312748324 +0100
@@ -0,0 +1,9 @@
+ .text
+foo:
+ lwu $0, 0x12345678($2)
+ ld $0, 0x12345678($2)
+ lld $0, 0x12345678($2)
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+ .align 4, 0
+ .space 16
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero-q.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero-q.d 2013-05-28 17:41:18.593800871 +0100
@@ -0,0 +1,11 @@
+#objdump: -dr --prefix-addresses
+#as: -32
+#name: MIPS R5900 load $zero
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+[0-9a-f]+ <[^>]*> lui at,0x1234
+[0-9a-f]+ <[^>]*> addu at,at,v0
+[0-9a-f]+ <[^>]*> lq zero,22136\(at\)
+ \.\.\.
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero-q.s
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero-q.s 2013-05-28 17:20:02.933802181 +0100
@@ -0,0 +1,7 @@
+ .text
+foo:
+ lq $0, 0x12345678($2)
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+ .align 4, 0
+ .space 16
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero-u.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero-u.d 2013-05-28 17:04:54.312748324 +0100
@@ -0,0 +1,15 @@
+#objdump: -dr --prefix-addresses
+#as: -32
+#name: microMIPS load $zero
+
+.*: +file format .*mips.*
+Disassembly of section \.text:
+[0-9a-f]+ <[^>]*> lui at,0x1234
+[0-9a-f]+ <[^>]*> ori at,at,0x5000
+[0-9a-f]+ <[^>]*> addu at,at,v0
+[0-9a-f]+ <[^>]*> lwp zero,1656\(at\)
+[0-9a-f]+ <[^>]*> lui at,0x1234
+[0-9a-f]+ <[^>]*> ori at,at,0x5000
+[0-9a-f]+ <[^>]*> addu at,at,v0
+[0-9a-f]+ <[^>]*> ldp zero,1656\(at\)
+ \.\.\.
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero-u.s
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero-u.s 2013-05-28 17:04:54.312748324 +0100
@@ -0,0 +1,8 @@
+ .text
+foo:
+ lwp $0, 0x12345678($2)
+ ldp $0, 0x12345678($2)
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+ .align 4, 0
+ .space 16
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero.d 2013-05-28 17:04:54.312748324 +0100
@@ -0,0 +1,23 @@
+#objdump: -dr --prefix-addresses
+#as: -32
+#name: MIPS load $zero
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+[0-9a-f]+ <[^>]*> lui at,0x1234
+[0-9a-f]+ <[^>]*> addu at,at,v0
+[0-9a-f]+ <[^>]*> lb zero,22136\(at\)
+[0-9a-f]+ <[^>]*> lui at,0x1234
+[0-9a-f]+ <[^>]*> addu at,at,v0
+[0-9a-f]+ <[^>]*> lbu zero,22136\(at\)
+[0-9a-f]+ <[^>]*> lui at,0x1234
+[0-9a-f]+ <[^>]*> addu at,at,v0
+[0-9a-f]+ <[^>]*> lh zero,22136\(at\)
+[0-9a-f]+ <[^>]*> lui at,0x1234
+[0-9a-f]+ <[^>]*> addu at,at,v0
+[0-9a-f]+ <[^>]*> lhu zero,22136\(at\)
+[0-9a-f]+ <[^>]*> lui at,0x1234
+[0-9a-f]+ <[^>]*> addu at,at,v0
+[0-9a-f]+ <[^>]*> lw zero,22136\(at\)
+ \.\.\.
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero.s
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/ld-zero.s 2013-05-28 17:04:54.312748324 +0100
@@ -0,0 +1,11 @@
+ .text
+foo:
+ lb $0, 0x12345678($2)
+ lbu $0, 0x12345678($2)
+ lh $0, 0x12345678($2)
+ lhu $0, 0x12345678($2)
+ lw $0, 0x12345678($2)
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+ .align 4, 0
+ .space 16
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/micromips@ld-zero-2.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/micromips@ld-zero-2.d 2013-05-28 17:04:54.312748324 +0100
@@ -0,0 +1,13 @@
+#objdump: -dr --prefix-addresses
+#as: -32
+#name: MIPS II load $zero
+#source: ld-zero-2.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+[0-9a-f]+ <[^>]*> lui at,0x1234
+[0-9a-f]+ <[^>]*> ori at,at,0x5000
+[0-9a-f]+ <[^>]*> addu at,at,v0
+[0-9a-f]+ <[^>]*> ll zero,1656\(at\)
+ \.\.\.
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/micromips@ld-zero-3.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/micromips@ld-zero-3.d 2013-05-28 17:04:54.813831749 +0100
@@ -0,0 +1,21 @@
+#objdump: -dr --prefix-addresses
+#as: -32
+#name: MIPS III load $zero
+#source: ld-zero-3.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+[0-9a-f]+ <[^>]*> lui at,0x1234
+[0-9a-f]+ <[^>]*> ori at,at,0x5000
+[0-9a-f]+ <[^>]*> addu at,at,v0
+[0-9a-f]+ <[^>]*> lwu zero,1656\(at\)
+[0-9a-f]+ <[^>]*> lui at,0x1234
+[0-9a-f]+ <[^>]*> addu at,v0,at
+[0-9a-f]+ <[^>]*> lw zero,22136\(at\)
+[0-9a-f]+ <[^>]*> lw at,22140\(at\)
+[0-9a-f]+ <[^>]*> lui at,0x1234
+[0-9a-f]+ <[^>]*> ori at,at,0x5000
+[0-9a-f]+ <[^>]*> addu at,at,v0
+[0-9a-f]+ <[^>]*> lld zero,1656\(at\)
+ \.\.\.
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips.exp
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/testsuite/gas/mips/mips.exp 2013-05-26 13:50:08.000000000 +0100
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips.exp 2013-05-28 17:33:08.033833129 +0100
@@ -698,6 +698,11 @@ if { [istarget mips*-*-vxworks*] } {
[mips_arch_list_matching mips3 !singlefloat]
}
}
+ run_dump_test_arches "ld-zero" [mips_arch_list_matching mips1]
+ run_dump_test_arches "ld-zero-2" [mips_arch_list_matching mips2 !nollsc]
+ run_dump_test_arches "ld-zero-3" [mips_arch_list_matching mips3 !nollsc]
+ run_dump_test_arches "ld-zero-u" [mips_arch_list_matching micromips]
+ run_dump_test_arches "ld-zero-q" [mips_arch_list_matching r5900]
if $elf { run_dump_test "ld-svr4pic" }
if $elf { run_dump_test "ld-xgot" }
run_dump_test_arches "li" [mips_arch_list_matching mips1]