From 18e905b461a7138185cf4f0efde4a4e1214fb798 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 30 Sep 2024 13:38:28 +0200 Subject: tree-optimization/116879 - failure to recognize non-empty latch When we relaxed the vectorizers constraint on loop structure verifying the emptiness of the latch became too lose as can be seen in the case for PR116879 where the latch effectively contains two basic-blocks which one being an unmerged forwarder that's not empty. PR tree-optimization/116879 * tree-vect-loop.cc (vect_analyze_loop_form): Scan all blocks that form the latch. * gcc.dg/pr116879.c: New testcase. --- gcc/tree-vect-loop.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'gcc/tree-vect-loop.cc') diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 5cd4bdb..0ce1bf8 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -1851,10 +1851,17 @@ vect_analyze_loop_form (class loop *loop, vect_loop_form_info *info) " too many incoming edges.\n"); /* We assume that 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"); + basic_block latch = loop->latch; + do + { + if (!empty_block_p (latch) + || !gimple_seq_empty_p (phi_nodes (latch))) + return opt_result::failure_at (vect_location, + "not vectorized: latch block not " + "empty.\n"); + latch = single_pred (latch); + } + while (single_succ_p (latch)); /* Make sure there is no abnormal exit. */ auto_vec exits = get_loop_exit_edges (loop); -- cgit v1.1