public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-6928] tree-optimization/103514 Missing XOR-EQ-AND Optimization
@ 2022-01-28 22:14 Jeff Law
  0 siblings, 0 replies; only message in thread
From: Jeff Law @ 2022-01-28 22:14 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:cb3ac1985a5332fa811a62844adb33ca140bd4ba

commit r12-6928-gcb3ac1985a5332fa811a62844adb33ca140bd4ba
Author: Navid Rahimi <navidrahimi@microsoft.com>
Date:   Fri Jan 28 17:11:30 2022 -0500

    tree-optimization/103514 Missing XOR-EQ-AND Optimization
    
    This patch will add the missed pattern described in bug 103514 [1] to the match.pd. [1] includes proof of correctness for the patch too.
    
    1) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103514
    
    gcc/
            PR tree-optimization/103514
            * match.pd (a & b) ^ (a == b) -> !(a | b): New optimization.
            (a & b) == (a ^ b) -> !(a | b): New optimization.
    
    gcc/testsuite
            * gcc.dg/tree-ssa/pr103514.c: Testcase for this optimization.

Diff:
---
 gcc/match.pd                             |  8 ++++++++
 gcc/testsuite/gcc.dg/tree-ssa/pr103514.c | 33 ++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index bd76da6ab8b..0544ddd91b3 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1784,6 +1784,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (negate (nop_convert? (bit_not @0)))
  (plus (view_convert @0) { build_each_one_cst (type); }))
 
+/* (a & b) ^ (a == b) -> !(a | b) */
+/* (a & b) == (a ^ b) -> !(a | b) */
+(for first_op (bit_xor eq)
+     second_op (eq bit_xor)
+ (simplify
+  (first_op:c (bit_and:c truth_valued_p@0 truth_valued_p@1) (second_op:c @0 @1))
+    (bit_not (bit_ior @0 @1))))
+
 /* Convert ~ (A - 1) or ~ (A + -1) to -A.  */
 (simplify
  (bit_not (convert? (minus @0 integer_each_onep)))
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr103514.c b/gcc/testsuite/gcc.dg/tree-ssa/pr103514.c
new file mode 100644
index 00000000000..de3709ce396
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr103514.c
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized" } */
+#include <stdbool.h>
+
+bool
+i (bool a, bool b)
+{
+     return (a & b) ^ (a == b);
+}
+
+bool
+j (bool a, bool b)
+{
+     return (a & b) == (a ^ b);
+}
+
+bool
+g (bool a, bool b)
+{
+    return (a && b) == (a ^ b); 
+}
+
+bool
+h (bool a, bool b)
+{
+     return (a && b) ^ (a == b);
+}
+
+
+/* Make sure we have removed "==" and "^" and "&". */
+/* { dg-final { scan-tree-dump-not "&" "optimized"} } */
+/* { dg-final { scan-tree-dump-not "\\^"  "optimized"} } */
+/* { dg-final { scan-tree-dump-not "==" "optimized"} } */
\ No newline at end of file


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-28 22:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-28 22:14 [gcc r12-6928] tree-optimization/103514 Missing XOR-EQ-AND Optimization Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).