tree-optimization/124677 - wrong recurrence permute placement

When vectorizing a recurrence we have to skip inserted vector
stmts for the latch definition when finding the insertion point
for the permute.

	PR tree-optimization/124677
	* tree-vect-loop.cc (vectorizable_recurr): Skip vector
	stmts for the def.

	* gcc.dg/vect/vect-pr124677.c: New testcase.
This commit is contained in:
Richard Biener
2026-03-30 10:41:15 +02:00
committed by Richard Biener
parent 3d4039e95d
commit 32cb5f67ab
2 changed files with 32 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
/* { dg-do compile } */
/* { dg-additional-options "-O3 -fno-tree-copy-prop" } */
int printf(const char *, ...);
int a, b, c, d, e;
int g(int h) { return h >> a; }
int main()
{
int j = c;
while (a)
while (1)
{
while (1)
{
for (e = 0; e < 16; e++)
{
d = b;
j && (b = g(2));
}
break;
}
printf("%d\n", b);
}
return 0;
}

View File

@@ -8863,7 +8863,13 @@ vectorizable_recurr (loop_vec_info loop_vinfo, stmt_vec_info stmt_info,
edge le = loop_latch_edge (LOOP_VINFO_LOOP (loop_vinfo));
gimple *latch_def = SSA_NAME_DEF_STMT (PHI_ARG_DEF_FROM_EDGE (phi, le));
gimple_stmt_iterator gsi2 = gsi_for_stmt (latch_def);
gsi_next (&gsi2);
do
{
gsi_next (&gsi2);
}
/* Skip inserted vectorized stmts for the latch definition. We have to
insert after those. */
while (gimple_uid (gsi_stmt (gsi2)) == 0);
for (unsigned i = 0; i < ncopies; ++i)
{