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
This commit is contained in:
James A. Morrison 2005-03-04 02:48:30 +00:00
parent 3159b178b0
commit 8d06c80914
4 changed files with 37 additions and 0 deletions

View File

@ -1,3 +1,9 @@
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.
2005-03-03 David Edelsohn <edelsohn@gnu.org>
* config/rs6000/predicates.md (branch_comparison_operator):

View File

@ -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)
{

View File

@ -1,3 +1,7 @@
2005-03-03 James A. Morrison <phython@gcc.gnu.org>
* gcc.dg/pr15784-4.c: New test.
2005-03-03 Geoffrey Keating <geoffk@apple.com>
* gcc.c-torture/execute/pr17133.c: New.

View File

@ -0,0 +1,12 @@
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-optimized" } */
int a (int x) {
return ~x + 1; /* -x */
}
int b (int x) {
return -x -1; /* ~x */
}
/* { dg-final { scan-tree-dump "~x;" "optimized" } } */
/* { dg-final { scan-tree-dump "-x;" "optimized" } } */