Loops with loop invariant increments cannot have known iteration bounds
as the number of elements processed each iteration is unknown.

gcc/ChangeLog:

        * tree-vect-loop.cc (vect_transform_loop): Add checks for
        iv loop increment being invariant.
---
 gcc/tree-vect-loop.cc | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 4a049238142..c7407098dc1 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -11508,7 +11508,8 @@ vect_transform_loop (loop_vec_info loop_vinfo, gimple 
*loop_vectorized_call)
          /* Both peeling for alignment and peeling for gaps can end up
             with the scalar epilogue running for more than VF-1 iterations.  */
          && !main_vinfo->peeling_for_alignment
-         && !main_vinfo->peeling_for_gaps)
+         && !main_vinfo->peeling_for_gaps
+         && LOOP_VINFO_IV_INCREMENT_INVARIANT_P (loop_vinfo))
        {
          unsigned int bound;
          poly_uint64 main_iters
@@ -11524,7 +11525,10 @@ vect_transform_loop (loop_vec_info loop_vinfo, gimple 
*loop_vectorized_call)
              = wi::umin ((bound_wide_int) (bound - 1),
                          loop->nb_iterations_upper_bound);
       }
-  }
+
+      if (loop_vinfo && !LOOP_VINFO_IV_INCREMENT_INVARIANT_P (loop_vinfo))
+       loop->any_upper_bound = false;
+    }
   if (loop->any_likely_upper_bound)
     loop->nb_iterations_likely_upper_bound
       = (final_iter_may_be_partial
-- 
2.43.0

Reply via email to