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

commit r16-5630-gb7942104794a754f9927916dfc8931d4bd515648
Author: Richard Biener <[email protected]>
Date:   Wed Nov 26 13:54:12 2025 +0100

    tree-optimization/110571 - fix vect_need_peeling_or_partial_vectors_p
    
    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.

Diff:
---
 gcc/tree-vect-loop-manip.cc |  6 ------
 gcc/tree-vect-loop.cc       | 12 ++++++++----
 gcc/tree-vectorizer.h       |  2 --
 3 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index a9fe14b31855..9ddf9acf2f19 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -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 ();
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 6b6dc206c59e..fe78107fe04c 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -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.  */
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index ad36f400418b..5d125afa6bc5 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -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);

Reply via email to