]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86: optimize away pointless segment overrides
authorJan Beulich <jbeulich@suse.com>
Fri, 14 Feb 2020 13:03:19 +0000 (14:03 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 14 Feb 2020 13:03:19 +0000 (14:03 +0100)
When optimizing there's no point keeping the segment overrides when we
warn about their presence in the first place.

gas/ChangeLog
gas/config/tc-i386.c
gas/testsuite/gas/i386/i386.exp
gas/testsuite/gas/i386/lea-optimize.d [new file with mode: 0644]

index 4f1aeed7c7c158a6acc618a3b848d3e7849d63b8..0cbd2a5bbffaadcc72e8a2e1ced80c0ac239efe5 100644 (file)
@@ -1,4 +1,11 @@
-2020-02-XX  Jan Beulich  <jbeulich@suse.com>
+2020-02-14  Jan Beulich  <jbeulich@suse.com>
+
+       * config/tc-i386.c (process_operands): Drop ineffectual segment
+       overrides when optimizing.
+       * testsuite/gas/i386/lea-optimize.d: New.
+       * testsuite/gas/i386/i386.exp: Run new test.
+
+2020-02-14  Jan Beulich  <jbeulich@suse.com>
 
        * config/tc-i386.c (process_operands): Also check insn prefix
        for ineffectual segment override warning. Don't cover possible
index 05151f2a6363d603a69e8ca34c1005bca05d3adb..d7d45de76e0f7af5bb61fbde10292cdce29a4db3 100644 (file)
@@ -7165,10 +7165,17 @@ duplicate:
     }
 
   if ((i.seg[0] || i.prefix[SEG_PREFIX])
-      && !quiet_warnings
       && i.tm.base_opcode == 0x8d /* lea */
       && !is_any_vex_encoding(&i.tm))
-    as_warn (_("segment override on `%s' is ineffectual"), i.tm.name);
+    {
+      if (!quiet_warnings)
+       as_warn (_("segment override on `%s' is ineffectual"), i.tm.name);
+      if (optimize)
+       {
+         i.seg[0] = NULL;
+         i.prefix[SEG_PREFIX] = 0;
+       }
+    }
 
   /* If a segment was explicitly specified, and the specified segment
      is not the default, use an opcode prefix to select it.  If we
index 147297e22f2a3a955154519e9beac4adab107d88..258fb763360d2f244563ea48f810c8f9996348e9 100644 (file)
@@ -502,6 +502,7 @@ if [expr ([istarget "i*86-*-*"] ||  [istarget "x86_64-*-*"]) && [gas_32_check]]
     run_list_test "optimize-6a" "-I${srcdir}/$subdir -march=+noavx -al"
     run_dump_test "optimize-6b"
     run_list_test "optimize-7" "-I${srcdir}/$subdir -march=+noavx2 -al"
+    run_dump_test "lea-optimize"
     run_dump_test "align-branch-1a"
     run_dump_test "align-branch-1b"
     run_dump_test "align-branch-1c"
diff --git a/gas/testsuite/gas/i386/lea-optimize.d b/gas/testsuite/gas/i386/lea-optimize.d
new file mode 100644 (file)
index 0000000..16e5b82
--- /dev/null
@@ -0,0 +1,13 @@
+#as: -O -q
+#objdump: -dw
+#name: i386 LEA-like segment overrride dropping
+#source: lea.s
+
+.*: +file format .*
+
+Disassembly of section .text:
+
+0+ <start>:
+[      ]*[0-9a-f]+:[   ]+8d 00[        ]+lea[  ]+\(%eax\),%eax
+[      ]*[0-9a-f]+:[   ]+8d 00[        ]+lea[  ]+\(%eax\),%eax
+#pass