diff options
author | Jakub Jelinek <jakub@redhat.com> | 2021-01-13 19:54:49 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2021-01-13 19:54:49 +0100 |
commit | 8fc183ccd0628465205b8a88c29ab69bfe74a08a (patch) | |
tree | 4f8b6bc9bb581e48d217a2c0baacbfcb5f13e102 | |
parent | 7d7ef413ef1b696dec2710ae0acc058bdc832686 (diff) | |
download | gcc-8fc183ccd0628465205b8a88c29ab69bfe74a08a.zip gcc-8fc183ccd0628465205b8a88c29ab69bfe74a08a.tar.gz gcc-8fc183ccd0628465205b8a88c29ab69bfe74a08a.tar.bz2 |
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.
-rw-r--r-- | gcc/match.pd | 12 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/pr96691.c | 21 |
2 files changed, 32 insertions, 1 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index 60c383d..6f7b41f 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 0000000..a254cc7 --- /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; +} |