[Bug tree-optimization/112104] loop of ^1 should just be reduced to ^(n&1)

"cvs-commit at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112104

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

https://gcc.gnu.org/g:62993cc9d2200ef7a05f317cdef3262996c0ac10

commit r17-3460-g62993cc9d2200ef7a05f317cdef3262996c0ac10
Author: Eikansh Gupta <[email protected]>
Date:   Thu Jul 23 17:04:17 2026 +0530

    tree-optimization: Handle variable trip count XOR in final value
replacement [PR112104]

    analyze_and_compute_bitop_with_inv_effect replaces a loop that repeatedly
    applies a bitwise op with a loop-invariant operand by its closed form.  The
    BIT_XOR case only handled a constant trip count; for a variable count it
    bailed out, leaving loops like "for (i=0;i<n;i++) j ^= 1;" in place.

    Mask the invariant with that runtime parity to handle a variable count.
    A constant count folds as before.

            PR tree-optimization/112104

    gcc/ChangeLog:

            * tree-scalar-evolution.cc
(analyze_and_compute_bitop_with_inv_effect):
            Handle BIT_XOR_EXPR with a variable trip count.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/pr105735-1.c: Bump final value replacement count
            from 8 to 9.
            * gcc.target/i386/pr105735-3.c: Likewise.
            * gcc.dg/tree-ssa/pr112104-1.c: New test.
            * gcc.dg/tree-ssa/pr112104-2.c: New test.

    Signed-off-by: Eikansh Gupta <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.