tree-optimization/127686 - mis-applied -O2 vector cost model heuristic

Message ID n09142p2-poop-q8os-8ons-6752qn186oqs@fhfr.qr
State Committed
Commit a9b19ded78ca2dd8f66b355b05ebbbb149c2d320
Headers
Series tree-optimization/127686 - mis-applied -O2 vector cost model heuristic |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-aarch64-bootstrap fail Patch failed to apply
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-arm-bootstrap fail Patch failed to apply

Commit Message

Richard Biener Oct. 1, 2026, 8:31 a.m. UTC
  With -O2 and it's default very-cheap vectorizer cost model we apply
the heuristic that even when the vector loop is only executed once
vectorization should be profitable.  But that is applied even when
the number of iterations is constant where we already assess
profitability over the whole run.  So do not apply the former heuristic
in this case.

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

	PR tree-optimization/127686
	* tree-vect-loop.cc (vect_analyze_loop_costing): Do not
	require a single vector iteration to be profitable iff
	the number of scalar iterations is constant.
---
 gcc/tree-vect-loop.cc | 1 +
 1 file changed, 1 insertion(+)
  

Patch

diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 9b2afad6034..287902089c6 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -1926,6 +1926,7 @@  vect_analyze_loop_costing (loop_vec_info loop_vinfo,
      things are probably too close to call, and the conservative thing
      would be to stick with the scalar code.  */
   if (loop_cost_model (loop) == VECT_COST_MODEL_VERY_CHEAP
+      && !LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
       && min_profitable_estimate > (int) vect_vf_for_cost (loop_vinfo))
     {
       if (dump_enabled_p ())