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

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

https://gcc.gnu.org/g:09e8d26982bf4280ec41b2e5215a57900517db7c

commit r17-5801-g09e8d26982bf4280ec41b2e5215a57900517db7c
Author: Steve Bezalel <[email protected]>
Date:   Fri Oct 30 02:47:27 2026 +0000

    tree-optimization/127211 - Reset SCEV after predcom without unrolling

    tree_predictive_commoning only resets SCEV when a loop was unrolled or
    needed loop-closed SSA fixup (changed > 1).  When a loop is transformed
    without either, the SCEV results cached by predcom's data-reference
    analysis survive the transform.  At -O2, where predcom only runs
    implicitly with -ftree-loop-vectorize and never unrolls, that is the
    common case.

    In the testcase, the evolution of s is cached as not analyzable while
    its step is still a load of a[4].  Predcom then hoists that load, after
    which s is the affine IV {a_I_lsm0.4_26, +, a_I_lsm0.4_26}_1, but ivopts
    still reads the cached result, finds no niter and does not
    strength-reduce the b[s] store.

    At plain -O2 this is hidden because passes between predcom and ivopts
    clear the SCEV cache as a side effect: fre4 in pass_pre_slp_scalar_cleanup,
    and slp1 through the SSA name freelist flush.  -fno-tree-slp-vectorize
    disables both.

    The fix resets SCEV whenever predcom changed something.

    Bootstrapped and regtested on x86_64-pc-linux-gnu.  OK for trunk?

            PR tree-optimization/127211

    gcc/ChangeLog:

            * tree-predcom.cc (tree_predictive_commoning): Reset SCEV
            whenever a loop was transformed, not only when unrolled.

    gcc/testsuite/ChangeLog:

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

    Signed-off-by: Steve Bezalel <[email protected]>

Reply via email to