https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116126
--- Comment #6 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:f4e259b4a66c81c234608056117836e13606e4c8 commit r15-6810-gf4e259b4a66c81c234608056117836e13606e4c8 Author: Alex Coplan <alex.cop...@arm.com> Date: Thu Jul 25 16:34:05 2024 +0000 vect: Ensure we add vector skip guard even when versioning for aliasing [PR118211] This fixes a latent wrong code issue whereby vect_do_peeling determined the wrong condition for inserting the vector skip guard. Specifically in the case where the loop niters are unknown at compile time we used to check: !LOOP_REQUIRES_VERSIONING (loop_vinfo) but LOOP_REQUIRES_VERSIONING is true for loops which we have versioned for aliasing, and that has nothing to do with prolog peeling. I think this condition should instead be checking specifically if we aren't versioning for alignment. As it stands, when we version for alignment, we don't peel, so the vector skip guard is indeed redundant in that case. With the testcase added (reduced from the Fortran frontend) we would version for aliasing, omit the vector skip guard, and then at runtime we would peel sufficient iterations for alignment that there wasn't a full vector iteration left when we entered the vector body, thus overflowing the output buffer. gcc/ChangeLog: PR tree-optimization/118211 PR tree-optimization/116126 * tree-vect-loop-manip.cc (vect_do_peeling): Adjust skip_vector condition to only omit the edge if we're versioning for alignment. gcc/testsuite/ChangeLog: PR tree-optimization/118211 PR tree-optimization/116126 * gcc.dg/vect/vect-early-break_130.c: New test.