]> git.ipfire.org Git - thirdparty/gcc.git/commit
vect: Ensure we add vector skip guard even when versioning for aliasing [PR118211]
authorAlex Coplan <alex.coplan@arm.com>
Thu, 25 Jul 2024 16:34:05 +0000 (16:34 +0000)
committerTamar Christina <tamar.christina@arm.com>
Fri, 10 Jan 2025 21:21:07 +0000 (21:21 +0000)
commitf4e259b4a66c81c234608056117836e13606e4c8
tree6bbcc47e07d1e6263c8613505f3a91e53b0239a5
parentf1c6789ab6c5443ccefab96c74b0e862119d1781
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.
gcc/testsuite/gcc.dg/vect/vect-early-break_130.c [new file with mode: 0644]
gcc/tree-vect-loop-manip.cc