GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
tree-optimization Performance Win

Vector cost model heuristic misapplied when loop iteration count is constant

GCC's vectorizer will no longer wrongly assume vectorization is profitable for single-iteration loops when the iteration count is already known.

GCC’s vectorizer uses a cost model heuristic that assumes vectorization is profitable even for loops that execute only once, provided the vector cost is cheap. However, this heuristic was being applied even when the loop’s iteration count was constant, a case already handled by a separate profitability assessment. This commit modifies the vector cost analysis to avoid applying the single-iteration heuristic when the iteration count is constant, preventing incorrect vectorization decisions.

In Details

The vectorizer's cost model in tree-vect-loop.cc has a heuristic to promote vectorization of loops executing only once if the per-iteration vector cost is cheap. This commit corrects vect_analyze_loop_costing to disable this heuristic when the number of scalar iterations is constant, as profitability is already evaluated over the entire execution in that scenario. This prevents misoptimizations where the single-iteration heuristic overrides a more accurate constant-iteration cost assessment.

Filed Under: optimizationvectorization