From d982c5b7b73b9bed5d63d614dc2ae4f17d49eb74 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Tue, 17 May 2016 19:54:28 +0200 Subject: [PATCH] ~X & Y to X ^ Y in some cases 2016-05-17 Marc Glisse gcc/ * match.pd (~X & Y): New transformation. gcc/testsuite/ * gcc.dg/tree-ssa/pr69270.c: Adjust. * gcc.dg/tree-ssa/andnot-1.c: New testcase. From-SVN: r236337 --- gcc/ChangeLog | 4 ++++ gcc/match.pd | 8 ++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/tree-ssa/andnot-1.c | 12 ++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/andnot-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 93c1a2d22a1..9ec5a9e688a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2016-05-17 Marc Glisse + + * match.pd (~X & Y): New transformation. + 2016-05-17 Marc Glisse * tree-vrp.c (simplify_truth_ops_using_ranges): Set range diff --git a/gcc/match.pd b/gcc/match.pd index 5b3cb3bfd5e..acc41be5a8d 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -503,6 +503,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (bit_ior:c (bit_and @0 INTEGER_CST@2) (bit_and (bit_not @0) INTEGER_CST@1)) (if (wi::bit_not (@2) == @1) (bit_xor @0 @1))) +/* Simplify (~X & Y) to X ^ Y if we know that (X & ~Y) is 0. */ +#if GIMPLE +(simplify + (bit_and (bit_not SSA_NAME@0) INTEGER_CST@1) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && (get_nonzero_bits (@0) & wi::bit_not (@1)) == 0) + (bit_xor @0 @1))) +#endif /* X % Y is smaller than Y. */ (for cmp (lt ge) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ca093a18527..61b6a2290c0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-05-17 Marc Glisse + + * gcc.dg/tree-ssa/pr69270.c: Adjust. + * gcc.dg/tree-ssa/andnot-1.c: New testcase. + 2016-05-17 Marc Glisse * gcc.dg/tree-ssa/pr69270.c: Adjust. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/andnot-1.c b/gcc/testsuite/gcc.dg/tree-ssa/andnot-1.c new file mode 100644 index 00000000000..7f161b672e5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/andnot-1.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-optimized-raw" } */ + +unsigned f(unsigned i){ + i >>= __SIZEOF_INT__ * __CHAR_BIT__ - 3; + i = ~i; + return i & 7; +} + +/* { dg-final { scan-tree-dump "bit_xor_expr" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "bit_not_expr" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "bit_and_expr" "optimized" } } */ -- 2.30.2