[gcc r14-7039] tree-optimization/113026 - fix vector epilogue maximum iter bound

Richard Biener rguenth@gcc.gnu.org
Tue Jan 9 12:37:07 GMT 2024


https://gcc.gnu.org/g:c22cf7a7a77bf9245bd0790b21695440208c3aa5

commit r14-7039-gc22cf7a7a77bf9245bd0790b21695440208c3aa5
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Jan 9 11:49:50 2024 +0100

    tree-optimization/113026 - fix vector epilogue maximum iter bound
    
    The late amendment with a limit based on VF was redundant and wrong
    for peeled early exits.  The following moves the adjustment done
    when we don't have a skip edge down to the place where the already
    existing VF based max iter check is done and removes the amendment.
    
            PR tree-optimization/113026
            * tree-vect-loop-manip.cc (vect_do_peeling): Remove
            redundant and wrong niter bound setting.  Move niter
            bound adjustment down.

Diff:
---
 gcc/tree-vect-loop-manip.cc | 47 +++++++++++++++------------------------------
 1 file changed, 15 insertions(+), 32 deletions(-)

diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index 2313d26338d..f0ea7fc069b 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -3383,38 +3383,6 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, tree nitersm1,
 	    bb_before_epilog->count = single_pred_edge (bb_before_epilog)->count ();
 	  bb_before_epilog = loop_preheader_edge (epilog)->src;
 	}
-      else
-	{
-	  /* When we do not have a loop-around edge to the epilog we know
-	     the vector loop covered at least VF scalar iterations unless
-	     we have early breaks and the epilog will cover at most
-	     VF - 1 + gap peeling iterations.
-	     Update any known upper bound with this knowledge.  */
-	  if (! LOOP_VINFO_EARLY_BREAKS (loop_vinfo))
-	    {
-	      if (epilog->any_upper_bound)
-		epilog->nb_iterations_upper_bound -= lowest_vf;
-	      if (epilog->any_likely_upper_bound)
-		epilog->nb_iterations_likely_upper_bound -= lowest_vf;
-	      if (epilog->any_estimate)
-		epilog->nb_iterations_estimate -= lowest_vf;
-	    }
-	  unsigned HOST_WIDE_INT const_vf;
-	  if (vf.is_constant (&const_vf))
-	    {
-	      const_vf += LOOP_VINFO_PEELING_FOR_GAPS (loop_vinfo) - 1;
-	      if (epilog->any_upper_bound)
-		epilog->nb_iterations_upper_bound
-		  = wi::umin (epilog->nb_iterations_upper_bound, const_vf);
-	      if (epilog->any_likely_upper_bound)
-		epilog->nb_iterations_likely_upper_bound
-		  = wi::umin (epilog->nb_iterations_likely_upper_bound,
-			      const_vf);
-	      if (epilog->any_estimate)
-		epilog->nb_iterations_estimate
-		  = wi::umin (epilog->nb_iterations_estimate, const_vf);
-	    }
-	}
 
       /* If loop is peeled for non-zero constant times, now niters refers to
 	 orig_niters - prolog_peeling, it won't overflow even the orig_niters
@@ -3505,6 +3473,21 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, tree nitersm1,
       if (LOOP_VINFO_EARLY_BREAKS (loop_vinfo))
 	iterate_fix_dominators (CDI_DOMINATORS, doms, false);
 
+      /* When we do not have a loop-around edge to the epilog we know
+	 the vector loop covered at least VF scalar iterations unless
+	 we have early breaks.
+	 Update any known upper bound with this knowledge.  */
+      if (! skip_vector
+	  && ! LOOP_VINFO_EARLY_BREAKS (loop_vinfo))
+	{
+	  if (epilog->any_upper_bound)
+	    epilog->nb_iterations_upper_bound -= lowest_vf;
+	  if (epilog->any_likely_upper_bound)
+	    epilog->nb_iterations_likely_upper_bound -= lowest_vf;
+	  if (epilog->any_estimate)
+	    epilog->nb_iterations_estimate -= lowest_vf;
+	}
+
       unsigned HOST_WIDE_INT bound;
       if (bound_scalar.is_constant (&bound))
 	{


More information about the Gcc-cvs mailing list