2013-05-06 Marc Glisse <marc.glisse@inria.fr>
authorglisse <glisse@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 6 May 2013 21:14:59 +0000 (21:14 +0000)
committerglisse <glisse@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 6 May 2013 21:14:59 +0000 (21:14 +0000)
* tree.c (integer_all_onesp) <COMPLEX_CST>: Test that both
components are all 1s.
(integer_minus_onep): New function.
* tree.h (integer_minus_onep): Declare it.
* fold-const.c (fold_binary_loc) <MULT_EXPR>: Test
integer_minus_onep instead of integer_all_onesp.

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

gcc/ChangeLog
gcc/fold-const.c
gcc/tree.c
gcc/tree.h

index 09108c3..d813433 100644 (file)
@@ -1,3 +1,12 @@
+2013-05-06  Marc Glisse  <marc.glisse@inria.fr>
+
+       * tree.c (integer_all_onesp) <COMPLEX_CST>: Test that both
+       components are all 1s.
+       (integer_minus_onep): New function.
+       * tree.h (integer_minus_onep): Declare it.
+       * fold-const.c (fold_binary_loc) <MULT_EXPR>: Test
+       integer_minus_onep instead of integer_all_onesp.
+
 2013-05-06  Oleg Endo  <olegendo@gcc.gnu.org>
 
        PR target/52933
index f93ce8a..74b451e 100644 (file)
@@ -10870,7 +10870,7 @@ fold_binary_loc (location_t loc,
          /* Transform x * -1 into -x.  Make sure to do the negation
             on the original operand with conversions not stripped
             because we can only strip non-sign-changing conversions.  */
-         if (integer_all_onesp (arg1))
+         if (integer_minus_onep (arg1))
            return fold_convert_loc (loc, type, negate_expr (op0));
          /* Transform x * -C into -x * C if x is easily negatable.  */
          if (TREE_CODE (arg1) == INTEGER_CST
index d8f2424..444c876 100644 (file)
@@ -1781,7 +1781,7 @@ integer_onep (const_tree expr)
 }
 
 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
-   it contains.  Likewise for the corresponding complex constant.  */
+   it contains, or a complex or vector whose subparts are such integers.  */
 
 int
 integer_all_onesp (const_tree expr)
@@ -1793,7 +1793,7 @@ integer_all_onesp (const_tree expr)
 
   if (TREE_CODE (expr) == COMPLEX_CST
       && integer_all_onesp (TREE_REALPART (expr))
-      && integer_zerop (TREE_IMAGPART (expr)))
+      && integer_all_onesp (TREE_IMAGPART (expr)))
     return 1;
 
   else if (TREE_CODE (expr) == VECTOR_CST)
@@ -1839,6 +1839,20 @@ integer_all_onesp (const_tree expr)
     return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
 }
 
+/* Return 1 if EXPR is the integer constant minus one.  */
+
+int
+integer_minus_onep (const_tree expr)
+{
+  STRIP_NOPS (expr);
+
+  if (TREE_CODE (expr) == COMPLEX_CST)
+    return (integer_all_onesp (TREE_REALPART (expr))
+           && integer_zerop (TREE_IMAGPART (expr)));
+  else
+    return integer_all_onesp (expr);
+}
+
 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
    one bit on).  */
 
index be43440..2b6f13b 100644 (file)
@@ -5310,6 +5310,11 @@ extern int integer_onep (const_tree);
 
 extern int integer_all_onesp (const_tree);
 
+/* integer_minus_onep (tree x) is nonzero if X is an integer constant of
+   value -1.  */
+
+extern int integer_minus_onep (const_tree);
+
 /* integer_pow2p (tree x) is nonzero is X is an integer constant with
    exactly one bit 1.  */