diff options
author | James A. Morrison <phython@gcc.gnu.org> | 2005-03-04 02:48:30 +0000 |
---|---|---|
committer | James A. Morrison <phython@gcc.gnu.org> | 2005-03-04 02:48:30 +0000 |
commit | 8d06c80914d7374d16887b0e817eadb41d898aa8 (patch) | |
tree | c908d67b93dc9a831686bb43afc3806aef6fd260 /gcc/fold-const.c | |
parent | 3159b178b0479e9c8998982c112f486d5d28ab53 (diff) | |
download | gcc-8d06c80914d7374d16887b0e817eadb41d898aa8.zip gcc-8d06c80914d7374d16887b0e817eadb41d898aa8.tar.gz gcc-8d06c80914d7374d16887b0e817eadb41d898aa8.tar.bz2 |
re PR tree-optimization/15784 (fold misses binary optimization)
2005-03-03 James A. Morrison <phython@gcc.gnu.org>
PR tree-optimization/15784
* fold-const.c (fold): Fold ~A + 1 to -1. Fold -A - 1
and -1 - A to ~A.
From-SVN: r95870
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 72e557e..2c6d71e 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -7223,6 +7223,11 @@ fold (tree expr) if (TREE_CODE (arg0) == NEGATE_EXPR && reorder_operands_p (TREE_OPERAND (arg0, 0), arg1)) return fold (build2 (MINUS_EXPR, type, arg1, TREE_OPERAND (arg0, 0))); + /* Convert ~A + 1 to -A. */ + if (INTEGRAL_TYPE_P (type) + && TREE_CODE (arg0) == BIT_NOT_EXPR + && integer_onep (arg1)) + return fold (build1 (NEGATE_EXPR, type, TREE_OPERAND (arg0, 0))); if (TREE_CODE (type) == COMPLEX_TYPE) { @@ -7661,6 +7666,16 @@ fold (tree expr) && reorder_operands_p (arg0, arg1)) return fold (build2 (MINUS_EXPR, type, negate_expr (arg1), TREE_OPERAND (arg0, 0))); + /* Convert -A - 1 to ~A. */ + if (INTEGRAL_TYPE_P (type) + && TREE_CODE (arg0) == NEGATE_EXPR + && integer_onep (arg1)) + return fold (build1 (BIT_NOT_EXPR, type, TREE_OPERAND (arg0, 0))); + + /* Convert -1 - A to ~A. */ + if (INTEGRAL_TYPE_P (type) + && integer_all_onesp (arg0)) + return fold (build1 (BIT_NOT_EXPR, type, arg1)); if (TREE_CODE (type) == COMPLEX_TYPE) { |