2014-12-01 Richard Biener <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 1 Dec 2014 13:08:10 +0000 (13:08 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 1 Dec 2014 13:08:10 +0000 (13:08 +0000)
PR middle-end/64126
* match.pd: Allow conversions in ~A + 1 -> -A, add -A - 1 -> ~A
and -1 - A -> ~A.
* fold-const.c (fold_binary_loc): Remove transforms here.

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

gcc/ChangeLog
gcc/fold-const.c
gcc/match.pd

index c31d8bc..d696865 100644 (file)
@@ -1,3 +1,10 @@
+2014-12-01  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/64126
+       * match.pd: Allow conversions in ~A + 1 -> -A, add -A - 1 -> ~A
+       and -1 - A -> ~A.
+       * fold-const.c (fold_binary_loc): Remove transforms here.
+
 2014-12-01  Maciej W. Rozycki  <macro@codesourcery.com>
 
        * config/mips/mips.c (mips16_build_call_stub): Move the save of
index 486ca19..51f3e2f 100644 (file)
@@ -10391,19 +10391,6 @@ fold_binary_loc (location_t loc,
                                              negate_expr (arg1)),
                            fold_convert_loc (loc, type,
                                              TREE_OPERAND (arg0, 0)));
-      /* Convert -A - 1 to ~A.  */
-      if (TREE_CODE (arg0) == NEGATE_EXPR
-         && integer_each_onep (arg1)
-         && !TYPE_OVERFLOW_TRAPS (type))
-       return fold_build1_loc (loc, BIT_NOT_EXPR, type,
-                           fold_convert_loc (loc, type,
-                                             TREE_OPERAND (arg0, 0)));
-
-      /* Convert -1 - A to ~A.  */
-      if (TREE_CODE (type) != COMPLEX_TYPE
-         && integer_all_onesp (arg0))
-       return fold_build1_loc (loc, BIT_NOT_EXPR, type, op1);
-
 
       /* X - (X / Y) * Y is X % Y.  */
       if ((INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type))
index 01f610c..42e7c62 100644 (file)
@@ -484,8 +484,22 @@ along with GCC; see the file COPYING3.  If not see
 
   /* ~A + 1 -> -A */
   (simplify
-   (plus (bit_not @0) integer_each_onep)
-   (negate @0))
+   (plus (convert? (bit_not @0)) integer_each_onep)
+   (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
+    (negate (convert @0))))
+
+  /* -A - 1 -> ~A */
+  (simplify
+   (minus (convert? (negate @0)) integer_each_onep)
+   (if (!TYPE_OVERFLOW_TRAPS (type)
+       && tree_nop_conversion_p (type, TREE_TYPE (@0)))
+    (bit_not (convert @0))))
+
+  /* -1 - A -> ~A */
+  (simplify
+   (minus integer_all_onesp @0)
+   (if (TREE_CODE (type) != COMPLEX_TYPE)
+    (bit_not @0)))
 
   /* (T)(P + A) - (T)P -> (T) A */
   (for add (plus pointer_plus)