This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 2/3] x86: optimize away pointless segment overrides


When optimizing there's no point keeping the segment overrides when
warning about their presence in the first place.

gas/
2020-02-XX  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.

--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -7198,10 +7198,17 @@ duplicate:
     }
 
   if ((i.seg[0] || i.prefix[SEG_PREFIX])
-      && !quiet_warnings
       && ((i.tm.base_opcode == 0x8d && !is_any_vex_encoding(&i.tm)) /* lea */
           || ((i.tm.base_opcode | 0x010001) == 0xf30f1b) /* bnd{c[lnu],mk} */))
-    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
--- a/gas/testsuite/gas/i386/i386.exp
+++ b/gas/testsuite/gas/i386/i386.exp
@@ -505,6 +505,7 @@ if [expr ([istarget "i*86-*-*"] ||  [ist
     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"
--- /dev/null
+++ b/gas/testsuite/gas/i386/lea-optimize.d
@@ -0,0 +1,21 @@
+#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
+[ 	]*[0-9a-f]+:[ 	]+f3 0f 1a 00[ 	]+bndcl[ 	]+\(%eax\),%bnd0
+[ 	]*[0-9a-f]+:[ 	]+f3 0f 1a 00[ 	]+bndcl[ 	]+\(%eax\),%bnd0
+[ 	]*[0-9a-f]+:[ 	]+f2 0f 1b 00[ 	]+bndcn[ 	]+\(%eax\),%bnd0
+[ 	]*[0-9a-f]+:[ 	]+f2 0f 1b 00[ 	]+bndcn[ 	]+\(%eax\),%bnd0
+[ 	]*[0-9a-f]+:[ 	]+f2 0f 1a 00[ 	]+bndcu[ 	]+\(%eax\),%bnd0
+[ 	]*[0-9a-f]+:[ 	]+f2 0f 1a 00[ 	]+bndcu[ 	]+\(%eax\),%bnd0
+[ 	]*[0-9a-f]+:[ 	]+f3 0f 1b 00[ 	]+bndmk[ 	]+\(%eax\),%bnd0
+[ 	]*[0-9a-f]+:[ 	]+f3 0f 1b 00[ 	]+bndmk[ 	]+\(%eax\),%bnd0
+#pass


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]