On 06/11/2026 17:28, Victor Do Nascimento wrote:
With the key machinery enabling the use of partial vectors and masking
for alignment being implemented in
`vect_set_loop_condition_partial_vectors{,_avx512}', the execution
path connecting the main transformation function `vect_transform_loop'
with the partial-vector enablement code must be modified when handling
uncounted loops such that we don't fail prematurely before reaching
the target functionality, relaxing the restriction on the call to
`vect_set_loop_condition' in `vect_transform_loop' to counted loops.
Here, we therefore relax the `vect_transform_loop' ->
`vect_set_loop_condition' call constraints so that it is allowed
either under the `!uncounted_p' condition or, alternatively, under the
`uncounted_p && LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo))'
condition.
A further modification requirement in `vect_transform_loop' is that
for counted loops, the vector iteration step is initialized as
part of the calculation of the vectorized iteration count.
Uncounted loops do not require this calculation, but still need
the vector iteration step when generating loop controls.
We therefore also initialize `step_vector' to the vectorization
factor for uncounted loops.
Finally, we allow `vect_set_loop_condition' to skip the
condition update, returning a nullptr for `cond_stmt' for uncounted
loops, when there is no IV-counting exit to update.
gcc/ChangeLog:
* tree-vect-loop-manip.cc (vect_set_loop_condition): Initialize
cond_stmt to nullptr.
* tree-vect-loop.cc (vect_transform_loop): Allow uncounted
loops using partial vectors to call vect_set_loop_condition.
---
gcc/tree-vect-loop-manip.cc | 2 +-
gcc/tree-vect-loop.cc | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index f57118337ca..f5af874a210 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -1415,7 +1415,7 @@ vect_set_loop_condition (class loop *loop, edge loop_e,
loop_vec_info loop_vinfo
tree niters, tree step, tree final_iv,
bool niters_maybe_zero)
{
- gcond *cond_stmt;
+ gcond *cond_stmt = nullptr;
gcond *orig_cond = get_loop_exit_condition (loop_e);
gimple_stmt_iterator loop_cond_gsi = gsi_for_stmt (orig_cond);
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index c52c584cf52..d6dc75d32b5 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -11579,6 +11579,8 @@ vect_transform_loop (loop_vec_info loop_vinfo, gimple
*loop_vectorized_call)
&niters_vector, &step_vector,
niters_no_overflow);
}
+ else if (uncounted_p)
+ step_vector = build_int_cst (sizetype, vf);
This should be LOOP_VINFO_IV_INCREMENT.
/* 1) Make sure the loop header has exactly two entries
2) Make sure we have a preheader basic block. */
@@ -11687,7 +11689,9 @@ vect_transform_loop (loop_vec_info loop_vinfo, gimple
*loop_vectorized_call)
}
}
- if (!uncounted_p)
+ if (!uncounted_p
+ || (uncounted_p
+ && LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo)))
Minor nit, but this can just be
+ if (!uncounted_p || LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo))
which is logically equivalent and in my opinion slightly more
understandable.
Also, I still think using vect_set_loop_condition for this is a bit
unnatural.
{
/* The vectorization factor is always > 1, so if we use an IV increment
of
1. A zero NITERS becomes a nonzero NITERS_VECTOR. */