mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-02-22 13:29:32 +08:00
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:
parent
5190a458bb
commit
2d9474dfd2
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
25
gcc/testsuite/gcc.dg/fold-mod-1.c
Normal file
25
gcc/testsuite/gcc.dg/fold-mod-1.c
Normal 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" } } */
|
Loading…
Reference in New Issue
Block a user