The PR120089 fix added more PHIs to LOOP_VINFO_EARLY_BREAKS_LIVE_IVS but not checking that we only add PHIs with a latch argument. The following adds this missing check.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/120211 * tree-vect-stmts.cc (vect_stmt_relevant_p): Only add PHIs from the loop header to LOOP_VINFO_EARLY_BREAKS_LIVE_IVS. * gcc.dg/vect/vect-early-break_135-pr120211.c: New testcase. * gcc.dg/torture/pr120211-1.c: Likewise. --- gcc/testsuite/gcc.dg/torture/pr120211-1.c | 20 +++++++++++++++++++ .../vect/vect-early-break_135-pr120211.c | 12 +++++++++++ gcc/tree-vect-stmts.cc | 1 + 3 files changed, 33 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr120211-1.c create mode 100644 gcc/testsuite/gcc.dg/vect/vect-early-break_135-pr120211.c diff --git a/gcc/testsuite/gcc.dg/torture/pr120211-1.c b/gcc/testsuite/gcc.dg/torture/pr120211-1.c new file mode 100644 index 00000000000..f9bc97cab5b --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr120211-1.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ + +int a, b, d; +void e() { + do { + int f = 0; + while (1) { + int c = a; + for (; (c & 1) == 0; c = 1) + for (; c & 1;) + ; + if (a) + break; + f++; + } + b = f & 5; + if (b) + break; + } while (d++); +} diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_135-pr120211.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_135-pr120211.c new file mode 100644 index 00000000000..664b60de2aa --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_135-pr120211.c @@ -0,0 +1,12 @@ +/* { dg-add-options vect_early_break } */ +/* { dg-additional-options "-O3 -fno-tree-copy-prop -fno-tree-dominator-opts -fno-tree-loop-ivcanon -fno-tree-pre -fno-code-hoisting" } */ + +int a, b[1]; +int main() { + int c = 0; + for (; c < 1; c++) { + while (a) + c++; + b[c] = 0; + } +} diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index efe6a2c9c42..bd390b26e0a 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -424,6 +424,7 @@ vect_stmt_relevant_p (stmt_vec_info stmt_info, loop_vec_info loop_vinfo, alternate exit. */ if (LOOP_VINFO_EARLY_BREAKS (loop_vinfo) && is_a <gphi *> (stmt) + && gimple_bb (stmt) == LOOP_VINFO_LOOP (loop_vinfo)->header && ((! VECTORIZABLE_CYCLE_DEF (STMT_VINFO_DEF_TYPE (stmt_info)) && ! *live_p) || STMT_VINFO_DEF_TYPE (stmt_info) == vect_induction_def)) -- 2.43.0