fold-const.c (fold_binary_loc): New transformation.
2010-10-20 Dmitry Melnik <dm@ispras.ru> gcc/ * fold-const.c (fold_binary_loc): New transformation. gcc/testsuite/ * gcc.dg/20101013-1.c: New test. From-SVN: r165720
This commit is contained in:
parent
b9121f42a1
commit
2298ade7e5
4 changed files with 44 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
|||
2010-10-20 Dmitry Melnik <dm@ispras.ru>
|
||||
|
||||
* fold-const.c (fold_binary_loc): New transformation.
|
||||
|
||||
2010-10-20 H.J. Lu <hongjiu.lu@intel.com>
|
||||
|
||||
PR target/46085
|
||||
|
|
|
@ -11599,6 +11599,31 @@ fold_binary_loc (location_t loc,
|
|||
return NULL_TREE;
|
||||
|
||||
case TRUNC_DIV_EXPR:
|
||||
/* Optimize (X & (-A)) / A where A is a power of 2,
|
||||
to X >> log2(A) */
|
||||
if (TREE_CODE (arg0) == BIT_AND_EXPR
|
||||
&& !TYPE_UNSIGNED (type) && TREE_CODE (arg1) == INTEGER_CST
|
||||
&& integer_pow2p (arg1) && tree_int_cst_sgn (arg1) > 0)
|
||||
{
|
||||
tree sum = fold_binary_loc (loc, PLUS_EXPR, TREE_TYPE (arg1),
|
||||
arg1, TREE_OPERAND (arg0, 1));
|
||||
if (sum && integer_zerop (sum)) {
|
||||
unsigned long pow2;
|
||||
|
||||
if (TREE_INT_CST_LOW (arg1))
|
||||
pow2 = exact_log2 (TREE_INT_CST_LOW (arg1));
|
||||
else
|
||||
pow2 = exact_log2 (TREE_INT_CST_HIGH (arg1))
|
||||
+ HOST_BITS_PER_WIDE_INT;
|
||||
|
||||
return fold_build2_loc (loc, RSHIFT_EXPR, type,
|
||||
TREE_OPERAND (arg0, 0),
|
||||
build_int_cst (NULL_TREE, pow2));
|
||||
}
|
||||
}
|
||||
|
||||
/* Fall thru */
|
||||
|
||||
case FLOOR_DIV_EXPR:
|
||||
/* Simplify A / (B << N) where A and B are positive and B is
|
||||
a power of 2, to A >> (N + log2(B)). */
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2010-10-20 Dmitry Melnik <dm@ispras.ru>
|
||||
|
||||
* gcc.dg/20101013-1.c: New test.
|
||||
|
||||
2010-10-20 H.J. Lu <hongjiu.lu@intel.com>
|
||||
|
||||
PR target/46085
|
||||
|
|
11
gcc/testsuite/gcc.dg/20101013-1.c
Normal file
11
gcc/testsuite/gcc.dg/20101013-1.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
/* { dg-do compile } */
|
||||
/* { dg-options "-O2 -fdump-tree-optimized" } */
|
||||
|
||||
int foo(int a)
|
||||
{
|
||||
int x = (a & (~15)) / 16;
|
||||
return x;
|
||||
}
|
||||
|
||||
/* { dg-final { scan-tree-dump ">>" "optimized" } } */
|
||||
/* { dg-final { cleanup-tree-dump "optimized" } } */
|
Loading…
Add table
Reference in a new issue