[gcc r11-6651] match.pd: Fold (~X | C) ^ D into (X | C) ^ (~D ^ C) if (~D ^ C) can be simplified [PR96691]
Jakub Jelinek
jakub@gcc.gnu.org
Wed Jan 13 18:56:29 GMT 2021
https://gcc.gnu.org/g:8fc183ccd0628465205b8a88c29ab69bfe74a08a
commit r11-6651-g8fc183ccd0628465205b8a88c29ab69bfe74a08a
Author: Jakub Jelinek <jakub@redhat.com>
Date: Wed Jan 13 19:54:49 2021 +0100
match.pd: Fold (~X | C) ^ D into (X | C) ^ (~D ^ C) if (~D ^ C) can be simplified [PR96691]
These simplifications are only simplifications if the (~D ^ C) or (D ^ C)
expressions fold into gimple vals, but in that case they decrease number of
operations by 1.
2021-01-13 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/96691
* match.pd ((~X | C) ^ D -> (X | C) ^ (~D ^ C),
(~X & C) ^ D -> (X & C) ^ (D ^ C)): New simplifications if
(~D ^ C) or (D ^ C) can be simplified.
* gcc.dg/tree-ssa/pr96691.c: New test.
Diff:
---
gcc/match.pd | 12 +++++++++++-
gcc/testsuite/gcc.dg/tree-ssa/pr96691.c | 21 +++++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/gcc/match.pd b/gcc/match.pd
index 60c383da13b..6f7b41fe0ff 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -947,8 +947,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(bit_ior:c (bit_xor:c@3 @0 @1) (bit_xor:c (bit_xor:c @1 @2) @0))
(bit_ior @3 @2))
-/* Simplify (~X & Y) to X ^ Y if we know that (X & ~Y) is 0. */
#if GIMPLE
+/* (~X | C) ^ D -> (X | C) ^ (~D ^ C) if (~D ^ C) can be simplified. */
+(simplify
+ (bit_xor:c (bit_ior:cs (bit_not:s @0) @1) @2)
+ (bit_xor (bit_ior @0 @1) (bit_xor! (bit_not! @2) @1)))
+
+/* (~X & C) ^ D -> (X & C) ^ (D ^ C) if (D ^ C) can be simplified. */
+(simplify
+ (bit_xor:c (bit_and:cs (bit_not:s @0) @1) @2)
+ (bit_xor (bit_and @0 @1) (bit_xor! @2 @1)))
+
+/* Simplify (~X & Y) to X ^ Y if we know that (X & ~Y) is 0. */
(simplify
(bit_and (bit_not SSA_NAME@0) INTEGER_CST@1)
(if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr96691.c b/gcc/testsuite/gcc.dg/tree-ssa/pr96691.c
new file mode 100644
index 00000000000..a254cc7da79
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr96691.c
@@ -0,0 +1,21 @@
+/* PR tree-optimization/96691 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-times " \\\| 123;" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " \\\& 123;" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " \\\^ -315;" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " \\\^ 314;" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-not " \\\^ 321;" "optimized" } } */
+/* { dg-final { scan-tree-dump-not " = ~" "optimized" } } */
+
+int
+foo (int x)
+{
+ return (~x | 123) ^ 321;
+}
+
+int
+bar (int x)
+{
+ return (~x & 123) ^ 321;
+}
More information about the Gcc-cvs
mailing list