re PR middle-end/55863 (Fails to fold (i + 2) - (i + 1) to 1)

2013-01-04  Richard Biener  <rguenther@suse.de>

	PR middle-end/55863
	* fold-const.c (split_tree): Undo -X - 1 to ~X folding for
	reassociation.

	* gcc.dg/fold-reassoc-2.c: New testcase.

From-SVN: r194899
This commit is contained in:
Richard Biener 2013-01-04 10:45:37 +00:00 committed by Richard Biener
parent db59befb09
commit 3068819a3a
4 changed files with 32 additions and 0 deletions

View File

@ -1,3 +1,9 @@
2013-01-04 Richard Biener <rguenther@suse.de>
PR middle-end/55863
* fold-const.c (split_tree): Undo -X - 1 to ~X folding for
reassociation.
2013-01-03 John David Anglin <dave.anglin@nrc-cnrc.gc.ca>
PR target/53789

View File

@ -821,6 +821,13 @@ split_tree (tree in, enum tree_code code, tree *conp, tree *litp,
if (neg_var_p)
var = negate_expr (var);
}
else if (TREE_CODE (in) == BIT_NOT_EXPR
&& code == PLUS_EXPR)
{
/* -X - 1 is folded to ~X, undo that here. */
*minus_litp = build_one_cst (TREE_TYPE (in));
var = negate_expr (TREE_OPERAND (in, 0));
}
else if (TREE_CONSTANT (in))
*conp = in;
else

View File

@ -1,3 +1,8 @@
2013-01-04 Richard Biener <rguenther@suse.de>
PR middle-end/55863
* gcc.dg/fold-reassoc-2.c: New testcase.
2013-01-04 Tobias Burnus <burnus@net-b.de>
PR fortran/55763

View File

@ -0,0 +1,14 @@
/* { dg-do compile } */
/* { dg-options "-O -fdump-tree-original" } */
int foo (int i)
{
return (i + 2) - (i + 1);
}
int bar (int i)
{
return (i + 2) + ~i;
}
/* { dg-final { scan-tree-dump "return 1;" "original" } } */
/* { dg-final { cleanup-tree-dump "original" } } */