aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2015-06-22 14:46:14 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2015-06-22 14:46:14 +0000
commit9ea65ca6889dc34515be84336175299ad9a44b6a (patch)
tree9c3319aa59047461dbd2781dc41cf35f91cb0185 /gcc
parentf4f9641b128d7692943f6378822ef79a69056427 (diff)
downloadgcc-9ea65ca6889dc34515be84336175299ad9a44b6a.zip
gcc-9ea65ca6889dc34515be84336175299ad9a44b6a.tar.gz
gcc-9ea65ca6889dc34515be84336175299ad9a44b6a.tar.bz2
match.pd ((x ^ y) ^ (x | y) -> x & y, (x & y) + (x ^ y) -> x | y, (x & y) | (x ^ y) -> x | y, (x & y) ^ (x ^ y) -> x | y, (x & y) + (x | y) -> x + y, (x | y) - (x ^ y) -> x & y, (x | y) - (x & y) -> x ^ y): New patterns.
* match.pd ((x ^ y) ^ (x | y) -> x & y, (x & y) + (x ^ y) -> x | y, (x & y) | (x ^ y) -> x | y, (x & y) ^ (x ^ y) -> x | y, (x & y) + (x | y) -> x + y, (x | y) - (x ^ y) -> x & y, (x | y) - (x & y) -> x ^ y): New patterns. * gcc.dg/fold-ior-1.c: New test. * gcc.dg/fold-minus-2.c: New test. * gcc.dg/fold-minus-3.c: New test. * gcc.dg/fold-plus-1.c: New test. * gcc.dg/fold-plus-2.c: New test. * gcc.dg/fold-xor-4.c: New test. * gcc.dg/fold-xor-5.c: New test. From-SVN: r224734
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/match.pd28
-rw-r--r--gcc/testsuite/ChangeLog10
-rw-r--r--gcc/testsuite/gcc.dg/fold-ior-1.c69
-rw-r--r--gcc/testsuite/gcc.dg/fold-minus-2.c37
-rw-r--r--gcc/testsuite/gcc.dg/fold-minus-3.c37
-rw-r--r--gcc/testsuite/gcc.dg/fold-plus-1.c70
-rw-r--r--gcc/testsuite/gcc.dg/fold-plus-2.c69
-rw-r--r--gcc/testsuite/gcc.dg/fold-xor-4.c69
-rw-r--r--gcc/testsuite/gcc.dg/fold-xor-5.c69
10 files changed, 465 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 6ca98cf..0b3ea81 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2015-06-22 Marek Polacek <polacek@redhat.com>
+
+ * match.pd ((x ^ y) ^ (x | y) -> x & y,
+ (x & y) + (x ^ y) -> x | y, (x & y) | (x ^ y) -> x | y,
+ (x & y) ^ (x ^ y) -> x | y, (x & y) + (x | y) -> x + y,
+ (x | y) - (x ^ y) -> x & y, (x | y) - (x & y) -> x ^ y): New patterns.
+
2015-06-22 Uros Bizjak <ubizjak@gmail.com>
PR target/65871
diff --git a/gcc/match.pd b/gcc/match.pd
index 1ab2b1c..badb80a 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -325,6 +325,34 @@ along with GCC; see the file COPYING3. If not see
(bit_xor:c (bit_and @0 @1) (bit_ior @0 @1))
(bit_xor @0 @1))
+/* (x ^ y) ^ (x | y) -> x & y */
+(simplify
+ (bit_xor:c (bit_xor @0 @1) (bit_ior @0 @1))
+ (bit_and @0 @1))
+
+/* (x & y) + (x ^ y) -> x | y */
+/* (x & y) | (x ^ y) -> x | y */
+/* (x & y) ^ (x ^ y) -> x | y */
+(for op (plus bit_ior bit_xor)
+ (simplify
+ (op:c (bit_and @0 @1) (bit_xor @0 @1))
+ (bit_ior @0 @1)))
+
+/* (x & y) + (x | y) -> x + y */
+(simplify
+ (plus:c (bit_and @0 @1) (bit_ior @0 @1))
+ (plus @0 @1))
+
+/* (x | y) - (x ^ y) -> x & y */
+(simplify
+ (minus (bit_ior @0 @1) (bit_xor @0 @1))
+ (bit_and @0 @1))
+
+/* (x | y) - (x & y) -> x ^ y */
+(simplify
+ (minus (bit_ior @0 @1) (bit_and @0 @1))
+ (bit_xor @0 @1))
+
(simplify
(abs (negate @0))
(abs @0))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index faa73a5..f9d2653 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,13 @@
+2015-06-22 Marek Polacek <polacek@redhat.com>
+
+ * gcc.dg/fold-ior-1.c: New test.
+ * gcc.dg/fold-minus-2.c: New test.
+ * gcc.dg/fold-minus-3.c: New test.
+ * gcc.dg/fold-plus-1.c: New test.
+ * gcc.dg/fold-plus-2.c: New test.
+ * gcc.dg/fold-xor-4.c: New test.
+ * gcc.dg/fold-xor-5.c: New test.
+
2015-06-22 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
PR target/65914
diff --git a/gcc/testsuite/gcc.dg/fold-ior-1.c b/gcc/testsuite/gcc.dg/fold-ior-1.c
new file mode 100644
index 0000000..0358eb5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-ior-1.c
@@ -0,0 +1,69 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-cddce1" } */
+
+int
+fn1 (int a, int b)
+{
+ int tem1 = a & b;
+ int tem2 = a ^ b;
+ return tem1 | tem2;
+}
+
+int
+fn2 (int a, int b)
+{
+ int tem1 = b & a;
+ int tem2 = a ^ b;
+ return tem1 | tem2;
+}
+
+int
+fn3 (int a, int b)
+{
+ int tem1 = a & b;
+ int tem2 = b ^ a;
+ return tem1 | tem2;
+}
+
+int
+fn4 (int a, int b)
+{
+ int tem1 = b & a;
+ int tem2 = b ^ a;
+ return tem1 | tem2;
+}
+
+int
+fn5 (int a, int b)
+{
+ int tem1 = a ^ b;
+ int tem2 = a & b;
+ return tem1 | tem2;
+}
+
+int
+fn6 (int a, int b)
+{
+ int tem1 = b ^ a;
+ int tem2 = a & b;
+ return tem1 | tem2;
+}
+
+int
+fn7 (int a, int b)
+{
+ int tem1 = a ^ b;
+ int tem2 = b & a;
+ return tem1 | tem2;
+}
+
+int
+fn8 (int a, int b)
+{
+ int tem1 = b ^ a;
+ int tem2 = b & a;
+ return tem1 | tem2;
+}
+
+/* { dg-final { scan-tree-dump-not " & " "cddce1" } } */
+/* { dg-final { scan-tree-dump-not " \\^ " "cddce1" } } */
diff --git a/gcc/testsuite/gcc.dg/fold-minus-2.c b/gcc/testsuite/gcc.dg/fold-minus-2.c
new file mode 100644
index 0000000..6501f2f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-minus-2.c
@@ -0,0 +1,37 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-cddce1" } */
+
+int
+fn1 (int a, int b)
+{
+ int tem1 = a | b;
+ int tem2 = a ^ b;
+ return tem1 - tem2;
+}
+
+int
+fn2 (int a, int b)
+{
+ int tem1 = b | a;
+ int tem2 = a ^ b;
+ return tem1 - tem2;
+}
+
+int
+fn3 (int a, int b)
+{
+ int tem1 = a | b;
+ int tem2 = b ^ a;
+ return tem1 - tem2;
+}
+
+int
+fn4 (int a, int b)
+{
+ int tem1 = b | a;
+ int tem2 = b ^ a;
+ return tem1 - tem2;
+}
+
+/* { dg-final { scan-tree-dump-not " \\^ " "cddce1" } } */
+/* { dg-final { scan-tree-dump-not " \\| " "cddce1" } } */
diff --git a/gcc/testsuite/gcc.dg/fold-minus-3.c b/gcc/testsuite/gcc.dg/fold-minus-3.c
new file mode 100644
index 0000000..e7adce6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-minus-3.c
@@ -0,0 +1,37 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-cddce1" } */
+
+int
+fn1 (int a, int b)
+{
+ int tem1 = a | b;
+ int tem2 = a & b;
+ return tem1 - tem2;
+}
+
+int
+fn2 (int a, int b)
+{
+ int tem1 = b | a;
+ int tem2 = a & b;
+ return tem1 - tem2;
+}
+
+int
+fn3 (int a, int b)
+{
+ int tem1 = a | b;
+ int tem2 = b & a;
+ return tem1 - tem2;
+}
+
+int
+fn4 (int a, int b)
+{
+ int tem1 = b | a;
+ int tem2 = b & a;
+ return tem1 - tem2;
+}
+
+/* { dg-final { scan-tree-dump-not " \\| " "cddce1" } } */
+/* { dg-final { scan-tree-dump-not " & " "cddce1" } } */
diff --git a/gcc/testsuite/gcc.dg/fold-plus-1.c b/gcc/testsuite/gcc.dg/fold-plus-1.c
new file mode 100644
index 0000000..40d6aa2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-plus-1.c
@@ -0,0 +1,70 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-cddce1" } */
+
+int
+fn1 (int a, int b)
+{
+ int tem1 = a & b;
+ int tem2 = a ^ b;
+ return tem1 + tem2;
+}
+
+int
+fn2 (int a, int b)
+{
+ int tem1 = b & a;
+ int tem2 = a ^ b;
+ return tem1 + tem2;
+}
+
+int
+fn3 (int a, int b)
+{
+ int tem1 = a & b;
+ int tem2 = b ^ a;
+ return tem1 + tem2;
+}
+
+int
+fn4 (int a, int b)
+{
+ int tem1 = b & a;
+ int tem2 = b ^ a;
+ return tem1 + tem2;
+}
+
+int
+fn5 (int a, int b)
+{
+ int tem1 = a ^ b;
+ int tem2 = a & b;
+ return tem1 + tem2;
+}
+
+int
+fn6 (int a, int b)
+{
+ int tem1 = b ^ a;
+ int tem2 = a & b;
+ return tem1 + tem2;
+}
+
+int
+fn7 (int a, int b)
+{
+ int tem1 = a ^ b;
+ int tem2 = b & a;
+ return tem1 + tem2;
+}
+
+int
+fn8 (int a, int b)
+{
+ int tem1 = b ^ a;
+ int tem2 = b & a;
+ 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-plus-2.c b/gcc/testsuite/gcc.dg/fold-plus-2.c
new file mode 100644
index 0000000..713abf6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-plus-2.c
@@ -0,0 +1,69 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-cddce1" } */
+
+int
+fn1 (int a, int b)
+{
+ int tem1 = a & b;
+ int tem2 = a | b;
+ return tem1 + tem2;
+}
+
+int
+fn2 (int a, int b)
+{
+ int tem1 = b & a;
+ int tem2 = a | b;
+ return tem1 + tem2;
+}
+
+int
+fn3 (int a, int b)
+{
+ int tem1 = a & b;
+ int tem2 = b | a;
+ return tem1 + tem2;
+}
+
+int
+fn4 (int a, int b)
+{
+ int tem1 = b & a;
+ int tem2 = b | a;
+ return tem1 + tem2;
+}
+
+int
+fn5 (int a, int b)
+{
+ int tem1 = a | b;
+ int tem2 = a & b;
+ return tem1 + tem2;
+}
+
+int
+fn6 (int a, int b)
+{
+ int tem1 = b | a;
+ int tem2 = a & b;
+ return tem1 + tem2;
+}
+
+int
+fn7 (int a, int b)
+{
+ int tem1 = a | b;
+ int tem2 = b & a;
+ return tem1 + tem2;
+}
+
+int
+fn8 (int a, int b)
+{
+ int tem1 = b | a;
+ int tem2 = b & a;
+ return tem1 + tem2;
+}
+
+/* { dg-final { scan-tree-dump-not " & " "cddce1" } } */
+/* { dg-final { scan-tree-dump-not " \\| " "cddce1" } } */
diff --git a/gcc/testsuite/gcc.dg/fold-xor-4.c b/gcc/testsuite/gcc.dg/fold-xor-4.c
new file mode 100644
index 0000000..b5a2c48
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-xor-4.c
@@ -0,0 +1,69 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-cddce1" } */
+
+int
+fn1 (int a, int b)
+{
+ int tem1 = a & b;
+ int tem2 = a ^ b;
+ return tem1 ^ tem2;
+}
+
+int
+fn2 (int a, int b)
+{
+ int tem1 = b & a;
+ int tem2 = a ^ b;
+ return tem1 ^ tem2;
+}
+
+int
+fn3 (int a, int b)
+{
+ int tem1 = a & b;
+ int tem2 = b ^ a;
+ return tem1 ^ tem2;
+}
+
+int
+fn4 (int a, int b)
+{
+ int tem1 = b & a;
+ int tem2 = b ^ a;
+ return tem1 ^ tem2;
+}
+
+int
+fn5 (int a, int b)
+{
+ int tem1 = a ^ b;
+ int tem2 = a & b;
+ return tem1 ^ tem2;
+}
+
+int
+fn6 (int a, int b)
+{
+ int tem1 = b ^ a;
+ int tem2 = a & b;
+ return tem1 ^ tem2;
+}
+
+int
+fn7 (int a, int b)
+{
+ int tem1 = a ^ b;
+ int tem2 = b & a;
+ return tem1 ^ tem2;
+}
+
+int
+fn8 (int a, int b)
+{
+ int tem1 = b ^ a;
+ int tem2 = b & a;
+ return tem1 ^ tem2;
+}
+
+/* { dg-final { scan-tree-dump-not " & " "cddce1" } } */
+/* { dg-final { scan-tree-dump-not " \\^ " "cddce1" } } */
diff --git a/gcc/testsuite/gcc.dg/fold-xor-5.c b/gcc/testsuite/gcc.dg/fold-xor-5.c
new file mode 100644
index 0000000..15ee76c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-xor-5.c
@@ -0,0 +1,69 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-cddce1" } */
+
+int
+fn1 (int a, int b)
+{
+ int tem1 = a | b;
+ int tem2 = a ^ b;
+ return tem1 ^ tem2;
+}
+
+int
+fn2 (int a, int b)
+{
+ int tem1 = b | a;
+ int tem2 = a ^ b;
+ return tem1 ^ tem2;
+}
+
+int
+fn3 (int a, int b)
+{
+ int tem1 = a | b;
+ int tem2 = b ^ a;
+ return tem1 ^ tem2;
+}
+
+int
+fn4 (int a, int b)
+{
+ int tem1 = b | a;
+ int tem2 = b ^ a;
+ return tem1 ^ tem2;
+}
+
+int
+fn5 (int a, int b)
+{
+ int tem1 = a ^ b;
+ int tem2 = a | b;
+ return tem1 ^ tem2;
+}
+
+int
+fn6 (int a, int b)
+{
+ int tem1 = b ^ a;
+ int tem2 = a | b;
+ return tem1 ^ tem2;
+}
+
+int
+fn7 (int a, int b)
+{
+ int tem1 = a ^ b;
+ int tem2 = b | a;
+ return tem1 ^ tem2;
+}
+
+int
+fn8 (int a, int b)
+{
+ int tem1 = b ^ a;
+ int tem2 = b | a;
+ return tem1 ^ tem2;
+}
+
+/* { dg-final { scan-tree-dump-not " \\| " "cddce1" } } */
+/* { dg-final { scan-tree-dump-not " \\^ " "cddce1" } } */