Adjust scalar_to_vec for invariant loads
Fixes incorrect cost estimation for non-uniform invariant loads in vectorization.
This commit corrects the cost estimation for vectorizable loads in GCC’s tree-vectorizer. Previously, non-uniform invariant loads were costed incorrectly, and scalar_to_vec was inappropriately used for non-splat loads. The fix ensures more accurate cost analysis and utilizes vec_construct for non-splat loads, improving vectorization efficiency.
In Details
This patch adjusts the vectorizable_load function in tree-vect-stmts.cc to correctly cost non-uniform invariant loads. It prevents the use of scalar_to_vec for loads that are not uniform (i.e., not splats), instead relying on vec_construct for such cases. This improves the accuracy of the vectorizer's cost model and avoids mis-vectorization or suboptimal code generation for invariant loads.
- Vectorization
- A compiler optimization technique that transforms code to perform the same operation on multiple data elements simultaneously, often using SIMD (Single Instruction, Multiple Data) instructions.
- Invariant Load
- A memory load operation within a loop whose address does not change from one iteration to the next.
- scalar_to_vec
- A GCC internal function or pattern used to convert a scalar value into a vector, typically by replicating the scalar value across all vector elements (a splat).
- vec_construct
- A GCC internal function or pattern used to construct a vector from a list of scalar values. Unlike
scalar_to_vec, it allows for vectors with distinct elements. - Splat
- In the context of vector operations, a splat refers to a vector where all elements have the same value.