diff --git a/gcc/testsuite/gcc.dg/vect/vect-pr124677.c b/gcc/testsuite/gcc.dg/vect/vect-pr124677.c new file mode 100644 index 00000000000..ee00a5612a3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-pr124677.c @@ -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; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 7121edb8d81..5d4af8c8ee5 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -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) {