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

--- Comment #16 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tamar Christina <tnfch...@gcc.gnu.org>:

https://gcc.gnu.org/g:28310b3ff84616cea242cb4cef8f16b4538dbd22

commit r16-2633-g28310b3ff84616cea242cb4cef8f16b4538dbd22
Author: Pengfei Li <pengfei....@arm.com>
Date:   Wed Jul 30 10:54:14 2025 +0100

    vect: Add missing skip-vector check for peeling with versioning [PR121020]

    This fixes a miscompilation issue introduced by the enablement of
    combined loop peeling and versioning. A test case that reproduces the
    issue is included in the patch.

    When performing loop peeling, GCC usually inserts a skip-vector check.
    This ensures that after peeling, there are enough remaining iterations
    to enter the main vectorized loop. Previously, the check was omitted if
    loop versioning for alignment was applied. It was safe before because
    versioning and peeling for alignment were mutually exclusive.

    However, with combined peeling and versioning enabled, this is not safe
    any more. A loop may be peeled and versioned at the same time. Without
    the skip-vector check, the main vectorized loop can be entered even if
    its iteration count is zero. This can cause the loop running many more
    iterations than needed, resulting in incorrect results.

    To fix this, the patch updates the condition of omitting the skip-vector
    check to when versioning is performed alone without peeling.

    gcc/ChangeLog:

            PR tree-optimization/121020
            * tree-vect-loop-manip.cc (vect_do_peeling): Update the
            condition of omitting the skip-vector check.
            * tree-vectorizer.h (LOOP_VINFO_USE_VERSIONING_WITHOUT_PEELING):
            Add a helper macro.

    gcc/testsuite/ChangeLog:

            PR tree-optimization/121020
            * gcc.dg/vect/vect-early-break_138-pr121020.c: New test.

Reply via email to