]> 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>
Fri, 5 Apr 2024 12:56:14 +0000 (14:56 +0200)
commita844095e17c1a5aada1364c6f6eaade87ead463c
treeaec22e346c4169882a17dd32f8b54bf0e0baf541
parent6f1005649ff5f544eefba29ba4fb121dba0c6683
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.
gcc/testsuite/gcc.target/i386/avx512f-pr114566.c [new file with mode: 0644]
gcc/tree-vect-loop.cc