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

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

https://gcc.gnu.org/g:372d44c5611ecce9144c985a849ca06f108289fe

commit r17-2916-g372d44c5611ecce9144c985a849ca06f108289fe
Author: Avinal Kumar <[email protected]>
Date:   Mon Aug 3 21:48:01 2026 -0600

    [PATCH] match: Simplify `(A | C) == A` to `(A & C) != 0` when C is power of
2 [PR101650]

    The expression (A | C) == A tests if all the bits in C are already set
    in A.  When C is a power of 2, this is equivalent to (A & C) != 0 which
    avoids OR and compares against 0 instead of original value thus
    optimizing the comparison.

    Similarly (A | C) != A can be optimized to (A & C) == 0.

    ---
    Bootstrapped and ran full test suite on x86_64 Fedora Linux.

    Output for this particular patch test:

    cat gcc/testsuite/gcc/gcc.sum | grep bitcmp-7

    PASS: gcc.dg/tree-ssa/bitcmp-7.c (test for excess errors)
    PASS: gcc.dg/tree-ssa/bitcmp-7.c scan-tree-dump-not optimized "\\| 4"
    PASS: gcc.dg/tree-ssa/bitcmp-7.c scan-tree-dump-times optimized " & 4" 2

    I also included some whitespace changes in some comments. Please let me
know
    if they should be a separate change.

            PR tree-optimization/101650

    gcc/ChangeLog:

            * match.pd: Simplify (A | C) == A to (A & C) != 0 when C is
            power of 2.

    gcc/testsuite/ChangeLog:

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

    Signed-off-by: Avinal Kumar <[email protected]>

Reply via email to