* config/i386/i386-protos.h (x86_maybe_negate_const_int): Declare.
authoruros <uros@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 6 Apr 2010 18:18:42 +0000 (18:18 +0000)
committeruros <uros@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 6 Apr 2010 18:18:42 +0000 (18:18 +0000)
* config/i386/i386.c (x86_maybe_negate_const_int): New.
(x86_output_mi_thunk): Use x86_maybe_negate_const_int.
* config/i386/i386.md (*add<mode>_1, *addsi_1_zext, *addhi_1,
*addhi_1_lea, *addqi_1, *addqi_1_lea, *addqi_1_slp, *add<mode>_2,
*addsi_2_zext, *addhi_2, *addqi_2, *add<mode>_3, *addsi_3_zext,
*addhi_3, *addqi_3,*add<mode>_5, *addhi_5, *addqi_5):
Use x86_maybe_negate_const_int to output insn mnemonic.
(*adddi_4, *addsi_4, *addhi_4, *addqi_4): Ditto.  Remove overflow
check from instruction predicate.  Update comments.
* config/i386/sync.md (sync_add<mode>): Use
x86_maybe_negate_const_int to output insn mnemonic.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@158013 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/config/i386/i386-protos.h
gcc/config/i386/i386.c
gcc/config/i386/i386.md
gcc/config/i386/sync.md

index a05b595..a958473 100644 (file)
@@ -1,12 +1,28 @@
-2010-04-06  Jan Hubicka  <jh@suse.czpli
+2010-04-06  Uros Bizjak  <ubizjak@gmail.com>
+
+       * config/i386/i386-protos.h (x86_maybe_negate_const_int): Declare.
+       * config/i386/i386.c (x86_maybe_negate_const_int): New.
+       (x86_output_mi_thunk): Use x86_maybe_negate_const_int.
+       * config/i386/i386.md (*add<mode>_1, *addsi_1_zext, *addhi_1,
+       *addhi_1_lea, *addqi_1, *addqi_1_lea, *addqi_1_slp, *add<mode>_2,
+       *addsi_2_zext, *addhi_2, *addqi_2, *add<mode>_3, *addsi_3_zext,
+       *addhi_3, *addqi_3,*add<mode>_5, *addhi_5, *addqi_5):
+       Use x86_maybe_negate_const_int to output insn mnemonic.
+       (*adddi_4, *addsi_4, *addhi_4, *addqi_4): Ditto.  Remove overflow
+       check from instruction predicate.  Update comments.
+       * config/i386/sync.md (sync_add<mode>): Use
+       x86_maybe_negate_const_int to output insn mnemonic.
 
-       PR tree-optimization/42906
 
-       * tree-ssa-dce.c (mark_control_dependent_edges_necessary): Add IGNORE_SELF
-       argument; set visited_control_parents for fully processed BBs.
+2010-04-06  Jan Hubicka  <jh@suse.cz>
+
+       PR tree-optimization/42906
+       * tree-ssa-dce.c (mark_control_dependent_edges_necessary): Add
+       IGNORE_SELF argument.  Set visited_control_parents for fully
+       processed BBs.
        (find_obviously_necessary_stmts): Update call of
        mark_control_dependent_edges_necessary.
-       (propagate_necessity): Likewise; handle PHI edges more curefully.
+       (propagate_necessity): Likewise.  Handle PHI edges more curefully.
 
 2010-04-06  Uros Bizjak  <ubizjak@gmail.com>
 
@@ -52,7 +68,7 @@
 
 2010-04-02  Steven Bosscher  <steven@gcc.gnu.org>
 
-       * ada/gcc-interface/Make-lang.in, alias.c, attribs.c, auto-inc-dec.c, 
+       * ada/gcc-interface/Make-lang.in, alias.c, attribs.c, auto-inc-dec.c,
        basic-block.h, bb-reorder.c, calls.c, c-common.c, cgraph.h,
        collect2.h, config/alpha/alpha.c, config/alpha/alpha.md,
        config/alpha/predicates.md, config/arm/arm.md,
 2010-04-02  Richard Earnshaw  <rearnsha@arm.com>
 
        PR target/43469
-       * arm.c (legitimize_tls_address): Adjust call to 
+       * arm.c (legitimize_tls_address): Adjust call to
        gen_tls_load_dot_plus_four.
        (arm_note_pic_base): New function.
        (arm_cannot_copy_insn_p): Use it.
 
 2010-02-15  Nick Clifton  <nickc@redhat.com>
 
-       * config/h8300/h8300.c: (h8300_push_pop): Use bool type for
+       * config/h8300/h8300.c (h8300_push_pop): Use bool type for
        boolean parameters.  Use emit_jump_insn when emitting a pop
        instruction containing a return insn.
        (push): Use 'true' rather than '1' as second parameter to F.
index d0dd8ca..5c6140d 100644 (file)
@@ -44,6 +44,7 @@ extern int symbolic_reference_mentioned_p (rtx);
 extern bool extended_reg_mentioned_p (rtx);
 extern bool x86_extended_QIreg_mentioned_p (rtx);
 extern bool x86_extended_reg_mentioned_p (rtx);
+extern bool x86_maybe_negate_const_int (rtx *, enum machine_mode);
 extern enum machine_mode ix86_cc_mode (enum rtx_code, rtx, rtx);
 
 extern int avx_vpermilp_parallel (rtx par, enum machine_mode mode);
index cfd2270..d498b47 100644 (file)
@@ -26202,10 +26202,7 @@ x86_output_mi_thunk (FILE *file,
   /* Adjust the this parameter by a fixed constant.  */
   if (delta)
     {
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
-         Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      bool sub = delta < 0 || delta == 128;
-      xops[0] = GEN_INT (sub ? -delta : delta);
+      xops[0] = GEN_INT (delta);
       xops[1] = this_reg ? this_reg : this_param;
       if (TARGET_64BIT)
        {
@@ -26217,12 +26214,12 @@ x86_output_mi_thunk (FILE *file,
              xops[0] = tmp;
              xops[1] = this_param;
            }
-         if (sub)
+         if (x86_maybe_negate_const_int (&xops[0], DImode))
            output_asm_insn ("sub{q}\t{%0, %1|%1, %0}", xops);
          else
            output_asm_insn ("add{q}\t{%0, %1|%1, %0}", xops);
        }
-      else if (sub)
+      else if (x86_maybe_negate_const_int (&xops[0], SImode))
        output_asm_insn ("sub{l}\t{%0, %1|%1, %0}", xops);
       else
        output_asm_insn ("add{l}\t{%0, %1|%1, %0}", xops);
@@ -26649,6 +26646,52 @@ x86_extended_reg_mentioned_p (rtx insn)
                       extended_reg_mentioned_1, NULL);
 }
 
+/* If profitable, negate (without causing overflow) integer constant
+   of mode MODE at location LOC.  Return true in this case.  */
+bool
+x86_maybe_negate_const_int (rtx *loc, enum machine_mode mode)
+{
+  HOST_WIDE_INT val;
+
+  if (!CONST_INT_P (*loc))
+    return false;
+
+  switch (mode)
+    {
+    case DImode:
+      /* DImode x86_64 constants must fit in 32 bits.  */
+      gcc_assert (x86_64_immediate_operand (*loc, mode));
+
+      mode = SImode;
+      break;
+
+    case SImode:
+    case HImode:
+    case QImode:
+      break;
+
+    default:
+      gcc_unreachable ();
+    }
+
+  /* Avoid overflows.  */
+  if (mode_signbit_p (mode, *loc))
+    return false;
+
+  val = INTVAL (*loc);
+
+  /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
+     Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
+  if ((val < 0 && val != -128)
+      || val == 128)
+    {
+      *loc = GEN_INT (-val);
+      return true;
+    }
+
+  return false;
+}
+
 /* Generate an unsigned DImode/SImode to FP conversion.  This is the same code
    optabs would emit if we didn't have TFmode patterns.  */
 
index 376d10e..8bd8e0f 100644 (file)
         return "add{<imodesuffix>}\t{%1, %0|%0, %1}";
         
       gcc_assert (rtx_equal_p (operands[0], operands[1]));
+      if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
+        return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
 
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-         /* Avoid overflows.  */
-         && (<MODE>mode != DImode
-             || ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1))))
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-        {
-          operands[2] = GEN_INT (-INTVAL (operands[2]));
-          return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
-        }
       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-        {
-          operands[2] = GEN_INT (-INTVAL (operands[2]));
-          return "sub{l}\t{%2, %k0|%k0, %2}";
-        }
+      if (x86_maybe_negate_const_int (&operands[2], SImode))
+        return "sub{l}\t{%2, %k0|%k0, %2}";
+
       return "add{l}\t{%2, %k0|%k0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-       {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
-         return "sub{w}\t{%2, %0|%0, %2}";
-       }
+      if (x86_maybe_negate_const_int (&operands[2], HImode))
+       return "sub{w}\t{%2, %0|%0, %2}";
+
       return "add{w}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-       {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
-         return "sub{w}\t{%2, %0|%0, %2}";
-       }
+      if (x86_maybe_negate_const_int (&operands[2], HImode))
+       return "sub{w}\t{%2, %0|%0, %2}";
+
       return "add{w}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
+      if (x86_maybe_negate_const_int (&operands[2], QImode))
        {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
          if (widen)
            return "sub{l}\t{%2, %k0|%k0, %2}";
          else
        }
 
     default:
-      /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
+      if (x86_maybe_negate_const_int (&operands[2], QImode))
        {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
          if (widen)
            return "sub{l}\t{%2, %k0|%k0, %2}";
          else
        }
 
     default:
-      /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.  */
-      if (CONST_INT_P (operands[1])
-         && INTVAL (operands[1]) < 0)
-       {
-         operands[1] = GEN_INT (-INTVAL (operands[1]));
-         return "sub{b}\t{%1, %0|%0, %1}";
-       }
+      if (x86_maybe_negate_const_int (&operands[1], QImode))
+       return "sub{b}\t{%1, %0|%0, %1}";
+
       return "add{b}\t{%1, %0|%0, %1}";
     }
 }
       gcc_assert (rtx_equal_p (operands[0], operands[1]));
       /* ???? In DImode, we ought to handle there the 32bit case too
         - do we need new constraint?  */
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-         /* Avoid overflows.  */
-         && (<MODE>mode != DImode
-             || ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1))))
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-        {
-          operands[2] = GEN_INT (-INTVAL (operands[2]));
-          return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
-        }
+      if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
+        return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
+
       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-        {
-          operands[2] = GEN_INT (-INTVAL (operands[2]));
-          return "sub{l}\t{%2, %k0|%k0, %2}";
-        }
+      if (x86_maybe_negate_const_int (&operands[2], SImode))
+        return "sub{l}\t{%2, %k0|%k0, %2}";
+
       return "add{l}\t{%2, %k0|%k0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-       {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
-         return "sub{w}\t{%2, %0|%0, %2}";
-       }
+      if (x86_maybe_negate_const_int (&operands[2], HImode))
+       return "sub{w}\t{%2, %0|%0, %2}";
+
       return "add{w}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.  */
-      if (CONST_INT_P (operands[2])
-          && INTVAL (operands[2]) < 0)
-       {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
-         return "sub{b}\t{%2, %0|%0, %2}";
-       }
+      if (x86_maybe_negate_const_int (&operands[2], QImode))
+       return "sub{b}\t{%2, %0|%0, %2}";
+
       return "add{b}\t{%2, %0|%0, %2}";
     }
 }
       gcc_assert (rtx_equal_p (operands[0], operands[1]));
       /* ???? In DImode, we ought to handle there the 32bit case too
         - do we need new constraint?  */
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-         /* Avoid overflows.  */
-         && (<MODE>mode != DImode
-             || ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1))))
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-        {
-          operands[2] = GEN_INT (-INTVAL (operands[2]));
-          return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
-        }
+      if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
+        return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
+
       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-        {
-          operands[2] = GEN_INT (-INTVAL (operands[2]));
-          return "sub{l}\t{%2, %k0|%k0, %2}";
-        }
+      if (x86_maybe_negate_const_int (&operands[2], SImode))
+        return "sub{l}\t{%2, %k0|%k0, %2}";
+
       return "add{l}\t{%2, %k0|%k0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-       {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
-         return "sub{w}\t{%2, %0|%0, %2}";
-       }
+      if (x86_maybe_negate_const_int (&operands[2], HImode))
+       return "sub{w}\t{%2, %0|%0, %2}";
+
       return "add{w}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.  */
-      if (CONST_INT_P (operands[2])
-          && INTVAL (operands[2]) < 0)
-       {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
-         return "sub{b}\t{%2, %0|%0, %2}";
-       }
+      if (x86_maybe_negate_const_int (&operands[2], QImode))
+       return "sub{b}\t{%2, %0|%0, %2}";
+
       return "add{b}\t{%2, %0|%0, %2}";
     }
 }
 ; by converting cmp to add, inc or dec as done by peephole2.  This pattern
 ; is matched then.  We can't accept general immediate, because for
 ; case of overflows,  the result is messed up.
-; This pattern also don't hold of 0x8000000000000000, since the value
-; overflows when negated.
 ; Also carry flag is reversed compared to cmp, so this conversion is valid
 ; only for comparisons not depending on it.
 
 
     default:
       gcc_assert (rtx_equal_p (operands[0], operands[1]));
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if ((INTVAL (operands[2]) == -128
-          || (INTVAL (operands[2]) > 0
-              && INTVAL (operands[2]) != 128))
-         /* Avoid overflows.  */
-         && ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1))))
-       return "sub{q}\t{%2, %0|%0, %2}";
-      operands[2] = GEN_INT (-INTVAL (operands[2]));
-      return "add{q}\t{%2, %0|%0, %2}";
+      if (x86_maybe_negate_const_int (&operands[2], DImode))
+       return "add{q}\t{%2, %0|%0, %2}";
+
+      return "sub{q}\t{%2, %0|%0, %2}";
     }
 }
   [(set (attr "type")
 ; by converting cmp to add, inc or dec as done by peephole2.  This pattern
 ; is matched then.  We can't accept general immediate, because for
 ; case of overflows,  the result is messed up.
-; This pattern also don't hold of 0x80000000, since the value overflows
-; when negated.
 ; Also carry flag is reversed compared to cmp, so this conversion is valid
 ; only for comparisons not depending on it.
 
          (match_operand:SI 1 "nonimmediate_operand" "0")
          (match_operand:SI 2 "const_int_operand" "n")))
    (clobber (match_scratch:SI 0 "=rm"))]
-  "ix86_match_ccmode (insn, CCGCmode)
-   && (INTVAL (operands[2]) & 0xffffffff) != 0x80000000"
+  "ix86_match_ccmode (insn, CCGCmode)"
 {
   switch (get_attr_type (insn))
     {
 
     default:
       gcc_assert (rtx_equal_p (operands[0], operands[1]));
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if ((INTVAL (operands[2]) == -128
-          || (INTVAL (operands[2]) > 0
-              && INTVAL (operands[2]) != 128)))
-       return "sub{l}\t{%2, %0|%0, %2}";
-      operands[2] = GEN_INT (-INTVAL (operands[2]));
-      return "add{l}\t{%2, %0|%0, %2}";
+      if (x86_maybe_negate_const_int (&operands[2], SImode))
+       return "add{l}\t{%2, %0|%0, %2}";
+
+      return "sub{l}\t{%2, %0|%0, %2}";
     }
 }
   [(set (attr "type")
          (match_operand:HI 1 "nonimmediate_operand" "0")
          (match_operand:HI 2 "const_int_operand" "n")))
    (clobber (match_scratch:HI 0 "=rm"))]
-  "ix86_match_ccmode (insn, CCGCmode)
-   && (INTVAL (operands[2]) & 0xffff) != 0x8000"
+  "ix86_match_ccmode (insn, CCGCmode)"
 {
   switch (get_attr_type (insn))
     {
 
     default:
       gcc_assert (rtx_equal_p (operands[0], operands[1]));
-      /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if ((INTVAL (operands[2]) == -128
-          || (INTVAL (operands[2]) > 0
-              && INTVAL (operands[2]) != 128)))
-       return "sub{w}\t{%2, %0|%0, %2}";
-      operands[2] = GEN_INT (-INTVAL (operands[2]));
-      return "add{w}\t{%2, %0|%0, %2}";
+      if (x86_maybe_negate_const_int (&operands[2], HImode))
+       return "add{w}\t{%2, %0|%0, %2}";
+
+      return "sub{w}\t{%2, %0|%0, %2}";
     }
 }
   [(set (attr "type")
          (match_operand:QI 1 "nonimmediate_operand" "0")
          (match_operand:QI 2 "const_int_operand" "n")))
    (clobber (match_scratch:QI 0 "=qm"))]
-  "ix86_match_ccmode (insn, CCGCmode)
-   && (INTVAL (operands[2]) & 0xff) != 0x80"
+  "ix86_match_ccmode (insn, CCGCmode)"
 {
   switch (get_attr_type (insn))
     {
 
     default:
       gcc_assert (rtx_equal_p (operands[0], operands[1]));
-      if (INTVAL (operands[2]) < 0)
-        {
-          operands[2] = GEN_INT (-INTVAL (operands[2]));
-          return "add{b}\t{%2, %0|%0, %2}";
-        }
+      if (x86_maybe_negate_const_int (&operands[2], QImode))
+       return "add{b}\t{%2, %0|%0, %2}";
+
       return "sub{b}\t{%2, %0|%0, %2}";
     }
 }
 
     default:
       gcc_assert (rtx_equal_p (operands[0], operands[1]));
-      /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-         /* Avoid overflows.  */
-         && (<MODE>mode != DImode
-             || ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1))))
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-        {
-          operands[2] = GEN_INT (-INTVAL (operands[2]));
-          return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
-        }
+      if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
+        return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
+
       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
-        Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
-      if (CONST_INT_P (operands[2])
-          && (INTVAL (operands[2]) == 128
-             || (INTVAL (operands[2]) < 0
-                 && INTVAL (operands[2]) != -128)))
-       {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
-         return "sub{w}\t{%2, %0|%0, %2}";
-       }
+      if (x86_maybe_negate_const_int (&operands[2], HImode))
+       return "sub{w}\t{%2, %0|%0, %2}";
+
       return "add{w}\t{%2, %0|%0, %2}";
     }
 }
        }
 
     default:
-      /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.  */
-      if (CONST_INT_P (operands[2])
-          && INTVAL (operands[2]) < 0)
-       {
-         operands[2] = GEN_INT (-INTVAL (operands[2]));
-         return "sub{b}\t{%2, %0|%0, %2}";
-       }
+      if (x86_maybe_negate_const_int (&operands[2], QImode))
+       return "sub{b}\t{%2, %0|%0, %2}";
+
       return "add{b}\t{%2, %0|%0, %2}";
     }
 }
index 0df85c7..feea161 100644 (file)
        return "lock{%;| }dec{<imodesuffix>}\t%0";
     }
 
+  if (x86_maybe_negate_const_int (&operands[1], <MODE>mode))
+    return "lock{%;| }sub{<imodesuffix>}\t{%1, %0|%0, %1}";
+
   return "lock{%;| }add{<imodesuffix>}\t{%1, %0|%0, %1}";
 })