fold-const.c (fold_plusminus_mult_expr): Do not fold i * 4 + 2 to (i * 2 + 1) * 2.
2009-04-01 Richard Guenther <rguenther@suse.de> * fold-const.c (fold_plusminus_mult_expr): Do not fold i * 4 + 2 to (i * 2 + 1) * 2. * gcc.dg/fold-plusmult-2.c: New testcase. From-SVN: r145403
This commit is contained in:
parent
b85eb797e2
commit
299b87f8a2
@ -1,3 +1,8 @@
|
||||
2009-04-01 Richard Guenther <rguenther@suse.de>
|
||||
|
||||
* fold-const.c (fold_plusminus_mult_expr): Do not fold
|
||||
i * 4 + 2 to (i * 2 + 1) * 2.
|
||||
|
||||
2009-04-01 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
PR c/37772
|
||||
|
@ -7466,7 +7466,11 @@ fold_plusminus_mult_expr (enum tree_code code, tree type, tree arg0, tree arg1)
|
||||
else
|
||||
maybe_same = arg11;
|
||||
|
||||
if (exact_log2 (abs (int11)) > 0 && int01 % int11 == 0)
|
||||
if (exact_log2 (abs (int11)) > 0 && int01 % int11 == 0
|
||||
/* The remainder should not be a constant, otherwise we
|
||||
end up folding i * 4 + 2 to (i * 2 + 1) * 2 which has
|
||||
increased the number of multiplications necessary. */
|
||||
&& TREE_CODE (arg10) != INTEGER_CST)
|
||||
{
|
||||
alt0 = fold_build2 (MULT_EXPR, TREE_TYPE (arg00), arg00,
|
||||
build_int_cst (TREE_TYPE (arg00),
|
||||
|
@ -1,3 +1,7 @@
|
||||
2009-04-01 Richard Guenther <rguenther@suse.de>
|
||||
|
||||
* gcc.dg/fold-plusmult-2.c: New testcase.
|
||||
|
||||
2009-04-01 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
PR c/37772
|
||||
|
20
gcc/testsuite/gcc.dg/fold-plusmult-2.c
Normal file
20
gcc/testsuite/gcc.dg/fold-plusmult-2.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-fdump-tree-original" } */
|
||||
|
||||
int foo (int i)
|
||||
{
|
||||
return 2 + i * 4;
|
||||
}
|
||||
|
||||
/* We do _not_ want the above to be canonicalized to (i * 2 + 1) * 2. */
|
||||
|
||||
int bar (int i)
|
||||
{
|
||||
return 4 + i * 2;
|
||||
}
|
||||
|
||||
/* But eventually this to be canonicalized to (i + 2) * 2. */
|
||||
|
||||
/* { dg-final { scan-tree-dump "i \\\* 4 \\\+ 2" "original" } } */
|
||||
/* { dg-final { scan-tree-dump "\\\(i \\\+ 2\\\) \\\* 2" "original" } } */
|
||||
/* { dg-final { cleanup-tree-dump "original" } } */
|
Loading…
x
Reference in New Issue
Block a user