vect: Prevent unsupported reduction recurrences in ifcvt
Fixes vectorizer to avoid creating unsupported reduction recurrences when using if-conversion.
This commit resolves an issue where GCC’s vectorizer incorrectly generated unsupported reduction recurrences when using if-conversion. The problem arises when a reduction is conditionally updated within an if-cvt transformation, hiding the true recurrence from the vectorizer. The fix involves restructuring the generated code to float out the conditional expression, preventing the vectorizer from misinterpreting the control flow and failing to vectorize the loop, as reported in PR126551.
In Details
This patch addresses an issue where if-cvt (if-conversion) transformations create reduction recurrences that the vectorizer cannot handle. In the example case, a reduction acc = acc + d is conditionally executed. After if-cvt, the code structure becomes acc_3 = cond ? acc_1 + value : acc_1, which hides the single-statement update needed for reduction analysis. The vectorizer then misses the optimization. The fix modifies if-cvt to transform the conditional update into a form where the conditional expression is floated out, avoiding the problematic structure and allowing the vectoriz…
- vect
- The vectorization component of GCC, responsible for transforming scalar code into SIMD (Single Instruction, Multiple Data) instructions.
- reduction recurrence
- A pattern in a loop where a variable is repeatedly updated by combining its previous value with a new value (e.g., summation, product). Vectorizers often target these for efficient parallel execution.
- if-conversion
- An optimization technique that transforms conditional branches within a loop into conditional operations on data, potentially improving instruction-level parallelism.
- PHI node
- In SSA form, a PHI node represents a value that can come from multiple different control flow paths. It merges values from different basic blocks.
- loop carried value
- A value that is computed in one iteration of a loop and used in the next iteration, forming a dependency chain across loop iterations.