From: Marek Polacek Date: Mon, 22 Jun 2015 14:46:14 +0000 (+0000) Subject: match.pd ((x ^ y) ^ (x | y) -> x & y, (x & y) + (x ^ y) -> x | y, (x & y) | (x ^... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9ea65ca6889dc34515be84336175299ad9a44b6a;p=gcc.git 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6ca98cf10f7..0b3ea81c7d3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2015-06-22 Marek Polacek + + * 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 PR target/65871 diff --git a/gcc/match.pd b/gcc/match.pd index 1ab2b1c0056..badb80a28a7 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 faa73a5dccf..f9d26537b4b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2015-06-22 Marek Polacek + + * 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 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 00000000000..0358eb5cf4d --- /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 00000000000..6501f2f9264 --- /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 00000000000..e7adce6b2d9 --- /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 00000000000..40d6aa251d7 --- /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 00000000000..713abf62466 --- /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 00000000000..b5a2c48b661 --- /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 00000000000..15ee76c791b --- /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" } } */