Move updated versioning threshold compute

Message ID 20241031104912.E3B8E3857438@sourceware.org
State Committed
Commit 6cbe075be7489c7ca2fa54e133e96ed1d1e64a93
Headers
Series Move updated versioning threshold compute |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Test passed

Commit Message

Richard Biener Oct. 31, 2024, 10:48 a.m. UTC
  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(-)
  

Patch

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,