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

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Daniel Barboza <[email protected]>:

https://gcc.gnu.org/g:59afbbd3cd6b4348e9badc972eb3f46c2cdd023d

commit r17-5945-g59afbbd3cd6b4348e9badc972eb3f46c2cdd023d
Author: Daniel Barboza <[email protected]>
Date:   Wed Oct 28 15:41:49 2026 -0300

    match.pd: (X ^ Y) & (X | Y) -> X ^ Y patterns [PR115547]

    Add a couple of match.pd patterns that simplifies a bit_and using a
    bit_xor and a bit_ior with the same operands:

    (X ^ Y) & (X | Y) -> X ^ Y

    For boolean values there is also a NE variant:

    (X NE Y) & (X | Y) -> X NE Y

    Also, for boolean values, we're also handling chained bit_iors:

    (X ^ Y)  & (Z | X | Y) -> (X ^ Y)
    (X NE Y) & (Z | X | Y) -> (X NE Y)

    The takeaway is that if we know that X != Y then X != Y & (X | Y | ...)
    is always going to be the same as X != Y.

    The remaining PR115547 patterns that uses "&&" generate chained ifconds
    that can't be handled via match.pd.  We'll try our luck handling those
    inside one of the passes at a later date.

    Bootstrapped and regression tested in x86_64.

            PR tree-optimization/115547

    gcc/ChangeLog:

            * match.pd(`(X ^ Y) & (X | Y)`): New pattern.
            (`(X NE Y) & (X | Y)`): New pattern.
            (`(X NE Y) & (Z | X | Y)`): New pattern.
            (`(X ^ Y) & (Z | X | Y)`): New pattern.

    gcc/testsuite/ChangeLog:

            * gcc.dg/tree-ssa/pr115547.c: New test.

Reply via email to