]> git.ipfire.org Git - thirdparty/gcc.git/commit
vect: Don't clear base_misaligned in update_epilogue_loop_vinfo [PR114566]
authorJakub Jelinek <jakub@redhat.com>
Fri, 5 Apr 2024 12:56:14 +0000 (14:56 +0200)
committerJakub Jelinek <jakub@redhat.com>
Sun, 21 Apr 2024 04:08:05 +0000 (06:08 +0200)
commit38af0d59043da4cc07cd62c17da599e43668e3be
tree423a12e56dfdd2ce040c7ee386d393f889b1cb95
parent910fa4d9df8f72d16279324cca2bf1f2649aa68b
vect: Don't clear base_misaligned in update_epilogue_loop_vinfo [PR114566]

The following testcase is miscompiled, because in the vectorized
epilogue the vectorizer assumes it can use aligned loads/stores
(if the base decl gets alignment increased), but it actually doesn't
increase that.
This is because r10-4203-g97c1460367 added the hunk following
patch removes.  The explanation feels reasonable, but actually it
is not true as the testcase proves.
The thing is, we vectorize the main loop with 64-byte vectors
and the corresponding data refs have base_alignment 16 (the
a array has DECL_ALIGN 128) and offset_alignment 32.  Now, because
of the offset_alignment 32 rather than 64, we need to use unaligned
loads/stores in the main loop (and ditto in the first load/store
in vectorized epilogue).  But the second load/store in the vectorized
epilogue uses only 32-byte vectors and because it is a multiple
of offset_alignment, it checks if we could increase alignment of the
a VAR_DECL, the function returns true, sets base_misaligned = true
and says the access is then aligned.
But when update_epilogue_loop_vinfo clears base_misaligned with the
assumption that the var had to have the alignment increased already,
the update of DECL_ALIGN doesn't happen anymore.

Now, I'd think this base_alignment = false was needed before
r10-4030-gd2db7f7901 change was committed where it incorrectly
overwrote DECL_ALIGN even if it was already larger, rather than
just always increasing it.  But with that change in, it doesn't
make sense to me anymore.

Note, the testcase is latent on the trunk, but reproduces on the 13
branch.

2024-04-05  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/114566
* tree-vect-loop.cc (update_epilogue_loop_vinfo): Don't clear
base_misaligned.

* gcc.target/i386/avx512f-pr114566.c: New test.

(cherry picked from commit a844095e17c1a5aada1364c6f6eaade87ead463c)
gcc/testsuite/gcc.target/i386/avx512f-pr114566.c [new file with mode: 0644]
gcc/tree-vect-loop.cc