aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2022-07-21 13:20:47 +0200
committerRichard Biener <rguenther@suse.de>2022-07-21 13:20:47 +0200
commit375668e0508fbe173af1ed519d8ae2b79f388d94 (patch)
treef477d9a9880b00e974211c7beb58ff3fd1e73935
parentdc477ffb4aba21e9cf47de22a4df6f2b23849505 (diff)
downloadgcc-375668e0508fbe173af1ed519d8ae2b79f388d94.zip
gcc-375668e0508fbe173af1ed519d8ae2b79f388d94.tar.gz
gcc-375668e0508fbe173af1ed519d8ae2b79f388d94.tar.bz2
tree-optimization/106379 - add missing ~(a ^ b) folding for _Bool
The following makes sure to fold ~(a ^ b) to a == b for truth values (but not vectors, we'd have to check for vector support of equality). That turns the PR106379 testcase into a ranger one. Note that while we arrive at ~(a ^ b) in a convoluted way from original !a == !b one can eventually write the expression this way directly as well. PR tree-optimization/106379 * match.pd (~(a ^ b) -> a == b): New pattern. * gcc.dg/pr106379-1.c: New testcase.
-rw-r--r--gcc/match.pd6
-rw-r--r--gcc/testsuite/gcc.dg/pr106379-1.c9
2 files changed, 15 insertions, 0 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index 8bbc0db..88a1a5a 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1938,6 +1938,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
(bit_not (bit_xor (view_convert @0) @1))))
+/* ~(a ^ b) is a == b for truth valued a and b. */
+(simplify
+ (bit_not (bit_xor:s truth_valued_p@0 truth_valued_p@1))
+ (if (!VECTOR_TYPE_P (type))
+ (convert (eq @0 @1))))
+
/* (x & ~m) | (y & m) -> ((x ^ y) & m) ^ x */
(simplify
(bit_ior:c (bit_and:cs @0 (bit_not @2)) (bit_and:cs @1 @2))
diff --git a/gcc/testsuite/gcc.dg/pr106379-1.c b/gcc/testsuite/gcc.dg/pr106379-1.c
new file mode 100644
index 0000000..7f2575e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr106379-1.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-forwprop1" } */
+
+_Bool foo (_Bool a, _Bool b)
+{
+ return !a == !b;
+}
+
+/* { dg-final { scan-tree-dump "\[ab\]_\[0-9\]+\\(D\\) == \[ba\]_\[0-9\]+\\(D\\)" "forwprop1" } } */