https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113467
--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
I do wonder whether LOOP_VINFO_EARLY_BREAKS_VECT_PEELED actually works (since
without early exits we cannot handle a non-empty latch because of correctness
issues). I'd very much have preferred to deal with these by loop rotation
(there's the loop_ch pass). We're still doing this, even when
LOOP_VINFO_EARLY_BREAKS_VECT_PEELED:
/* We assume that the loop exit condition is at the end of the loop. i.e,
that the loop is represented as a do-while (with a proper if-guard
before the loop if needed), where the loop header contains all the
executable statements, and the latch is empty. */
if (!empty_block_p (loop->latch)
|| !gimple_seq_empty_p (phi_nodes (loop->latch)))
return opt_result::failure_at (vect_location,
"not vectorized: latch block not empty.\n");
so that's a bit odd (but loop_ch tries to ensure the latch is empty anyway).
Does the following fix the issue?
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 330c4571c8d..b67ee783002 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -998,6 +1000,9 @@ vec_init_loop_exit_info (class loop *loop)
}
}
+ if (candidate->src != single_pred (loop->latch))
+ return NULL;
+
return candidate;
}