On Tue, May 17, 2016 at 8:59 AM, Marc Glisse <marc.gli...@inria.fr> wrote: > Hello, > > the testcase for this patch is taken from > https://gcc.gnu.org/ml/gcc-patches/2016-05/msg00683.html > > get_nonzero_bits only gives may-be-set bits. To handle an equivalent > transform for bit_ior, I would need must-be-set bits, maybe I should check > if that is available somewhere in CCP... > > The patch is extremely similar to > https://gcc.gnu.org/ml/gcc-patches/2016-05/msg01042.html , I'll make sure > they are consistant with respect to testing for SSA_NAME / !POINTER_TYPE_P > if I get feedback on either (today I am leaning towards adding all possible > checks, just to be sure).
Yeah, better be safe than sorry. > Bootstrap+regtest on powerpc64le-unknown-linux-gnu. Ok with the missing INTEGRAL_TYPE_P check. Thanks, Richard. > > 2016-05-17 Marc Glisse <marc.gli...@inria.fr> > > gcc/ > * match.pd (X & C): New transformation. > > gcc/testsuite/ > * gcc.dg/tree-ssa/and-1.c: New testcase. > > -- > Marc Glisse > Index: gcc/match.pd > =================================================================== > --- gcc/match.pd (revision 236300) > +++ gcc/match.pd (working copy) > @@ -548,20 +548,28 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (simplify > (bit_and @0 integer_all_onesp) > (non_lvalue @0)) > > /* x & x -> x, x | x -> x */ > (for bitop (bit_and bit_ior) > (simplify > (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 ((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)) > (bit_and (plus @0 @1) (bit_not @1))) > > /* x & ~(x & y) -> x & ~y */ > /* x | ~(x | y) -> x | ~y */ > (for bitop (bit_and bit_ior) > (simplify > (bitop:c @0 (bit_not (bitop:cs @0 @1))) > Index: gcc/testsuite/gcc.dg/tree-ssa/and-1.c > =================================================================== > --- gcc/testsuite/gcc.dg/tree-ssa/and-1.c (revision 0) > +++ gcc/testsuite/gcc.dg/tree-ssa/and-1.c (working copy) > @@ -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" } } */ >