Robustify reduction analysis by handling unsupported operations early
Prevents compiler crashes by performing early checks for vectorizable reduction operations.
This commit improves the robustness of the vectorization reduction analysis by adding an early exit for unsupported reduction operations. The analysis previously assumed a direct correspondence between GIMPLE statement operands and SLP (Shortest-Length Processing) vectorization operands, which can break for operations like count-leading-zeros with multiple operands. By rejecting such cases upfront, the compiler avoids internal errors (ICEs) and provides better diagnostics.
In Details
The vectorizable_reduction function within tree-vect-loop.cc is responsible for determining if a reduction operation can be vectorized using the SLP (Shortest-Length Processing) peephole optimization. This commit adds a check to ensure that all operands of the GIMPLE statement correspond to children in the SLP tree. This robustification prevents an ICE when, for example, .CLZ is used with two operands, as the operand count mismatch previously would not be caught until later, by which point the GIMPLE statement's structure was already assumed to match the SLP tree.
- Vectorization
- An optimization technique that allows a single instruction to operate on multiple data elements simultaneously. This is often achieved by leveraging SIMD (Single Instruction, Multiple Data) instructions.
- Reduction Operation
- An operation that combines a sequence of values into a single result, such as sum, product, minimum, or maximum. In vectorization, these can often be parallelized.
- SLP (Shortest-Length Processing)
- A compiler optimization technique that vectorizes sequences of identical, consecutive operations that have identical operands, even if they are not aligned in a straight vector.
- GIMPLE
- A three-address intermediate representation used by GCC. It's designed to simplify many optimizations compared to RTL (Register Transfer Language).
- ICE (Internal Compiler Error)
- An error that occurs within the compiler itself, indicating a bug in the compiler's internal logic or data structures. It typically results in the compilation process aborting.