aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAndrew Pinski <apinski@marvell.com>2023-09-03 14:26:53 -0700
committerAndrew Pinski <apinski@marvell.com>2023-09-05 14:14:55 -0700
commitab286761bf703a43bbd8495cd3fc33a7e88c8440 (patch)
tree0b74dfef9715ca79e667e9ddeae4d39ac830b17b /gcc
parent8e995e84233661a1a246807a66cc84003426b1df (diff)
downloadgcc-ab286761bf703a43bbd8495cd3fc33a7e88c8440.zip
gcc-ab286761bf703a43bbd8495cd3fc33a7e88c8440.tar.gz
gcc-ab286761bf703a43bbd8495cd3fc33a7e88c8440.tar.bz2
MATCH: Add `(x | c) & ~(y | c)` and `x & ~(y | x)` patterns [PR98710]
Adding some more simple bit_and/bit_ior patterns. How often these show up, I have no idea. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: PR tree-optimization/98710 * match.pd (`(x | c) & ~(y | c)`, `(x & c) | ~(y & c)`): New pattern. (`x & ~(y | x)`, `x | ~(y & x)`): New patterns. gcc/testsuite/ChangeLog: PR tree-optimization/98710 * gcc.dg/tree-ssa/andor-7.c: New test. * gcc.dg/tree-ssa/andor-8.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/match.pd14
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/andor-7.c16
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/andor-8.c19
3 files changed, 48 insertions, 1 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index bc9ddd6..801edb1 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2075,7 +2075,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* (x & y) | (x | z) -> (x | z) */
(simplify
(bitop:c (rbitop:c @0 @1) (bitop:c@3 @0 @2))
- @3))
+ @3)
+ /* (x | c) & ~(y | c) -> x & ~(y | c) */
+ /* (x & c) | ~(y & c) -> x | ~(y & c) */
+ (simplify
+ (bitop:c (rbitop:c @0 @1) (bit_not@3 (rbitop:c @1 @2)))
+ (bitop @0 @3))
+ /* x & ~(y | x) -> 0 */
+ /* x | ~(y & x) -> -1 */
+ (simplify
+ (bitop:c @0 (bit_not (rbitop:c @0 @1)))
+ (if (bitop == BIT_AND_EXPR)
+ { build_zero_cst (type); }
+ { build_minus_one_cst (type); })))
/* ((x | y) & z) | x -> (z & y) | x
((x ^ y) & z) | x -> (z & y) | x */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/andor-7.c b/gcc/testsuite/gcc.dg/tree-ssa/andor-7.c
new file mode 100644
index 0000000..63b70fa
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/andor-7.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-original" } */
+/* PR tree-optimization/98710 */
+
+signed foo(signed x, signed y, signed z)
+{
+ return (x | z) & ~(y | z); // x & ~(y | z);
+}
+// Note . here is `(` or `)`
+/* { dg-final { scan-tree-dump "return x \& ~.y \\| z.;|return ~.y \\| z. \& x;" "original" } } */
+
+signed foo_or(signed a, signed b, signed c)
+{
+ return (a & c) | ~(b & c); // a | ~(b & c);
+}
+/* { dg-final { scan-tree-dump "return a \\| ~.b \& c.;|return ~.b \& c. \\| a;" "original" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/andor-8.c b/gcc/testsuite/gcc.dg/tree-ssa/andor-8.c
new file mode 100644
index 0000000..0c2eb4c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/andor-8.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-original" } */
+/* PR tree-optimization/98710 */
+
+signed foo2(signed a, signed b, signed c)
+{
+ return (a & ~(b | a)) & c; // 0
+}
+/* { dg-final { scan-tree-dump "return 0;" "original" } } */
+signed foo2_or(signed x, signed y, signed z)
+{
+ return (x | ~(y & x)) & z; // -1 & z -> z
+}
+
+/* { dg-final { scan-tree-dump "return z;" "original" } } */
+/* All | and & should have been removed. */
+/* { dg-final { scan-tree-dump-not "~" "original" } } */
+/* { dg-final { scan-tree-dump-not " \& " "original" } } */
+/* { dg-final { scan-tree-dump-not " \\| " "original" } } */