ChangeLog gcc/
authorKai Tietz <ktietz@redhat.com>
Mon, 20 Jun 2011 11:49:27 +0000 (13:49 +0200)
committerKai Tietz <ktietz@gcc.gnu.org>
Mon, 20 Jun 2011 11:49:27 +0000 (13:49 +0200)
2011-06-20  Kai Tietz  <ktietz@redhat.com>

* fold-const.c (fold_binary_loc): Add missing
folding for truth-not operations in combination
with binary and.

ChangeLog gcc/testsuite/

2011-06-20  Kai Tietz  <ktietz@redhat.com>

* gcc.dg/binop-notand1.c: New test.
* gcc.dg/binop-notand2.c: New test.
* gcc.dg/binop-notand3.c: New test.
* gcc.dg/binop-notand4.c: New test.
* gcc.dg/binop-notand5.c: New test.
* gcc.dg/binop-notand6.c: New test.

From-SVN: r175206

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/binop-notand1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/binop-notand2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/binop-notand3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/binop-notand4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/binop-notand5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/binop-notand6.c [new file with mode: 0644]

index 89c5f65c372c7cd81891ea76afc6aeb465abd7cb..673dd46ae14e3950695e948faf2405042f67b36a 100644 (file)
@@ -1,3 +1,9 @@
+2011-06-20  Kai Tietz  <ktietz@redhat.com>
+
+       * fold-const.c (fold_binary_loc): Add missing
+       folding for truth-not operations in combination
+       with binary and.
+
 2011-06-20  Bernd Schmidt  <bernds@codesourcery.com>
 
        * regrename.c (do_replace): Don't update notes.
index c39d33e1da22106c073c1f0a4703fd6e74e1e625..e48aae9f4ce19a2ed7538194524b091603bff87e 100644 (file)
@@ -10866,13 +10866,19 @@ fold_binary_loc (location_t loc,
       if (operand_equal_p (arg0, arg1, 0))
        return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
 
-      /* ~X & X is always zero.  */
-      if (TREE_CODE (arg0) == BIT_NOT_EXPR
+      /* ~X & X, (X == 0) & X, and !X & X are always zero.  */
+      if ((TREE_CODE (arg0) == BIT_NOT_EXPR
+          || TREE_CODE (arg0) == TRUTH_NOT_EXPR
+          || (TREE_CODE (arg0) == EQ_EXPR
+              && integer_zerop (TREE_OPERAND (arg0, 1))))
          && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
        return omit_one_operand_loc (loc, type, integer_zero_node, arg1);
 
-      /* X & ~X is always zero.  */
-      if (TREE_CODE (arg1) == BIT_NOT_EXPR
+      /* X & ~X , X & (X == 0), and X & !X are always zero.  */
+      if ((TREE_CODE (arg1) == BIT_NOT_EXPR
+          || TREE_CODE (arg1) == TRUTH_NOT_EXPR
+          || (TREE_CODE (arg1) == EQ_EXPR
+              && integer_zerop (TREE_OPERAND (arg1, 1))))
          && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
        return omit_one_operand_loc (loc, type, integer_zero_node, arg0);
 
@@ -10933,6 +10939,14 @@ fold_binary_loc (location_t loc,
                                           build_int_cst (TREE_TYPE (tem), 1)),
                              build_int_cst (TREE_TYPE (tem), 0));
        }
+      /* Fold !X & 1 as X == 0.  */
+      if (TREE_CODE (arg0) == TRUTH_NOT_EXPR
+         && integer_onep (arg1))
+       {
+         tem = TREE_OPERAND (arg0, 0);
+         return fold_build2_loc (loc, EQ_EXPR, type, tem,
+                                 build_int_cst (TREE_TYPE (tem), 0));
+       }
 
       /* Fold (X ^ Y) & Y as ~X & Y.  */
       if (TREE_CODE (arg0) == BIT_XOR_EXPR
index 7868b7b8e84b9648367c272b8bfd92e1caef6313..3aa6446ab6bd702fed3aece952f29fcf387fe1c3 100644 (file)
@@ -1,3 +1,12 @@
+2011-06-20  Kai Tietz  <ktietz@redhat.com>
+
+       * gcc.dg/binop-notand1.c: New test.
+       * gcc.dg/binop-notand2.c: New test.
+       * gcc.dg/binop-notand3.c: New test.
+       * gcc.dg/binop-notand4.c: New test.
+       * gcc.dg/binop-notand5.c: New test.
+       * gcc.dg/binop-notand6.c: New test.
+
 2011-06-18  Jakub Jelinek  <jakub@redhat.com>
 
        PR testsuite/49432
diff --git a/gcc/testsuite/gcc.dg/binop-notand1.c b/gcc/testsuite/gcc.dg/binop-notand1.c
new file mode 100644 (file)
index 0000000..cadf7e5
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int
+foo (int a, int b)
+{
+  return (a & !a) | (b & !b);
+}
+
+/* { dg-final { scan-tree-dump-times "return 0" 1 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/binop-notand2.c b/gcc/testsuite/gcc.dg/binop-notand2.c
new file mode 100644 (file)
index 0000000..0076d4b
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int
+foo (int a)
+{
+  return (!a & 1) != (a == 0);
+}
+
+/* { dg-final { scan-tree-dump-times "return 0" 1 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/binop-notand3.c b/gcc/testsuite/gcc.dg/binop-notand3.c
new file mode 100644 (file)
index 0000000..5f8e32f
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int
+foo (int a)
+{
+  return (!a & 1) != ((a == 0) & 1);
+}
+
+/* { dg-final { scan-tree-dump-times "return 0" 1 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/binop-notand4.c b/gcc/testsuite/gcc.dg/binop-notand4.c
new file mode 100644 (file)
index 0000000..1c3fefd
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int
+foo (int a, int b)
+{
+  return (!a & a) | (b & !b);
+}
+
+/* { dg-final { scan-tree-dump-times "return 0" 1 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/binop-notand5.c b/gcc/testsuite/gcc.dg/binop-notand5.c
new file mode 100644 (file)
index 0000000..463f19b
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int
+foo (int a, int b)
+{
+  return (a & (a == 0)) | (b & !b);
+}
+
+/* { dg-final { scan-tree-dump-times "return 0" 1 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/binop-notand6.c b/gcc/testsuite/gcc.dg/binop-notand6.c
new file mode 100644 (file)
index 0000000..e1882ac
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int
+foo (int a, int b)
+{
+  return (a & !a) | (b & (b == 0));
+}
+
+/* { dg-final { scan-tree-dump-times "return 0" 1 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */