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.

Bootstrapped Regtested on aarch64-none-linux-gnu,
arm-none-linux-gnueabihf, x86_64-pc-linux-gnu
-m32, -m64 and no issues.

Tested testcase on riscv64-unknown-linux-gnu. Should use
the same testcase as patch 1.

Ok for master?

Thanks,
Tamar

gcc/ChangeLog:

        PR tree-optimization/120922
        * tree-vect-loop-manip.cc (vect_gen_vector_loop_niters): Support range
        for partial vectors.

---
diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index 
9c58a6a01d7c9c3d97a2f8595b1ea6cff2d653f6..2d01a4b0ed1c8431510ad5e6e2175dbe89371618
 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)),


-- 
diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index 9c58a6a01d7c9c3d97a2f8595b1ea6cff2d653f6..2d01a4b0ed1c8431510ad5e6e2175dbe89371618 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