https://gcc.gnu.org/g:a9b19ded78ca2dd8f66b355b05ebbbb149c2d320

commit r17-4808-ga9b19ded78ca2dd8f66b355b05ebbbb149c2d320
Author: Richard Biener <[email protected]>
Date:   Thu Oct 1 09:21:30 2026 +0200

    tree-optimization/127686 - mis-applied -O2 vector cost model heuristic
    
    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.
    
            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.

Diff:
---
 gcc/tree-vect-loop.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 9b2afad6034a..287902089c6a 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 ())

Reply via email to