+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
&& 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)
+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
--- /dev/null
+/* { 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" } } */
--- /dev/null
+/* { 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" } } */
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" } } */