Commit 9a0ee7b0 by Marc Glisse Committed by Marc Glisse

tree.c (integer_all_onesp): Test that both components are all 1s.

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.

From-SVN: r198649
parent 6698175d
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> 2013-05-06 Oleg Endo <olegendo@gcc.gnu.org>
PR target/52933 PR target/52933
......
...@@ -10870,7 +10870,7 @@ fold_binary_loc (location_t loc, ...@@ -10870,7 +10870,7 @@ fold_binary_loc (location_t loc,
/* Transform x * -1 into -x. Make sure to do the negation /* Transform x * -1 into -x. Make sure to do the negation
on the original operand with conversions not stripped on the original operand with conversions not stripped
because we can only strip non-sign-changing conversions. */ 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)); return fold_convert_loc (loc, type, negate_expr (op0));
/* Transform x * -C into -x * C if x is easily negatable. */ /* Transform x * -C into -x * C if x is easily negatable. */
if (TREE_CODE (arg1) == INTEGER_CST if (TREE_CODE (arg1) == INTEGER_CST
......
...@@ -1781,7 +1781,7 @@ integer_onep (const_tree expr) ...@@ -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 /* 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 int
integer_all_onesp (const_tree expr) integer_all_onesp (const_tree expr)
...@@ -1793,7 +1793,7 @@ integer_all_onesp (const_tree expr) ...@@ -1793,7 +1793,7 @@ integer_all_onesp (const_tree expr)
if (TREE_CODE (expr) == COMPLEX_CST if (TREE_CODE (expr) == COMPLEX_CST
&& integer_all_onesp (TREE_REALPART (expr)) && integer_all_onesp (TREE_REALPART (expr))
&& integer_zerop (TREE_IMAGPART (expr))) && integer_all_onesp (TREE_IMAGPART (expr)))
return 1; return 1;
else if (TREE_CODE (expr) == VECTOR_CST) else if (TREE_CODE (expr) == VECTOR_CST)
...@@ -1839,6 +1839,20 @@ integer_all_onesp (const_tree expr) ...@@ -1839,6 +1839,20 @@ integer_all_onesp (const_tree expr)
return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1; 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 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
one bit on). */ one bit on). */
......
...@@ -5310,6 +5310,11 @@ extern int integer_onep (const_tree); ...@@ -5310,6 +5310,11 @@ extern int integer_onep (const_tree);
extern int integer_all_onesp (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 /* integer_pow2p (tree x) is nonzero is X is an integer constant with
exactly one bit 1. */ exactly one bit 1. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment