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

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

https://gcc.gnu.org/g:35f921dfbf1f548fc5b14cd39c17d673e3588c72

commit r17-7039-g35f921dfbf1f548fc5b14cd39c17d673e3588c72
Author: Tamar Christina <[email protected]>
Date:   Wed Dec 2 17:16:59 2026 +0000

    vect: Skip zero-trip peeled early-break vectors [PR129241]

    With an early break peeled loop the loop body can be tested once more
    than the body runs.  That matters when the known iteration count is exactly
the
    vectorization factor.  For example:

        int xs[4] = { 0, 8, 4, 3 };
        int *p = xs;
        int *q = xs + 3;
        while (p != q)
          if (*p++ & 3)
            __builtin_abort ();

    The scalar loop reads only xs[0] through xs[2].  SCEV records three latch
    executions and LOOP_VINFO_NITERS is four: the fourth visit to the header
    exits before reaching the load.  With VF 4, vect_gen_vector_loop_niters
    correctly computes (4 - 1) / 4 = 0 complete vectors.  The known-count
    skip check however sees 4 < 4 as false, so it omits the guard.

    After the counted exit is moved to the latch, the vector body runs once
    and tests xs[3], where 3 & 3 causes the abort.

    This fixes it by adjusting min_iters with +1, to match the peeling code.

    This is latent but can't be triggered pre GCC-17.

    gcc/ChangeLog:

            PR tree-optimization/129241
            * tree-vect-loop-manip.cc (vect_do_peeling): Account for the
            header-only iteration when deciding whether to guard a full-vector
            peeled early-break loop.

    gcc/testsuite/ChangeLog:

            PR tree-optimization/129241
            * gcc.dg/vect/vect-early-break_152-pr129241.c: New test.

Reply via email to