re PR middle-end/87009 (Can't find XOR pattern applying De Morgan sequentially)
authorMCC CS <deswurstes@users.noreply.github.com>
Tue, 28 Aug 2018 20:23:05 +0000 (20:23 +0000)
committerJeff Law <law@gcc.gnu.org>
Tue, 28 Aug 2018 20:23:05 +0000 (14:23 -0600)
PR tree-optimization/87009
* match.pd: Add boolean optimizations.

PR tree-optimization/87009
* gcc.dg/pr87009.c: New test.

From-SVN: r263931

gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr87009.c [new file with mode: 0644]

index b4b56da..3dbee46 100644 (file)
@@ -1,3 +1,8 @@
+2018-08-28 MCC CS <deswurstes@users.noreply.github.com>
+
+       PR tree-optimization/87009
+       * match.pd: Add boolean optimizations.
+
 2018-08-28  Martin Sebor  <msebor@redhat.com>
 
        PR middle-end/86631
index d43e52d..be669ca 100644 (file)
@@ -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:cs (bit_not @0) @1) (bit_ior:cs @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))
+
 /* ~x & ~y -> ~(x | y)
    ~x | ~y -> ~(x & y) */
 (for op (bit_and bit_ior)
index 3a1b8d5..72f5a95 100644 (file)
@@ -1,3 +1,8 @@
+2018-08-28 MCC CS <deswurstes@users.noreply.github.com>
+
+       PR tree-optimization/87009
+       * gcc.dg/pr87009.c: New test.
+
 2018-08-28  Martin Sebor  <msebor@redhat.com>
 
        PR middle-end/86631
diff --git a/gcc/testsuite/gcc.dg/pr87009.c b/gcc/testsuite/gcc.dg/pr87009.c
new file mode 100644 (file)
index 0000000..eb8a4ec
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-original" } */
+/* { dg-final { scan-tree-dump-times "return s \\^ x;" 4 "original" } } */
+
+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);
+}