This fixes PR55863, a folding missed optimization caused by folding -X - 1 to ~X. This makes data dependence analysis fail for offsetted-by-1 accesses (in some cases).
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2013-01-04 Richard Biener <rguent...@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. Index: gcc/fold-const.c =================================================================== *** gcc/fold-const.c (revision 194855) --- gcc/fold-const.c (working copy) *************** split_tree (tree in, enum tree_code code *** 821,826 **** --- 821,833 ---- 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 Index: gcc/testsuite/gcc.dg/fold-reassoc-2.c =================================================================== *** gcc/testsuite/gcc.dg/fold-reassoc-2.c (revision 0) --- gcc/testsuite/gcc.dg/fold-reassoc-2.c (working copy) *************** *** 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" } } */