GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
vect

Fix incorrect code generation with SLP IV reuse

Corrects vectorization of induction variables by ensuring proper validation before reusing them.

This commit fixes a bug in the vectorization of induction variables (IVs) using the Superword-Level Parallelism (SLP) technique. The vectorizable_induction function previously reused IVs without fully validating that the scalar initial values and steps of the folded vector chunks matched their predecessors. This could lead to incorrect code generation. The fix ensures that IV reuse only occurs when these initial values and steps are identical, adding new tests to cover these scenarios.

In Details

The function vectorizable_induction in tree-vect-loop.cc is responsible for identifying and reusing induction variables within SLP vectorization. The condition for reducing the number of generated IVs, based on group_size being divisible by const_nunits, was too broad. This change introduces a new helper function vect_slp_induction_reuse_p to perform a more thorough check. Reuse is now conditional on each folded chunk having scalar initial values and steps that precisely match their corresponding earlier chunks, preventing incorrect code when these differ.

For Context
Vectorization
An optimization technique where a single instruction operates on multiple data elements simultaneously (SIMD - Single Instruction, Multiple Data). This can significantly speed up computations on arrays or similar data structures.
SLP
Superword-Level Parallelism. A compiler optimization technique that finds independent scalar operations within a basic block that can be combined and executed in parallel using vector instructions. It's often used for loop-invariant code motion and straight-line code optimization.
Induction Variable (IV)
A variable in a loop whose value is altered by a constant amount in each iteration. Commonly used for loop termination and array indexing, and often optimized by compilers.
Scalar
A single data value, as opposed to a vector or array of values.
Filed Under: vectorizationoptimizationSLPinduction variable