~X & Y to X ^ Y in some cases

2016-05-17  Marc Glisse  <marc.glisse@inria.fr>

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
This commit is contained in:
Marc Glisse 2016-05-17 19:54:28 +02:00 committed by Marc Glisse
parent 0139ba9332
commit d982c5b7b7
4 changed files with 29 additions and 0 deletions

View File

@ -1,3 +1,7 @@
2016-05-17 Marc Glisse <marc.glisse@inria.fr>
* match.pd (~X & Y): New transformation.
2016-05-17 Marc Glisse <marc.glisse@inria.fr>
* tree-vrp.c (simplify_truth_ops_using_ranges): Set range

View File

@ -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)

View File

@ -1,3 +1,8 @@
2016-05-17 Marc Glisse <marc.glisse@inria.fr>
* gcc.dg/tree-ssa/pr69270.c: Adjust.
* gcc.dg/tree-ssa/andnot-1.c: New testcase.
2016-05-17 Marc Glisse <marc.glisse@inria.fr>
* gcc.dg/tree-ssa/pr69270.c: Adjust.

View File

@ -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" } } */