Loop Vectorizer: Detect uniform gather offsets using SCEV
Vectorizer now optimizes uniform gather offsets by broadcasting a single load.
The loop vectorizer can now identify when the offsets used in gather load operations are uniform across all lanes of a vector. By analyzing Scalar Evolution (SCEV) information, it detects if expressions like i >> 6 evaluate to the same value for all lanes in a given iteration. When uniformity is detected, the vectorizer replaces multiple scalar loads with a single load and a broadcast operation, significantly improving performance for such memory access patterns.
In Details
This patch enhances the GCC loop vectorizer's ability to optimize gather loads by introducing analysis using SCEV (Scalar Evolution) to detect uniform offsets. The new vect_check_gather_load_offset_uniform function checks if gather offsets are constant across all N = CONST_NUNITS lanes within a loop iteration. If uniform, vectorizable_load transforms the operation from emulated gathers (N loads) into a single scalar load followed by a broadcast, storing the result into the vector register. This optimization is tracked by a new field gs_offset_uniform_p in vect_load_store_data.
- Loop Vectorizer
- A compiler optimization pass that transforms loops to execute multiple iterations or multiple operations within an iteration in parallel using wide vector (SIMD) instructions.
- Scalar Evolution (SCEV)
- A compiler analysis technique that computes precise information about how scalar values (like loop counters and array indices) change across loop iterations. It's crucial for predicting memory access patterns and enabling optimizations like vectorization.
- Gather Load
- A memory access operation where elements are loaded from non-contiguous memory locations into a vector register. Each element's address is computed individually.
- Broadcast
- An operation that duplicates a single value into all elements of a vector register. Used here to efficiently replicate a single memory load across multiple lanes.
- SIMD
- Single Instruction, Multiple Data. A class of parallel computing where a single instruction operates on multiple data points simultaneously, typically using wide vector registers.