Skip to content

Commit a844095

Browse files
committed
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 <[email protected]> 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.
1 parent 6f10056 commit a844095

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* PR tree-optimization/114566 */
2+
/* { dg-do run } */
3+
/* { dg-options "-O3 -mavx512f" } */
4+
/* { dg-additional-options "-fstack-protector-strong" { target fstack_protector } } */
5+
/* { dg-require-effective-target avx512f } */
6+
7+
#define AVX512F
8+
#include "avx512f-helper.h"
9+
10+
__attribute__((noipa)) int
11+
foo (float x, float y)
12+
{
13+
float a[8][56];
14+
__builtin_memset (a, 0, sizeof (a));
15+
16+
for (int j = 0; j < 8; j++)
17+
for (int k = 0; k < 56; k++)
18+
{
19+
float b = k * y;
20+
if (b < 0.)
21+
b = 0.;
22+
if (b > 0.)
23+
b = 0.;
24+
a[j][k] += b;
25+
}
26+
27+
return __builtin_log (x);
28+
}
29+
30+
void
31+
TEST (void)
32+
{
33+
foo (86.25f, 0.625f);
34+
}

gcc/tree-vect-loop.cc

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11590,9 +11590,7 @@ find_in_mapping (tree t, void *context)
1159011590
corresponding dr_vec_info need to be reconnected to the EPILOGUE's
1159111591
stmt_vec_infos, their statements need to point to their corresponding copy,
1159211592
if they are gather loads or scatter stores then their reference needs to be
11593-
updated to point to its corresponding copy and finally we set
11594-
'base_misaligned' to false as we have already peeled for alignment in the
11595-
prologue of the main loop. */
11593+
updated to point to its corresponding copy. */
1159611594

1159711595
static void
1159811596
update_epilogue_loop_vinfo (class loop *epilogue, tree advance)
@@ -11736,10 +11734,6 @@ update_epilogue_loop_vinfo (class loop *epilogue, tree advance)
1173611734
}
1173711735
DR_STMT (dr) = STMT_VINFO_STMT (stmt_vinfo);
1173811736
stmt_vinfo->dr_aux.stmt = stmt_vinfo;
11739-
/* The vector size of the epilogue is smaller than that of the main loop
11740-
so the alignment is either the same or lower. This means the dr will
11741-
thus by definition be aligned. */
11742-
STMT_VINFO_DR_INFO (stmt_vinfo)->base_misaligned = false;
1174311737
}
1174411738

1174511739
epilogue_vinfo->shared->datarefs_copy.release ();

0 commit comments

Comments
 (0)