[binutils-gdb] x86: minor improvements to optimize_imm()

Jan Beulich jbeulich@sourceware.org
Fri May 7 10:03:21 GMT 2021


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

commit 87ed972dc348404a4f8b820efa8dc79aaaa966f2
Author: Jan Beulich <jbeulich@suse.com>
Date:   Fri May 7 12:02:07 2021 +0200

    x86: minor improvements to optimize_imm()
    
    - Drop a pointless & where just before it was checked that the
      respective bits are clear already anyway.
    - Avoid a not really necessary operand_type_set() and a redundant
      operand_type_or() / operand_type_and() pair.

Diff:
---
 gas/ChangeLog        |  5 +++++
 gas/config/tc-i386.c | 14 ++++++--------
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 790951ad932..ad82f9b3c75 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,8 @@
+2021-05-07  Jan Beulich  <jbeulich@suse.com>
+
+	* config/tc-i386.c (optimize_imm): Drop redundant masking.
+	Re-arrange operand type accumulation.
+
 2021-05-06  Stafford Horne  <shorne@gmail.com>
 
 	PR 21464
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 5d5897fdb2b..c09d63f5e21 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -5791,8 +5791,8 @@ optimize_imm (void)
 	    if ((i.types[op].bitfield.imm16)
 		&& (i.op[op].imms->X_add_number & ~(offsetT) 0xffff) == 0)
 	      {
-		i.op[op].imms->X_add_number =
-		  (((i.op[op].imms->X_add_number & 0xffff) ^ 0x8000) - 0x8000);
+		i.op[op].imms->X_add_number = ((i.op[op].imms->X_add_number
+						^ 0x8000) - 0x8000);
 	      }
 #ifdef BFD64
 	    /* Store 32-bit immediate in 64-bit for 64-bit BFD.  */
@@ -5826,17 +5826,15 @@ optimize_imm (void)
 	       than those matching the insn suffix.  */
 	    {
 	      i386_operand_type mask, allowed;
-	      const insn_template *t;
+	      const insn_template *t = current_templates->start;
 
 	      operand_type_set (&mask, 0);
-	      operand_type_set (&allowed, 0);
+	      allowed = t->operand_types[op];
 
-	      for (t = current_templates->start;
-		   t < current_templates->end;
-		   ++t)
+	      while (++t < current_templates->end)
 		{
-		  allowed = operand_type_or (allowed, t->operand_types[op]);
 		  allowed = operand_type_and (allowed, anyimm);
+		  allowed = operand_type_or (allowed, t->operand_types[op]);
 		}
 	      switch (guess_suffix)
 		{


More information about the Binutils-cvs mailing list