summaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2013-01-04 10:45:37 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2013-01-04 10:45:37 +0000
commit3068819a3af2da9cdab935d39b952912b1f63325 (patch)
tree002d1787e93d0fc5c2e65f699f5d251bbf4f31ad /gcc/fold-const.c
parentdb59befb099fc4d20a2a60f9eaa6b1fb8a9e85c7 (diff)
downloadgcc-3068819a3af2da9cdab935d39b952912b1f63325.tar.gz
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
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 4f384a75344..7e619d6d1e5 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -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