On Tue, Sep 05, 2017 at 11:21:48PM -0600, Jeff Law wrote:
> --- a/gcc/tree-ssa-reassoc.c
> +++ b/gcc/tree-ssa-reassoc.c
> @@ -5763,14 +5763,15 @@ reassociate_bb (basic_block bb)
>                            "Width = %d was chosen for reassociation\n", 
> width);
>  
>  
> -               /* For binary bit operations, if the last operand in
> -                  OPS is a constant, move it to the front.  This
> -                  helps ensure that we generate (X & Y) & C rather
> -                  than (X & C) & Y.  The former will often match
> -                  a canonical bit test when we get to RTL.  */
> -               if ((rhs_code == BIT_AND_EXPR
> -                    || rhs_code == BIT_IOR_EXPR
> -                    || rhs_code == BIT_XOR_EXPR)
> +               /* For binary bit operations, if there are at least 3
> +                  operands and the last last operand in OPS is a constant,
> +                  move it to the front.  This helps ensure that we generate
> +                  (X & Y) & C rather than (X & C) & Y.  The former will
> +                  often match a canonical bit test when we get to RTL.  */
> +               if (ops.length () != 2

So wouldn't it be clearer to write ops.length () > 2 ?
if (ops.length () == 0)
else if (ops.length () == 1)
come earlier, so it is the same thing, but might help the reader.

> +                   && (rhs_code == BIT_AND_EXPR
> +                       || rhs_code == BIT_IOR_EXPR
> +                       || rhs_code == BIT_XOR_EXPR)
>                     && TREE_CODE (ops.last ()->op) == INTEGER_CST)
>                   std::swap (*ops[0], *ops[ops_num - 1]);

Don't you then want to put the constant as second operand rather than first,
i.e. swap with *ops[1]?
And doesn't swap_ops_for_binary_stmt undo it again?

        Jakub

Reply via email to