Improve BB vectorization of reductions
Enhances loop vectorization for reductions by improving SLP discovery and handling of non-uniform operation chains.
This commit improves the vectorization of reduction operations in basic blocks (BBs) by refining the use of Super Low-Power (SLP) vectorization. Previously, uneven operation chains led to premature stripping of operations to achieve an even number of lanes, which was suboptimal. The change removes this early stripping, allowing SLP to discover the full pattern and re-analyze larger matching or non-matching parts, increasing successful vectorization.
In Details
The vect_slp_check_for_roots and vect_build_slp_instance functions in GCC's SLP vectorizer were modified to better handle reduction operations. The change removes the artificial constraint of forcing BB reduction roots to have an even number of lanes. Instead, it allows SLP to re-attempt discovery on either the matching or non-matching portion of a non-uniform operation chain when an initial BB reduction attempt fails, improving robustness for cases like PR126028.
- vectorization
- A compiler optimization technique that allows a single instruction to operate on multiple data elements simultaneously, often improving performance for numerical computations.
- SLP (Super Low-Power) vectorization
- A compiler technique used to find straight-line code patterns that can be vectorized, even if they are not part of a loop. It works by identifying sequences of identical operations that can be mapped to SIMD instructions.
- Reduction operation
- An operation that combines a sequence of values into a single result, such as summing, multiplying, or finding the maximum/minimum.
- Basic Block (BB)
- A sequence of instructions with a single entry point and a single exit point. Vectorization is often applied to instructions within basic blocks.