summaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
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