[Bug tree-optimization/126225] [13/14/15/16 Regression] Wrong code at -O2 due to incorrect SLP IV reuse (r11-4714)

"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=126225

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

https://gcc.gnu.org/g:65ba830f4ec193acd44f738217ff36490ead67b3

commit r16-9381-g65ba830f4ec193acd44f738217ff36490ead67b3
Author: Cem Akgok <[email protected]>
Date:   Mon Jul 13 17:21:46 2026 +0300

    vect: Fix wrong code with SLP IV reuse [PR126225]

    vectorizable_induction reduces the number of generated SLP induction
    IVs when group_size is evenly divisible by const_nunits. Existing
    code did this without checking that the vector chunks being folded have
    the same scalar initial values and steps with their counterparts.
    If either differed, reusing an earlier IV produced wrong code.

    Compute the unreduced IV count first and use the reduced count only when
    each folded chunk has initial values and steps equal to its corresponding
    earlier chunk.

    Added tests for mismatched initial values, mismatched steps, and a valid
    multi-IV reuse pattern.

    gcc/ChangeLog:

            PR tree-optimization/126225
            * tree-vect-loop.cc (vect_slp_induction_reuse_p): New function.
            (vectorizable_induction): Validate SLP induction IV reuse.  Reuse
            generated IVs cyclically when filling the SLP group.

    gcc/testsuite/ChangeLog:

            PR tree-optimization/126225
            * gcc.dg/vect/vect-iv-12.c: New test.
            * gcc.dg/vect/vect-iv-13.c: New test.
            * gcc.dg/vect/vect-iv-14.c: New test.

    Signed-off-by: Cem Akgok <[email protected]>
    (cherry picked from commit 6c1a23f4bfe2403c12439c299064af557b317737)
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.