aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNavid Rahimi <navidrahimi@microsoft.com>2022-01-28 17:11:30 -0500
committerJeff Law <jeffreyalaw@gmail.com>2022-01-28 17:13:08 -0500
commitcb3ac1985a5332fa811a62844adb33ca140bd4ba (patch)
treee8b109bf7cac75e22a362e7c3550d0b66e898f58 /gcc
parent5d8b422818714737bd61d1667461efce96687073 (diff)
downloadgcc-cb3ac1985a5332fa811a62844adb33ca140bd4ba.zip
gcc-cb3ac1985a5332fa811a62844adb33ca140bd4ba.tar.gz
gcc-cb3ac1985a5332fa811a62844adb33ca140bd4ba.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/match.pd8
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr103514.c33
2 files changed, 41 insertions, 0 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index bd76da6..0544ddd 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 0000000..de3709c
--- /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