aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Glisse <marc.glisse@inria.fr>2013-05-06 21:14:59 +0000
committerMarc Glisse <marc.glisse@inria.fr>2013-05-06 21:14:59 +0000
commit261f584df76987d64a79a0a6a16abc011a82fecb (patch)
tree7d9d8b97ec358bd6267025f8446e73231ebbc98e
parentb39bbba3d89b0bfc2993c8d82861050e6545d0bd (diff)
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. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@198649 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/fold-const.c2
-rw-r--r--gcc/tree.c18
-rw-r--r--gcc/tree.h5
4 files changed, 31 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 09108c32ab2..d813433e124 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index f93ce8a7e26..74b451e470a 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -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
diff --git a/gcc/tree.c b/gcc/tree.c
index d8f2424a1ef..444c87673d7 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -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). */
diff --git a/gcc/tree.h b/gcc/tree.h
index be43440783d..2b6f13b8f12 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -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. */