The following moves computing the combined main + epilogue loop
versioning threshold until we figured the epilogues to use rather
than incrementally updating it with the chance to joust candidates
after the fact.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

        * tree-vect-loop.cc (vect_analyze_loop): Move lowest_th
        compute until after epilogue_vinfos is final.
---
 gcc/tree-vect-loop.cc | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index df89edac036..7ed3a56bc68 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -3691,7 +3691,6 @@ vect_analyze_loop (class loop *loop, gimple 
*loop_vectorized_call,
     return first_loop_vinfo;
 
   /* Now analyze first_loop_vinfo for epilogue vectorization.  */
-  poly_uint64 lowest_th = LOOP_VINFO_VERSIONING_THRESHOLD (first_loop_vinfo);
 
   /* For epilogues start the analysis from the first mode.  The motivation
      behind starting from the beginning comes from cases where the VECTOR_MODES
@@ -3750,16 +3749,7 @@ vect_analyze_loop (class loop *loop, gimple 
*loop_vectorized_call,
            }
          /* For now only allow one epilogue loop.  */
          if (first_loop_vinfo->epilogue_vinfos.is_empty ())
-           {
-             first_loop_vinfo->epilogue_vinfos.safe_push (loop_vinfo);
-             poly_uint64 th = LOOP_VINFO_VERSIONING_THRESHOLD (loop_vinfo);
-             gcc_assert (!LOOP_REQUIRES_VERSIONING (loop_vinfo)
-                         || maybe_ne (lowest_th, 0U));
-             /* Keep track of the known smallest versioning
-                threshold.  */
-             if (ordered_p (lowest_th, th))
-               lowest_th = ordered_min (lowest_th, th);
-           }
+           first_loop_vinfo->epilogue_vinfos.safe_push (loop_vinfo);
          else
            {
              delete loop_vinfo;
@@ -3780,6 +3770,17 @@ vect_analyze_loop (class loop *loop, gimple 
*loop_vectorized_call,
 
   if (!first_loop_vinfo->epilogue_vinfos.is_empty ())
     {
+      poly_uint64 lowest_th
+       = LOOP_VINFO_VERSIONING_THRESHOLD (first_loop_vinfo);
+      for (auto epilog_vinfo : first_loop_vinfo->epilogue_vinfos)
+       {
+         poly_uint64 th = LOOP_VINFO_VERSIONING_THRESHOLD (epilog_vinfo);
+         gcc_assert (!LOOP_REQUIRES_VERSIONING (epilog_vinfo)
+                     || maybe_ne (lowest_th, 0U));
+         /* Keep track of the known smallest versioning threshold.  */
+         if (ordered_p (lowest_th, th))
+           lowest_th = ordered_min (lowest_th, th);
+       }
       LOOP_VINFO_VERSIONING_THRESHOLD (first_loop_vinfo) = lowest_th;
       if (dump_enabled_p ())
        dump_printf_loc (MSG_NOTE, vect_location,
-- 
2.43.0

Reply via email to