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

--- Comment #20 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jakub Jelinek
<ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:f8a327930b82e89ae1466cfacb9e8ac9f5c44e77

commit r12-10520-gf8a327930b82e89ae1466cfacb9e8ac9f5c44e77
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Fri Apr 5 14:56:14 2024 +0200

    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  <ja...@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)

Reply via email to