[multiple changes]

2005-11-25  Andrew Pinski  <pinskia@physics.uc.edu>

        PR middle-end/24989
        * fold-const.c (fold_build): Convert bool_var != 1 and
        bool_var == 0 to !bool_var.

2005-11-24  Andrew Pinski  <pinskia@physics.uc.edu>

        PR middle-end/24989
        * gcc.dg/tree-ssa/bool-10.c: New test.
        * gcc.dg/tree-ssa/bool-11.c: New test.
        * gcc.dg/tree-ssa/bool-7.c: Un-xfail.

From-SVN: r107488
This commit is contained in:
Andrew Pinski 2005-11-25 05:05:26 +00:00 committed by Andrew Pinski
parent 210dfe6ecc
commit 7934558dd1
6 changed files with 53 additions and 3 deletions

View File

@ -1,3 +1,9 @@
2005-11-25 Andrew Pinski <pinskia@physics.uc.edu>
PR middle-end/24989
* fold-const.c (fold_build): Convert bool_var != 1 and
bool_var == 0 to !bool_var.
2005-11-25 Andrew Pinski <pinskia@physics.uc.edu>
PR middle-end/24990

View File

@ -8857,6 +8857,16 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
&& code == EQ_EXPR)
return non_lvalue (fold_convert (type, arg0));
/* bool_var != 1 becomes !bool_var. */
if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_onep (arg1)
&& code == NE_EXPR)
return fold_build1 (TRUTH_NOT_EXPR, type, arg0);
/* bool_var == 0 becomes !bool_var. */
if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_zerop (arg1)
&& code == EQ_EXPR)
return fold_build1 (TRUTH_NOT_EXPR, type, arg0);
/* If this is an equality comparison of the address of a non-weak
object against zero, then we know the result. */
if ((code == EQ_EXPR || code == NE_EXPR)

View File

@ -1,3 +1,10 @@
2005-11-24 Andrew Pinski <pinskia@physics.uc.edu>
PR middle-end/24989
* gcc.dg/tree-ssa/bool-10.c: New test.
* gcc.dg/tree-ssa/bool-11.c: New test.
* gcc.dg/tree-ssa/bool-7.c: Un-xfail.
2005-11-24 Andrew Pinski <pinskia@physics.uc.edu>
PR middle-end/24990

View File

@ -0,0 +1,14 @@
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
int f(_Bool x)
{
return (x != 1);
}
/* There should be no != 1 which is produced by the front-end as
bool_var != 1 is the same as !bool_var. */
/* { dg-final { scan-tree-dump-times "!= 1" 0 "optimized"} } */
/* { dg-final { scan-tree-dump-times "!x" 1 "optimized"} } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -0,0 +1,14 @@
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
int f(_Bool x)
{
return (x == 0);
}
/* There should be no == 0 which is produced by the front-end as
bool_var == 0 is the same as !bool_var. */
/* { dg-final { scan-tree-dump-times "== 0" 0 "optimized"} } */
/* { dg-final { scan-tree-dump-times "!x" 1 "optimized"} } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

View File

@ -11,8 +11,7 @@ int f(_Bool x)
return y;
}
/* There should be no != 1. Though PHI-OPT or invert_truth does not
fold its tree. */
/* { dg-final { scan-tree-dump-times "!= 1" 0 "optimized" { xfail *-*-* } } }*/
/* There should be no != 1. Fold changes x != 1 to ! x. */
/* { dg-final { scan-tree-dump-times "!= 1" 0 "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */