fold-const.c (negate_expr_p): Return true for BIT_NOT_EXPR.
authorAndrew Pinski <pinskia@physics.uc.edu>
Tue, 29 Nov 2005 15:26:21 +0000 (15:26 +0000)
committerAndrew Pinski <pinskia@gcc.gnu.org>
Tue, 29 Nov 2005 15:26:21 +0000 (07:26 -0800)
2005-11-29  Andrew Pinski  <pinskia@physics.uc.edu>

        * fold-const.c (negate_expr_p): Return true for BIT_NOT_EXPR.
        (fold_unary) <case NEGATE_EXPR>: Move -(~a) transformation to ...
        (negate_expr): Here.

From-SVN: r107671

gcc/ChangeLog
gcc/fold-const.c

index 081455fe63ba5518ca86235088d8548ddc8dc8c6..8a736655b6f7b8e8c0c670727cfaf02696fb6509 100644 (file)
@@ -1,3 +1,9 @@
+2005-11-29  Andrew Pinski  <pinskia@physics.uc.edu>
+
+       * fold-const.c (negate_expr_p): Return true for BIT_NOT_EXPR.
+       (fold_unary) <case NEGATE_EXPR>: Move -(~a) transformation to ...
+       (negate_expr): Here.
+
 2005-11-29  Ben Elliston  <bje@au.ibm.com>
 
        * config/i386/i386.h (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN):
index 2d80e66eb05f08fdaf671e0b8c6e152d64053658..2718af1490ff3e22411c55ecc4f4538706aa7114 100644 (file)
@@ -953,6 +953,8 @@ negate_expr_p (tree t)
 
       /* Check that -CST will not overflow type.  */
       return may_negate_without_overflow_p (t);
+    case BIT_NOT_EXPR:
+       return INTEGRAL_TYPE_P (type);
 
     case REAL_CST:
     case NEGATE_EXPR:
@@ -1052,6 +1054,12 @@ negate_expr (tree t)
 
   switch (TREE_CODE (t))
     {
+    /* Convert - (~A) to A + 1.  */
+    case BIT_NOT_EXPR:
+      if (INTEGRAL_TYPE_P (type))
+        return fold_build2 (PLUS_EXPR, type, TREE_OPERAND (t, 0),
+                            build_int_cst (type, 1));
+      
     case INTEGER_CST:
       tem = fold_negate_const (t, type);
       if (! TREE_OVERFLOW (tem)
@@ -7030,10 +7038,6 @@ fold_unary (enum tree_code code, tree type, tree op0)
     case NEGATE_EXPR:
       if (negate_expr_p (arg0))
        return fold_convert (type, negate_expr (arg0));
-      /* Convert - (~A) to A + 1.  */
-      if (INTEGRAL_TYPE_P (type) && TREE_CODE (arg0) == BIT_NOT_EXPR)
-       return fold_build2 (PLUS_EXPR, type, TREE_OPERAND (arg0, 0),
-                           build_int_cst (type, 1));
       return NULL_TREE;
 
     case ABS_EXPR: