x86: re-order optimize_disp()
authorJan Beulich <jbeulich@suse.com>
Fri, 23 Apr 2021 07:16:57 +0000 (09:16 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 23 Apr 2021 07:16:57 +0000 (09:16 +0200)
While I can't point out any specific case where things break, it looks
wrong to have the consumer of a flag before its producer. Set .disp32
first, then do the possible conversion to signed 32-bit, and finally
check whether the value fits in a signed long.

gas/ChangeLog
gas/config/tc-i386.c

index a820eab5122290853587de65b4159f2967d5ad86..669fb6b37429b1880c1b207a69f986e86f77de5e 100644 (file)
@@ -1,3 +1,8 @@
+2021-04-23  Jan Beulich  <jbeulich@suse.com>
+
+       * config/tc-i386.c (optimize_disp): Move down BFD64 section.
+       Move up setting of disp32.
+
 2021-04-23  Jan Beulich  <jbeulich@suse.com>
 
        * config/tc-i386.c (pe): Don't truncate expression value.
index 007d774203a417b691e9fcd0e28db28eeef09856..5180320bcac4a7e72db74f51823350e16e29251b 100644 (file)
@@ -5707,19 +5707,6 @@ optimize_disp (void)
                op_disp = (((op_disp & 0xffff) ^ 0x8000) - 0x8000);
                i.types[op].bitfield.disp64 = 0;
              }
-#ifdef BFD64
-           /* Optimize 64-bit displacement to 32-bit for 64-bit BFD.  */
-           if (i.types[op].bitfield.disp32
-               && (op_disp & ~(((offsetT) 2 << 31) - 1)) == 0)
-             {
-               /* If this operand is at most 32 bits, convert
-                  to a signed 32 bit number and don't use 64bit
-                  displacement.  */
-               op_disp &= (((offsetT) 2 << 31) - 1);
-               op_disp = (op_disp ^ ((offsetT) 1 << 31)) - ((addressT) 1 << 31);
-               i.types[op].bitfield.disp64 = 0;
-             }
-#endif
            if (!op_disp && i.types[op].bitfield.baseindex)
              {
                i.types[op].bitfield.disp8 = 0;
@@ -5730,17 +5717,32 @@ optimize_disp (void)
                i.op[op].disps = 0;
                i.disp_operands--;
              }
+#ifdef BFD64
            else if (flag_code == CODE_64BIT)
              {
+               if (i.prefix[ADDR_PREFIX]
+                   && fits_in_unsigned_long (op_disp))
+                 i.types[op].bitfield.disp32 = 1;
+
+               /* Optimize 64-bit displacement to 32-bit for 64-bit BFD.  */
+               if (i.types[op].bitfield.disp32
+                   && (op_disp & ~(((offsetT) 2 << 31) - 1)) == 0)
+                 {
+                   /* If this operand is at most 32 bits, convert
+                      to a signed 32 bit number and don't use 64bit
+                      displacement.  */
+                   op_disp &= (((offsetT) 2 << 31) - 1);
+                   op_disp = (op_disp ^ ((offsetT) 1 << 31)) - ((addressT) 1 << 31);
+                   i.types[op].bitfield.disp64 = 0;
+                 }
+
                if (fits_in_signed_long (op_disp))
                  {
                    i.types[op].bitfield.disp64 = 0;
                    i.types[op].bitfield.disp32s = 1;
                  }
-               if (i.prefix[ADDR_PREFIX]
-                   && fits_in_unsigned_long (op_disp))
-                 i.types[op].bitfield.disp32 = 1;
              }
+#endif
            if ((i.types[op].bitfield.disp32
                 || i.types[op].bitfield.disp32s
                 || i.types[op].bitfield.disp16)