From: Marek Polacek Date: Fri, 26 Jun 2015 10:13:49 +0000 (+0000) Subject: match.pd ((x | y) & ~(x & y) -> x ^ y, (x | y) & (~x ^ y) -> x & y): New patterns. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=66cc6273bad0c51db5e499dec2352a6bb7b4a952;p=gcc.git match.pd ((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): New patterns. * gcc.dg/fold-and-1.c: New test. * gcc.dg/fold-and-2.c: New test. From-SVN: r225001 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bd9abfc6702..f47ea92978f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2015-06-26 Marek Polacek + + * match.pd ((x | y) & ~(x & y) -> x ^ y, + (x | y) & (~x ^ y) -> x & y): New patterns. + 2015-06-26 Richard Sandiford * rtl.h (emit): Add an optional boolean parameter to control diff --git a/gcc/match.pd b/gcc/match.pd index b1a88272618..91dfddb9645 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -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)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e3ae30a0a38..ddf2a9fa8e6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-06-26 Marek Polacek + + * gcc.dg/fold-and-1.c: New test. + * gcc.dg/fold-and-2.c: New test. + 2015-06-26 Eric Botcazou * 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 index 00000000000..d555bb4b2d5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/fold-and-1.c @@ -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 index 00000000000..3df2a0ba59a --- /dev/null +++ b/gcc/testsuite/gcc.dg/fold-and-2.c @@ -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" } } */