https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113576
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index fe631252dc2..28ad03e0b8a 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -991,8 +991,12 @@ vec_init_loop_exit_info (class loop *loop)
{
tree may_be_zero = niter_desc.may_be_zero;
if ((integer_zerop (may_be_zero)
- || integer_nonzerop (may_be_zero)
- || COMPARISON_CLASS_P (may_be_zero))
+ /* As we are handling may_be_zero that's not false by
+ rewriting niter to may_be_zero ? 0 : niter we require
+ an empty latch. */
+ || (exit->src == single_pred (loop->latch)
+ && (integer_nonzerop (may_be_zero)
+ || COMPARISON_CLASS_P (may_be_zero))))
&& (!candidate
|| dominated_by_p (CDI_DOMINATORS, exit->src,
candidate->src)))
fixes it, I'm testing this.