Hi,

This a fix for the regression caused by '[vect] Re-analyze all modes for epilogues'. The earlier patch assumed there was always at least one other mode than VOIDmode, but that does not need to be the case. If we are dealing with a target that does not define more modes for 'autovectorize_vector_modes', the behaviour before the patch would be to try to create an epilogue for the same autodetected_vector_mode, which unless the target supported partial vectors would always fail. So as a fix I suggest trying to vectorize the epilogue with the preferred_simd_mode for QI, mimicking autovectorize_vector_mode, which will be skipped if it is not a vector_mode (since that already should indicate partial vectors aren't possible) or if no partial vectors are supported and its pessimistic NUNITS is larger than the main loop's VF.

Currently bootstrapping and regression testing, otherwise OK for trunk? Can someone verify this fixes the issue for PR103971 on powerpc?

gcc/ChangeLog:

        * tree-vect-loop.c (vect-analyze-loop): Handle scenario where target
        does add autovectorize_vector_modes.
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 
6ed2b5f8724e5ebf27592f67d7f6bdfe1ebcf512..c81ebc411312e649f9cd954895244c60c928fee1
 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -3024,6 +3024,18 @@ vect_analyze_loop (class loop *loop, vec_info_shared 
*shared)
      ordering is not guaranteed, so we could end up picking a mode for the main
      loop that is after the epilogue's optimal mode.  */
   mode_i = 1;
+  /* If we only had VOIDmode then push the AUTODETECTED_VECTOR_MODE to see if
+     an epilogue can be created with that mode.  */
+  if (vector_modes.length () == 1)
+    {
+      machine_mode preferred_mode
+       = targetm.vectorize.preferred_simd_mode (QImode);
+      /* If the preferred mode isn't a vector mode we will not be needing an
+         epilogue.  */
+      if (!VECTOR_MODE_P (preferred_mode))
+       return first_loop_vinfo;
+      vector_modes.safe_push (preferred_mode);
+    }
   bool supports_partial_vectors = partial_vectors_supported_p ();
   poly_uint64 first_vinfo_vf = LOOP_VINFO_VECT_FACTOR (first_loop_vinfo);
 

Reply via email to