Commit 2d9474df by James A. Morrison

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
parent 5190a458
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> 2005-06-18 Uros Bizjak <uros@kss-loka.si>
* doc/md.texi (Standard Names): Change insn pattern name * doc/md.texi (Standard Names): Change insn pattern name
......
...@@ -8337,11 +8337,11 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) ...@@ -8337,11 +8337,11 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
&& TREE_INT_CST_HIGH (arg1) == -1) && TREE_INT_CST_HIGH (arg1) == -1)
return omit_one_operand (type, integer_zero_node, arg0); return omit_one_operand (type, integer_zero_node, arg0);
/* Optimize unsigned TRUNC_MOD_EXPR by a power of two into a /* Optimize TRUNC_MOD_EXPR by a power of two into a BIT_AND_EXPR,
BIT_AND_EXPR, i.e. "X % C" into "X & C2". */ i.e. "X % C" into "X & C2", if X and C are positive. */
if (code == TRUNC_MOD_EXPR if ((code == TRUNC_MOD_EXPR || code == FLOOR_MOD_EXPR)
&& TYPE_UNSIGNED (type) && (TYPE_UNSIGNED (type) || tree_expr_nonnegative_p (arg0))
&& integer_pow2p (arg1)) && integer_pow2p (arg1) && tree_int_cst_sgn (arg1) >= 0)
{ {
unsigned HOST_WIDE_INT high, low; unsigned HOST_WIDE_INT high, low;
tree mask; tree mask;
......
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> 2005-06-18 Steven G. Kargl <kargls@comcast.net>
PR fortran/19926 PR fortran/19926
......
/* { 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" } } */
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