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 | 2d9474dfd2b300d6a10b541ef5a282759a1ca190 (patch) | |
tree | 9030eac2ba4b6f77300c26c535cf1365cacfaf7f /gcc/fold-const.c | |
parent | 5190a458bbace7bd99887361bc7e9f05112908dd (diff) | |
download | gcc-2d9474dfd2b300d6a10b541ef5a282759a1ca190.zip gcc-2d9474dfd2b300d6a10b541ef5a282759a1ca190.tar.gz gcc-2d9474dfd2b300d6a10b541ef5a282759a1ca190.tar.bz2 |
fold_const (fold_binary): Fold X % (2**N) to X & (2**N - 1) for nonnegative values of X.
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.
From-SVN: r101163
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 8433d1d..335e556 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; |