]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Check LOOP_VINFO_PEELING_FOR_GAPS on epilog is supported
authorRichard Biener <rguenther@suse.de>
Mon, 4 Nov 2024 12:03:33 +0000 (13:03 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 7 Nov 2024 12:49:08 +0000 (13:49 +0100)
We need to check that an epilogue doesn't require LOOP_VINFO_PEELING_FOR_GAPS
in case the main loop didn't (the other way around is OK), the
computation whether the epilog is executed or not gets our of sync
otherwise.

* tree-vect-loop.cc (vect_analyze_loop_2): Move
vect_analyze_loop_costing after check whether we can do
peeling.  Add check on LOOP_VINFO_PEELING_FOR_GAPS for
epilogues.

gcc/tree-vect-loop.cc

index e6d241482ce30f4e0620b948218d090bf90656e9..e91549a643b94d394ea54d15afb99ced50b65d4a 100644 (file)
@@ -3143,17 +3143,15 @@ start_over:
                                       " epilogue loop.\n");
     }
 
-  /* Check the costings of the loop make vectorizing worthwhile.  */
-  res = vect_analyze_loop_costing (loop_vinfo, suggested_unroll_factor);
-  if (res < 0)
-    {
-      ok = opt_result::failure_at (vect_location,
-                                  "Loop costings may not be worthwhile.\n");
-      goto again;
-    }
-  if (!res)
+  /* If the epilogue needs peeling for gaps but the main loop doesn't give
+     up on the epilogue.  */
+  if (LOOP_VINFO_EPILOGUE_P (loop_vinfo)
+      && LOOP_VINFO_PEELING_FOR_GAPS (loop_vinfo)
+      && (LOOP_VINFO_PEELING_FOR_GAPS (orig_loop_vinfo)
+         != LOOP_VINFO_PEELING_FOR_GAPS (loop_vinfo)))
     return opt_result::failure_at (vect_location,
-                                  "Loop costings not worthwhile.\n");
+                                  "Epilogue loop requires peeling for gaps "
+                                  "but main loop does not.\n");
 
   /* If an epilogue loop is required make sure we can create one.  */
   if (LOOP_VINFO_PEELING_FOR_GAPS (loop_vinfo)
@@ -3174,6 +3172,18 @@ start_over:
         }
     }
 
+  /* Check the costings of the loop make vectorizing worthwhile.  */
+  res = vect_analyze_loop_costing (loop_vinfo, suggested_unroll_factor);
+  if (res < 0)
+    {
+      ok = opt_result::failure_at (vect_location,
+                                  "Loop costings may not be worthwhile.\n");
+      goto again;
+    }
+  if (!res)
+    return opt_result::failure_at (vect_location,
+                                  "Loop costings not worthwhile.\n");
+
   /* During peeling, we need to check if number of loop iterations is
      enough for both peeled prolog loop and vector loop.  This check
      can be merged along with threshold check of loop versioning, so