`vect_verify_loop_lens' determines the precision required for the
loop-control induction variable using the maximum number of
scalar iterations and the precision of `LOOP_VINFO_NITERS'.
For uncounted loops, however, the scalar iteration count is
unknown, and `LOOP_VINFO_NITERS' cannot be used to determine the
required precision.
Handle uncounted loops separately by using the precision of
`Pmode' as the minimum requirement for the induction variable.
Retain the existing precision calculation for counted loops.
This allows targets using length-based partial vectors, such
as RISC-V RVV, to verify loop controls for uncounted loops.
gcc/ChangeLog:
* tree-vect-loop.cc (vect_verify_loop_lens): Use Pmode
precision as the minimum induction-variable precision for
uncounted loops.
---
gcc/tree-vect-loop.cc | 34 +++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 955fb7414ef..a37f7febdda 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -1317,24 +1317,28 @@ vect_verify_loop_lens (loop_vec_info loop_vinfo)
max_nitems_per_iter = MAX (max_nitems_per_iter, nitems_per_iter);
}
- /* Work out how many bits we need to represent the length limit. */
- unsigned int min_ni_prec
- = vect_min_prec_for_max_niters (loop_vinfo, max_nitems_per_iter);
+ unsigned int min_ni_prec = GET_MODE_BITSIZE (Pmode);
- /* Now use the maximum of below precisions for one suitable IV type:
- - the IV's natural precision
- - the precision needed to hold: the maximum number of scalar
- iterations multiplied by the scale factor (min_ni_prec above)
- - the Pmode precision
+ if (!LOOP_VINFO_NITERS_UNCOUNTED_P (loop_vinfo))
+ {
+ /* Work out how many bits we need to represent the length limit. */
+ min_ni_prec
+ = vect_min_prec_for_max_niters (loop_vinfo, max_nitems_per_iter);
- If min_ni_prec is less than the precision of the current niters,
- we prefer to still use the niters type. Prefer to use Pmode and
- wider IV to avoid narrow conversions. */
+ /* Now use the maximum of below precisions for one suitable IV type:
+ - the IV's natural precision
+ - the precision needed to hold: the maximum number of scalar
+ iterations multiplied by the scale factor (min_ni_prec above)
+ - the Pmode precision
- unsigned int ni_prec
- = TYPE_PRECISION (TREE_TYPE (LOOP_VINFO_NITERS (loop_vinfo)));
- min_ni_prec = MAX (min_ni_prec, ni_prec);
- min_ni_prec = MAX (min_ni_prec, GET_MODE_BITSIZE (Pmode));
+ If min_ni_prec is less than the precision of the current niters,
+ we prefer to still use the niters type. Prefer to use Pmode and
+ wider IV to avoid narrow conversions. */
+ unsigned int ni_prec
+ = TYPE_PRECISION (TREE_TYPE (LOOP_VINFO_NITERS (loop_vinfo)));
+ min_ni_prec = MAX (min_ni_prec, ni_prec);
+ min_ni_prec = MAX (min_ni_prec, GET_MODE_BITSIZE (Pmode));
+ }
tree iv_type = NULL_TREE;
opt_scalar_int_mode tmode_iter;
--
2.43.0