summaryrefslogtreecommitdiffstats
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorphython <phython@138bc75d-0d04-0410-961f-82ee72b054a4>2005-06-18 19:57:12 +0000
committerphython <phython@138bc75d-0d04-0410-961f-82ee72b054a4>2005-06-18 19:57:12 +0000
commitc44b9c58374637dd7b300bc52255a81ac120217b (patch)
tree9030eac2ba4b6f77300c26c535cf1365cacfaf7f /gcc/fold-const.c
parentbc05520ee63bef7816312ec85f923478b04cceba (diff)
downloadppe42-gcc-c44b9c58374637dd7b300bc52255a81ac120217b.tar.gz
ppe42-gcc-c44b9c58374637dd7b300bc52255a81ac120217b.zip
2005-06-18 James A. Morrison <phython@gcc.gnu.org>
* fold_const (fold_binary): Fold X % (2**N) to X & (2**N - 1) for nonnegative values of X. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@101163 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 8433d1dfd98..335e556f5e9 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8337,11 +8337,11 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
&& TREE_INT_CST_HIGH (arg1) == -1)
return omit_one_operand (type, integer_zero_node, arg0);
- /* Optimize unsigned TRUNC_MOD_EXPR by a power of two into a
- BIT_AND_EXPR, i.e. "X % C" into "X & C2". */
- if (code == TRUNC_MOD_EXPR
- && TYPE_UNSIGNED (type)
- && integer_pow2p (arg1))
+ /* Optimize TRUNC_MOD_EXPR by a power of two into a BIT_AND_EXPR,
+ i.e. "X % C" into "X & C2", if X and C are positive. */
+ if ((code == TRUNC_MOD_EXPR || code == FLOOR_MOD_EXPR)
+ && (TYPE_UNSIGNED (type) || tree_expr_nonnegative_p (arg0))
+ && integer_pow2p (arg1) && tree_int_cst_sgn (arg1) >= 0)
{
unsigned HOST_WIDE_INT high, low;
tree mask;
OpenPOWER on IntegriCloud