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
This commit is contained in:
James A. Morrison 2005-06-18 19:57:12 +00:00
parent 5190a458bb
commit 2d9474dfd2
4 changed files with 39 additions and 5 deletions

View File

@ -1,3 +1,8 @@
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.
2005-06-18 Uros Bizjak <uros@kss-loka.si>
* doc/md.texi (Standard Names): Change insn pattern name

View File

@ -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;

View File

@ -1,3 +1,7 @@
2005-06-18 James A Morrison <phython@gcc.gnu.org>
* gcc.dg/fold-mod-1.c: New test.
2005-06-18 Steven G. Kargl <kargls@comcast.net>
PR fortran/19926

View File

@ -0,0 +1,25 @@
/* { dg-do compile } */
/* { dg-options "-fdump-tree-gimple" } */
#define ABS(x) (x > 0 ? x : -x)
unsigned int f (unsigned int a) {
/* (unsigned)-8 is not a power of 2. */
return a % -8;
}
int g (int b) {
return ABS (b) % -8;
}
int h (int c) {
return ABS (c) % 8;
}
unsigned int k (unsigned int d) {
return d % 8;
}
/* { dg-final { scan-tree-dump "a % 4294967288" "gimple" } } */
/* { dg-final { scan-tree-dump-times " & 7" 3 "gimple" } } */
/* { dg-final { cleanup-tree-dump "gimple" } } */