On Mon, 10 Nov 2025, Victor Do Nascimento wrote:

> The iteration count profitability check is irrelevant for uncounted
> loops given that, even at runtime, the number of iterations is unknown
> at the start of loop execution.
> 
> Likewise, the test for skipping the vectorized version of the loop is
> based on whether the number of iterations that will be run for the
> loop and whether it is smaller than the vectorization factor.  As this
> is undetermined, the check can never be run for uncounted loops.
> 
> Consequently, we skip these checks.
> 
> gcc/ChangeLog:
> 
>       * tree-vect-loop-manip.cc (vect_loop_versioning): skip
>       profitability check for uncounted loops.
>       * tree-vect-loop-manip.cc (vect_do_peeling): Disable vector
>       loop skip checking.
> ---
>  gcc/tree-vect-loop-manip.cc | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
> index 18a5059251b..640735388fe 100644
> --- a/gcc/tree-vect-loop-manip.cc
> +++ b/gcc/tree-vect-loop-manip.cc
> @@ -3293,11 +3293,13 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree 
> niters, tree nitersm1,
>       because we have asserted that there are enough scalar iterations to 
> enter
>       the main loop, so this skip is not necessary.  When we are versioning 
> then
>       we only add such a skip if we have chosen to vectorize the epilogue.  */
> -  bool skip_vector = (LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
> -                   ? maybe_lt (LOOP_VINFO_INT_NITERS (loop_vinfo),
> -                               bound_prolog + bound_epilog)
> -                   : (!LOOP_VINFO_USE_VERSIONING_WITHOUT_PEELING (loop_vinfo)
> -                      || vect_epilogues));
> +  bool skip_vector = false;
> +  if (!uncounted_p)
> +    skip_vector = (LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
> +                ? maybe_lt (LOOP_VINFO_INT_NITERS (loop_vinfo),
> +                            bound_prolog + bound_epilog)
> +                : (!LOOP_VINFO_USE_VERSIONING_WITHOUT_PEELING (loop_vinfo)
> +                   || vect_epilogues));
>  
>    /* Epilog loop must be executed if the number of iterations for epilog
>       loop is known at compile time, otherwise we need to add a check at
> @@ -4157,13 +4159,14 @@ vect_loop_versioning (loop_vec_info loop_vinfo,
>    tree version_simd_if_cond
>      = LOOP_REQUIRES_VERSIONING_FOR_SIMD_IF_COND (loop_vinfo);
>    unsigned th = LOOP_VINFO_COST_MODEL_THRESHOLD (loop_vinfo);
> +  bool uncounted_p = LOOP_VINFO_NITERS_UNCOUNTED_P (loop_vinfo);
>  
>    if (vect_apply_runtime_profitability_check_p (loop_vinfo)
> -      && !ordered_p (th, versioning_threshold))
> +      && !ordered_p (th, versioning_threshold) && !uncounted_p)

can you test !uncounted_p first, before calling
vect_apply_runtime_profitability_check_p?

Otherwise OK.

Richard.

>      cond_expr = fold_build2 (GE_EXPR, boolean_type_node, scalar_loop_iters,
>                            build_int_cst (TREE_TYPE (scalar_loop_iters),
>                                           th - 1));
> -  if (maybe_ne (versioning_threshold, 0U))
> +  if (!uncounted_p && maybe_ne (versioning_threshold, 0U))
>      {
>        tree expr = fold_build2 (GE_EXPR, boolean_type_node, scalar_loop_iters,
>                              build_int_cst (TREE_TYPE (scalar_loop_iters),
> 

-- 
Richard Biener <[email protected]>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

Reply via email to