https://gcc.gnu.org/g:963d5362c598d48ee7a896e674d2a68c41179785

commit r16-2120-g963d5362c598d48ee7a896e674d2a68c41179785
Author: Tamar Christina <tamar.christ...@arm.com>
Date:   Wed Jul 9 08:42:02 2025 +0100

    middle-end: Use rounding division for ranges for partial vectors [PR120922]
    
    This patch adds support for niters ranges for partial
    vector loops.
    
    Due to the last iteration being partial the bounds should
    be at least 1 but niters // vf as the max.
    
    gcc/ChangeLog:
    
            PR tree-optimization/120922
            * tree-vect-loop-manip.cc (vect_gen_vector_loop_niters): Support 
range
            for partial vectors.

Diff:
---
 gcc/tree-vect-loop-manip.cc | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index 9c58a6a01d7c..2d01a4b0ed1c 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -2857,11 +2857,21 @@ vect_gen_vector_loop_niters (loop_vec_info loop_vinfo, 
tree niters,
         we set range information to make niters analyzer's life easier.
         Note the number of latch iteration value can be TYPE_MAX_VALUE so
         we have to represent the vector niter TYPE_MAX_VALUE + 1 / vf.  */
-      if (stmts != NULL
-         && const_vf > 0
-         && !LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo))
+      if (stmts != NULL && const_vf > 0)
        {
-         if (niters_no_overflow)
+         if (niters_no_overflow
+             && LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo))
+           {
+             int_range<1> vr (type,
+                              wi::one (TYPE_PRECISION (type)),
+                              wi::div_ceil (wi::max_value
+                                                       (TYPE_PRECISION (type),
+                                                        TYPE_SIGN (type)),
+                                            const_vf,
+                                            TYPE_SIGN (type)));
+             set_range_info (niters_vector, vr);
+           }
+         else if (niters_no_overflow)
            {
              int_range<1> vr (type,
                               wi::one (TYPE_PRECISION (type)),

Reply via email to