diff options
author | law <law@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-03-11 04:52:42 +0000 |
---|---|---|
committer | law <law@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-03-11 04:52:42 +0000 |
commit | c860f88ec9cc331115b7dda39265b5fbd24e4c57 (patch) | |
tree | b68e8b88fbd204957fa2a685eaa6985b21264dfc /gcc/fold-const.c | |
parent | ef1ba9f3b02aaede549862dde9e8fed0ad42c0e4 (diff) | |
download | ppe42-gcc-c860f88ec9cc331115b7dda39265b5fbd24e4c57.tar.gz ppe42-gcc-c860f88ec9cc331115b7dda39265b5fbd24e4c57.zip |
PR tree-optimization/15784
* fold-const.c (fold): Fold ~A + 1 to -A. Fold -A - 1
and -1 - A to ~A.
* stmt.c (expand_case): Don't change index_type. Convert minval
to the proper type.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@96289 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 9d0a9f02d73..3fdfb92f3b2 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -7198,6 +7198,11 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) 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) { @@ -7636,6 +7641,16 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) && 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) { |