On Mon, 20 Aug 2018, MCC CS wrote:
this patch optimizes ~(~x | y), (~x | y) & (x | ~y) and
(~x | y) ^ (x | ~y).
Thank you. I didn't mean to force you to add the extra transformations to
your patch, but now that they are here, that's good :-)
gcc/
PR tree-optimization/87009
* match.pd: Improve boolean optimizations
(maybe the mailer ate the initial TAB)
"." at the end of the description.
Maybe "new" instead of "improve" since you are adding new transformations
and not modifying existing ones.
Some people list the patterns in parentheses here, but not all, so I guess
that's ok.
gcc/testsuite/
PR tree-optimization/87009
* gcc.dg/pr87009.c: Add boolean optimization tests
You can simply go with "New file." or "New test.", like most entries in
this ChangeLog, though the longer version is ok.
Index: gcc/match.pd
===================================================================
--- gcc/match.pd (revision 263646)
+++ gcc/match.pd (working copy)
@@ -776,6 +776,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(bit_not (bit_and:cs (bit_not @0) @1))
(bit_ior @0 (bit_not @1)))
+/* ~(~a | b) --> a & ~b */
+(simplify
+ (bit_not (bit_ior:cs (bit_not @0) @1))
+ (bit_and @0 (bit_not @1)))
+
/* Simplify (~X & Y) to X ^ Y if we know that (X & ~Y) is 0. */
#if GIMPLE
(simplify
@@ -981,6 +986,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(bit_and:c (bit_ior:c @0 @1) (bit_xor:c @1 (bit_not @0)))
(bit_and @0 @1))
+/* (~x | y) & (x | ~y) -> ~(x ^ y) */
+(simplify
+ (bit_and (bit_ior:c (bit_not @0) @1) (bit_ior:c @0 (bit_not @1)))
+ (bit_not (bit_xor @0 @1)))
+
+/* (~x | y) ^ (x | ~y) -> x ^ y */
+(simplify
+ (bit_xor (bit_ior:c (bit_not @0) @1) (bit_ior:c @0 (bit_not @1)))
+ (bit_xor @0 @1))
+
For what it's worth, I think that's good, though you need to wait for an
official reviewer.
(I wondered about a single_use check on the second transformation, but I
hope it isn't needed)
/* ~x & ~y -> ~(x | y)
~x | ~y -> ~(x & y) */
(for op (bit_and bit_ior)
Index: gcc/testsuite/gcc.dg/pr87009.c
===================================================================
--- gcc/testsuite/gcc.dg/pr87009.c (nonexistent)
+++ gcc/testsuite/gcc.dg/pr87009.c (working copy)
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-original" } */
If -O is sufficient, that would be better.
+/* { dg-final { scan-tree-dump-times " \\^ " 4 "original" } } */
You may also want to check that there are no unexpected &|~ , to be sure
that you are getting the expected output.
+
+int f1 (int x, int s)
+{
+ return ~(~(x|s)|x)|~(~(x|s)|s);
+}
+
+int f2 (int x, int s)
+{
+ return ~(~(~x&s)&~(x&~s));
+}
+
+int f3 (int x, int s)
+{
+ return ~((x|~s)&(~x|s));
+}
+
+int f4 (int x, int s)
+{
+ return (~x|s)&(x|~s);
+}
--
Marc Glisse