]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/110571 - fix vect_need_peeling_or_partial_vectors_p
authorRichard Biener <rguenther@suse.de>
Wed, 26 Nov 2025 12:54:12 +0000 (13:54 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 26 Nov 2025 14:20:37 +0000 (15:20 +0100)
The following avoids re-calling of vect_need_peeling_or_partial_vectors_p
after peeling.  This was neccesary because the function does not
properly handle being called for epilogues since it looks for the
applied prologue peeling not in the main vector loop but the current
one operated on.

PR tree-optimization/110571
* tree-vectorizer.h (vect_need_peeling_or_partial_vectors_p): Remove.
* tree-vect-loop.cc (vect_need_peeling_or_partial_vectors_p):
Fix when called on epilog loops.  Make static.
* tree-vect-loop-manip.cc (vect_do_peeling): Do not
re-compute LOOP_VINFO_PEELING_FOR_NITER.

gcc/tree-vect-loop-manip.cc
gcc/tree-vect-loop.cc
gcc/tree-vectorizer.h

index a9fe14b3185584c36ffa60aab3bc9f53306676ea..9ddf9acf2f190958cf2594385f42fa6d58a61bc3 100644 (file)
@@ -3727,12 +3727,6 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, tree nitersm1,
        = fold_build2 (MINUS_EXPR, TREE_TYPE (epilogue_niters),
                       epilogue_niters,
                       build_one_cst (TREE_TYPE (epilogue_niters)));
-
-      /* ???  During analysis phase this is computed wrongly, re-do it
-        here.  */
-      LOOP_VINFO_PEELING_FOR_NITER (epilogue_vinfo)
-       = (!LOOP_VINFO_USING_PARTIAL_VECTORS_P (epilogue_vinfo)
-          && vect_need_peeling_or_partial_vectors_p (epilogue_vinfo));
     }
 
   adjust_vec.release ();
index 6b6dc206c59e96687624fb5f8be1a600b1ad0a28..fe78107fe04c9da0ab6dca17747ba3a81591c1a9 100644 (file)
@@ -937,7 +937,7 @@ vect_min_prec_for_max_niters (loop_vec_info loop_vinfo, unsigned int factor)
 
 /* True if the loop needs peeling or partial vectors when vectorized.  */
 
-bool
+static bool
 vect_need_peeling_or_partial_vectors_p (loop_vec_info loop_vinfo)
 {
   unsigned HOST_WIDE_INT const_vf;
@@ -949,19 +949,23 @@ vect_need_peeling_or_partial_vectors_p (loop_vec_info loop_vinfo)
     th = LOOP_VINFO_COST_MODEL_THRESHOLD (LOOP_VINFO_ORIG_LOOP_INFO
                                          (loop_vinfo));
 
+  loop_vec_info main_loop_vinfo
+    = (LOOP_VINFO_EPILOGUE_P (loop_vinfo)
+       ? LOOP_VINFO_MAIN_LOOP_INFO (loop_vinfo) : loop_vinfo);
   if (LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
-      && LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo) >= 0)
+      && LOOP_VINFO_PEELING_FOR_ALIGNMENT (main_loop_vinfo) >= 0)
     {
       /* Work out the (constant) number of iterations that need to be
         peeled for reasons other than niters.  */
-      unsigned int peel_niter = LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo);
+      unsigned int peel_niter
+       = LOOP_VINFO_PEELING_FOR_ALIGNMENT (main_loop_vinfo);
       if (LOOP_VINFO_PEELING_FOR_GAPS (loop_vinfo))
        peel_niter += 1;
       if (!multiple_p (LOOP_VINFO_INT_NITERS (loop_vinfo) - peel_niter,
                       LOOP_VINFO_VECT_FACTOR (loop_vinfo)))
        return true;
     }
-  else if (LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo)
+  else if (LOOP_VINFO_PEELING_FOR_ALIGNMENT (main_loop_vinfo)
       /* ??? When peeling for gaps but not alignment, we could
         try to check whether the (variable) niters is known to be
         VF * N + 1.  That's something of a niche case though.  */
index ad36f400418b4d5418c22f84158ab51b0625b47f..5d125afa6bc5166c04dbc68e968ca7207685abb8 100644 (file)
@@ -2635,8 +2635,6 @@ extern tree vect_create_addr_base_for_vector_ref (vec_info *,
 extern tree neutral_op_for_reduction (tree, code_helper, tree, bool = true);
 extern widest_int vect_iv_limit_for_partial_vectors (loop_vec_info loop_vinfo);
 bool vect_rgroup_iv_might_wrap_p (loop_vec_info, rgroup_controls *);
-/* Used in tree-vect-loop-manip.cc */
-extern bool vect_need_peeling_or_partial_vectors_p (loop_vec_info);
 /* Used in gimple-loop-interchange.c and tree-parloops.cc.  */
 extern bool check_reduction_path (dump_user_location_t, loop_p, gphi *, tree,
                                  enum tree_code);