match.pd ((x | y) & ~(x & y) -> x ^ y, (x | y) & (~x ^ y) -> x & y): New patterns.
authorMarek Polacek <polacek@redhat.com>
Fri, 26 Jun 2015 10:13:49 +0000 (10:13 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 26 Jun 2015 10:13:49 +0000 (10:13 +0000)
* match.pd ((x | y) & ~(x & y) -> x ^ y,
(x | y) & (~x ^ y) -> x & y): New patterns.

* gcc.dg/fold-and-1.c: New test.
* gcc.dg/fold-and-2.c: New test.

From-SVN: r225001

gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/fold-and-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/fold-and-2.c [new file with mode: 0644]

index bd9abfc..f47ea92 100644 (file)
@@ -1,3 +1,8 @@
+2015-06-26  Marek Polacek  <polacek@redhat.com>
+
+       * match.pd ((x | y) & ~(x & y) -> x ^ y,
+       (x | y) & (~x ^ y) -> x & y): New patterns.
+
 2015-06-26  Richard Sandiford  <richard.sandiford@arm.com>
 
        * rtl.h (emit): Add an optional boolean parameter to control
index b1a8827..91dfddb 100644 (file)
@@ -367,6 +367,16 @@ along with GCC; see the file COPYING3.  If not see
  (minus (bit_ior @0 @1) (bit_and @0 @1))
  (bit_xor @0 @1))
 
+/* (x | y) & ~(x & y) -> x ^ y */
+(simplify
+ (bit_and:c (bit_ior @0 @1) (bit_not (bit_and @0 @1)))
+ (bit_xor @0 @1))
+
+/* (x | y) & (~x ^ y) -> x & y */
+(simplify
+ (bit_and:c (bit_ior:c @0 @1) (bit_xor:c @1 (bit_not @0)))
+ (bit_and @0 @1))
+
 (simplify
  (abs (negate @0))
  (abs @0))
index e3ae30a..ddf2a9f 100644 (file)
@@ -1,3 +1,8 @@
+2015-06-26  Marek Polacek  <polacek@redhat.com>
+
+       * gcc.dg/fold-and-1.c: New test.
+       * gcc.dg/fold-and-2.c: New test.
+
 2015-06-26  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/warn11.adb: Add missing dg directive.
diff --git a/gcc/testsuite/gcc.dg/fold-and-1.c b/gcc/testsuite/gcc.dg/fold-and-1.c
new file mode 100644 (file)
index 0000000..d555bb4
--- /dev/null
@@ -0,0 +1,70 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-cddce1" } */
+
+int
+fn1 (int x, int y)
+{
+  int tem1 = x | y;
+  int tem2 = ~(x & y);
+  return tem1 & tem2;
+}
+
+int
+fn2 (int x, int y)
+{
+  int tem1 = y | x;
+  int tem2 = ~(x & y);
+  return tem1 & tem2;
+}
+
+int
+fn3 (int x, int y)
+{
+  int tem1 = x | y;
+  int tem2 = ~(y & x);
+  return tem1 & tem2;
+}
+
+int
+fn4 (int x, int y)
+{
+  int tem1 = y | x;
+  int tem2 = ~(y & x);
+  return tem1 & tem2;
+}
+
+int
+fn5 (int x, int y)
+{
+  int tem1 = ~(x & y);
+  int tem2 = x | y;
+  return tem1 & tem2;
+}
+
+int
+fn6 (int x, int y)
+{
+  int tem1 = ~(x & y);
+  int tem2 = y | x;
+  return tem1 & tem2;
+}
+
+int
+fn7 (int x, int y)
+{
+  int tem1 = ~(y & x);
+  int tem2 = x | y;
+  return tem1 & tem2;
+}
+
+int
+fn8 (int x, int y)
+{
+  int tem1 = ~(y & x);
+  int tem2 = y | x;
+  return tem1 & tem2;
+}
+
+/* { dg-final { scan-tree-dump-not " \\| " "cddce1" } } */
+/* { dg-final { scan-tree-dump-not " \\& " "cddce1" } } */
+/* { dg-final { scan-tree-dump-not "~" "cddce1" } } */
diff --git a/gcc/testsuite/gcc.dg/fold-and-2.c b/gcc/testsuite/gcc.dg/fold-and-2.c
new file mode 100644 (file)
index 0000000..3df2a0b
--- /dev/null
@@ -0,0 +1,70 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-cddce1" } */
+
+int
+fn1 (int x, int y)
+{
+  int tem1 = x | y;
+  int tem2 = ~x ^ y;
+  return tem1 & tem2;
+}
+
+int
+fn2 (int x, int y)
+{
+  int tem1 = y | x;
+  int tem2 = ~x ^ y;
+  return tem1 & tem2;
+}
+
+int
+fn3 (int x, int y)
+{
+  int tem1 = x | y;
+  int tem2 = y ^ ~x;
+  return tem1 & tem2;
+}
+
+int
+fn4 (int x, int y)
+{
+  int tem1 = y | x;
+  int tem2 = y ^ ~x;
+  return tem1 & tem2;
+}
+
+int
+fn5 (int x, int y)
+{
+  int tem1 = ~x ^ y;
+  int tem2 = x | y;
+  return tem1 & tem2;
+}
+
+int
+fn6 (int x, int y)
+{
+  int tem1 = ~x ^ y;
+  int tem2 = y | x;
+  return tem1 & tem2;
+}
+
+int
+fn7 (int x, int y)
+{
+  int tem1 = y ^ ~x;
+  int tem2 = x | y;
+  return tem1 & tem2;
+}
+
+int
+fn8 (int x, int y)
+{
+  int tem1 = y ^ ~x;
+  int tem2 = y | x;
+  return tem1 & tem2;
+}
+
+/* { dg-final { scan-tree-dump-not " \\| " "cddce1" } } */
+/* { dg-final { scan-tree-dump-not " \\^ " "cddce1" } } */
+/* { dg-final { scan-tree-dump-not "~" "cddce1" } } */