On 06/11/2026 17:28, Victor Do Nascimento wrote:
For counted loops, `vect_set_loop_condition' replaces the scalar
main exit condition with a condition based on the vectorized
iteration count.

For uncounted loops using partial vectors, however, the main
exit is handled as an early-break exit, and its condition has
already been transformed by the early-break machinery.

Avoid replacing this condition a second time, since doing so
would discard the vectorized early-break exit test.

gcc/ChangeLog:

        * tree-vect-loop-manip.cc (vect_set_loop_condition): Preserve
        the existing exit condition for uncounted loops using partial
        vectors.
---
  gcc/tree-vect-loop-manip.cc | 7 +++++++
  1 file changed, 7 insertions(+)

diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index 07a75400174..f57118337ca 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -1452,6 +1452,13 @@ vect_set_loop_condition (class loop *loop, edge loop_e, 
loop_vec_info loop_vinfo
                                                step, final_iv,
                                                niters_maybe_zero);
+ if (loop_vinfo
+      && (LOOP_VINFO_NITERS_UNCOUNTED_P (loop_vinfo)
+         && LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo)))
+    return;
I may be way off here, so feel free to disregard but...

It feels a bit strange to be calling vect_set_loop_condition on an uncounted loop at all, and then especially strange for vect_set_loop_condition to _not_ set the condition.

I would expect instead to never call this function for uncounted loops and to have another logic path for setting up masks and ivs for an uncounted loop. Hopefully refactoring out quite a bit of shared behaviour?

+
+  gcc_assert (cond_stmt);
+
    /* A peeled early-break loop is entered only when it has at least one
       vector iteration to execute.  Test the IV after that iteration rather
       than before it, regardless of the style of loop control.  */

Reply via email to