diff options
author | James A. Morrison <phython@gcc.gnu.org> | 2005-06-18 19:57:12 +0000 |
---|---|---|
committer | James A. Morrison <phython@gcc.gnu.org> | 2005-06-18 19:57:12 +0000 |
commit | 5b017a9e8de0329e1955a2d7c56513f99ae455a6 (patch) | |
tree | 9030eac2ba4b6f77300c26c535cf1365cacfaf7f /gcc/fold-const.c | |
parent | 6fa3dd65caaa95982f123c70f77b36bbb9b29a5a (diff) |
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: https://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.c | 10 |
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; |