From c7986356a1ca8e8e671af74e9e7b76d14238bd5f Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Tue, 17 May 2016 19:57:27 +0200 Subject: [PATCH] x & C -> x if we know that x & ~C == 0 2016-05-17 Marc Glisse gcc/ * match.pd (X & C): New transformation. gcc/testsuite/ * gcc.dg/tree-ssa/and-1.c: New testcase. From-SVN: r236338 --- gcc/ChangeLog | 4 ++++ gcc/match.pd | 9 +++++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/tree-ssa/and-1.c | 11 +++++++++++ 4 files changed, 28 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/and-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9ec5a9e688a..7f722277fd5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2016-05-17 Marc Glisse + + * match.pd (X & C): New transformation. + 2016-05-17 Marc Glisse * match.pd (~X & Y): New transformation. diff --git a/gcc/match.pd b/gcc/match.pd index acc41be5a8d..db8e39cb15d 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -563,6 +563,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (bitop @0 @0) (non_lvalue @0))) +/* x & C -> x if we know that x & ~C == 0. */ +#if GIMPLE +(simplify + (bit_and SSA_NAME@0 INTEGER_CST@1) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && (get_nonzero_bits (@0) & wi::bit_not (@1)) == 0) + @0)) +#endif + /* x + (x & 1) -> (x + 1) & ~1 */ (simplify (plus:c @0 (bit_and:s @0 integer_onep@1)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 61b6a2290c0..0e648e58ef0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-05-17 Marc Glisse + + * gcc.dg/tree-ssa/and-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/and-1.c b/gcc/testsuite/gcc.dg/tree-ssa/and-1.c new file mode 100644 index 00000000000..276c2b9bd8a --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/and-1.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-optimized-raw" } */ + +int f(int in) { + in = in | 3; + in = in ^ 1; + in = (in & ~(unsigned long)1); + return in; +} + +/* { dg-final { scan-tree-dump-not "bit_and_expr" "optimized" } } */ -- 2.30.2