diff options
author | Marek Polacek <polacek@redhat.com> | 2015-06-26 10:13:49 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2015-06-26 10:13:49 +0000 |
commit | 66cc6273bad0c51db5e499dec2352a6bb7b4a952 (patch) | |
tree | 6d9fcb7f7e6678089e1bc411453302549aa0833c /gcc | |
parent | 9d8895c9342d2c46d7d7e9b0437879db9d60cf7c (diff) | |
download | gcc-66cc6273bad0c51db5e499dec2352a6bb7b4a952.zip gcc-66cc6273bad0c51db5e499dec2352a6bb7b4a952.tar.gz gcc-66cc6273bad0c51db5e499dec2352a6bb7b4a952.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/match.pd | 10 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/fold-and-1.c | 70 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/fold-and-2.c | 70 |
5 files changed, 160 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bd9abfc..f47ea92 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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 diff --git a/gcc/match.pd b/gcc/match.pd index b1a8827..91dfddb 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 e3ae30a..ddf2a9f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000..d555bb4 --- /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 0000000..3df2a0b --- /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" } } */ |