https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71343

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Roger Sayle <sa...@gcc.gnu.org>:

https://gcc.gnu.org/g:03acd8b6429e22068330dce5abf129291d3f26de

commit r13-2047-g03acd8b6429e22068330dce5abf129291d3f26de
Author: Roger Sayle <ro...@nextmovesoftware.com>
Date:   Mon Aug 15 17:32:26 2022 +0100

    PR tree-optimization/71343: Optimize (X<<C)&(Y<<C) as (X&Y)<<C.

    This patch is the first part of a solution to PR tree-optimization/71343,
    a missed-optimization enhancement request where GCC fails to see that
    (a<<2)+(b<<2) == a*4+b*4.

    This piece is that (X<<C) op (Y<<C) can be simplified to (X op Y) << C,
    for many binary operators, including AND, IOR, XOR, and (if overflow
    isn't an issue) PLUS and MINUS.  Likewise, the right shifts (both logical
    and arithmetic) and bit-wise logical operators can be simplified in a
    similar fashion.  These all reduce the number of GIMPLE binary operations
    from 3 to 2, by combining/eliminating a shift operation.

    2022-08-15  Roger Sayle  <ro...@nextmovesoftware.com>
                Richard Biener  <rguent...@suse.de>

    gcc/ChangeLog
            PR tree-optimization/71343
            * match.pd (op (lshift @0 @1) (lshift @2 @1)): Optimize the
            expression (X<<C) + (Y<<C) to (X+Y)<<C for multiple operators.
            (op (rshift @0 @1) (rshift @2 @1)): Likewise, simplify
(X>>C)^(Y>>C)
            to (X^Y)>>C for binary logical operators, AND, IOR and XOR.

    gcc/testsuite/ChangeLog
            PR tree-optimization/71343
            * gcc.dg/pr71343-1.c: New test case.

Reply via email to