[2/2] Fix vect_need_peeling_or_partial_vectors_p wrt peeling for gaps

Message ID 20251205122924.19AC13EA63@imap1.dmz-prg2.suse.org
State Committed
Commit 27210c145b0b293c2958b8cd8ff3ee7f6867a8a0
Headers
Series [1/2] tree-optimization/120939 - remove uninitialized use of LOOP_VINFO_COST_MODEL_THRESHOLD |

Commit Message

Richard Biener Dec. 5, 2025, 12:29 p.m. UTC
  The code assuming that peeling for gaps can be elided by means of
knowing niters and prologue peeling is wrong.  Peeling for gaps
means we need an epilog.

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

	* tree-vect-loop.cc (vect_need_peeling_or_partial_vectors_p):
	When peeling for gaps we always need an epilog.
---
 gcc/tree-vect-loop.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Patch

diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index cd62c96892b..3787e7bdfb6 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -946,6 +946,9 @@  vect_need_peeling_or_partial_vectors_p (loop_vec_info loop_vinfo)
 {
   unsigned HOST_WIDE_INT const_vf;
 
+  if (LOOP_VINFO_PEELING_FOR_GAPS (loop_vinfo))
+    return true;
+
   loop_vec_info main_loop_vinfo
     = (LOOP_VINFO_EPILOGUE_P (loop_vinfo)
        ? LOOP_VINFO_MAIN_LOOP_INFO (loop_vinfo) : loop_vinfo);
@@ -956,14 +959,11 @@  vect_need_peeling_or_partial_vectors_p (loop_vec_info loop_vinfo)
 	 peeled for reasons other than niters.  */
       unsigned int peel_niter
 	= LOOP_VINFO_PEELING_FOR_ALIGNMENT (main_loop_vinfo);
-      if (LOOP_VINFO_PEELING_FOR_GAPS (loop_vinfo))
-	peel_niter += 1;
       return !multiple_p (LOOP_VINFO_INT_NITERS (loop_vinfo) - peel_niter,
 			  LOOP_VINFO_VECT_FACTOR (loop_vinfo));
     }
 
   if (!LOOP_VINFO_PEELING_FOR_ALIGNMENT (main_loop_vinfo)
-      && !LOOP_VINFO_PEELING_FOR_GAPS (loop_vinfo)
       && LOOP_VINFO_VECT_FACTOR (loop_vinfo).is_constant (&const_vf))
     {
       /* When the number of iterations is a multiple of the vectorization