diff options
author | phython <phython@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-03-04 02:48:30 +0000 |
---|---|---|
committer | phython <phython@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-03-04 02:48:30 +0000 |
commit | aa8057b43cfc5906f3ec496e182a913613b60a96 (patch) | |
tree | c908d67b93dc9a831686bb43afc3806aef6fd260 /gcc/fold-const.c | |
parent | 35db3ec168fe37033e35bb171191d3f707af8c0d (diff) | |
download | gcc-aa8057b43cfc5906f3ec496e182a913613b60a96.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@95870 138bc75d-0d04-0410-961f-82ee72b054a4
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 72e557eeb71..2c6d71ec030 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) { |