BB SLP: Enabling reduction root finding for sum-of-diff kind of patterns
This commit enables vectorization of "sum of diffs" patterns by allowing the SLP vectorizer to recognize chains involving both PLUS and MINUS expressions.
This commit enhances the SLP (Straight-Line Program) vectorizer to recognize and vectorize “sum of diffs” patterns, where the sum of differences between elements of two arrays is calculated. It introduces an optional parameter to vect_slp_linearize_chain to control whether MINUS_EXPR nodes are followed during reduction root finding. By default, MINUS_EXPR nodes are treated as leaves, enabling the vectorization of the “sum of diffs” pattern. A new test case is added to verify the functionality.
In Details
This commit modifies vect_slp_linearize_chain in tree-vect-slp.cc to enable the recognition of "sum of diffs" patterns. An allow_alt_code parameter is added to control whether MINUS_EXPR nodes are traversed. The vect_slp_check_for_roots function now calls vect_slp_linearize_chain with allow_alt_code set to false, treating MINUS_EXPR nodes as leaves.
For Context
The SLP vectorizer in GCC aims to identify and vectorize straight-line code sequences to improve performance. This commit expands the vectorizer's capabilities by enabling it to recognize patterns that involve both addition and subtraction operations, such as calculating the sum of differences between two arrays. By allowing chains of operations to include subtraction, the compiler can generate more efficient vectorized code for these common patterns, leading to performance improvements.