GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
tree-optimization

tree-optimization/126404 - Fix CTZ pattern to not break reductions

Prevents the CTZ pattern recognizer from breaking vector reduction chains by avoiding recursion on reduction patterns.

A bug in the Count Trailing Zeros (CTZ) pattern recognition logic could cause it to incorrectly recurse into a temporary pattern statement. This led to the vectorizer breaking reduction chains because the setup was incomplete, resulting in multiple uses of the intermediate pattern. The fix ensures that the recognizer avoids recursing when the original pattern is part of a reduction, thus preserving the integrity of vector reductions.

In Details

Fixes GCC PR tree-optimization/126404. The vect_recog_popcount_clz_ctz_ffs_pattern function incorrectly recursed into vect_recog_ctz_ffs_pattern even when the original pattern was intended for vector reduction. This commit modifies vect_recog_popcount_clz_ctz_ffs_pattern to avoid this recursion when a reduction pattern is detected, preventing the premature breaking of reduction chains.

For Context
CTZ
Count Trailing Zeros. An instruction or function that counts the number of zero bits from the least significant bit up to the first set bit.
vector reduction
A loop transformation technique where operations within a loop, such as summation or finding a minimum/maximum, are parallelized across vector lanes. The final result is then produced by combining the results from each lane.
pattern recognition
In compilers, a technique used by optimizers to identify specific sequences or structures in the intermediate representation that correspond to known efficient operations or idioms.
tree-optimization
A phase in GCC's compilation pipeline where the intermediate representation (GIMPLE, which resembles an abstract syntax tree) is analyzed and transformed to improve code efficiency.
Filed Under: optimizationvectorizerbugfix