GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc/tree-optimization/vect Performance Win

Allow Commutative Operand Swap for IFN in SLP Reduction

GCC can now swap commutative operands in SLP vectorization for internal functions (IFN) like `.COND_ADD`, improving vectorization of code generated by if-conve…

GCC’s SLP vectorizer now recognizes commutative operand swaps for internal functions (IFN) generated during if-conversion, such as .COND_ADD. Previously, the vectorizer only recognized commutative swaps for tree_code operations (e.g. PLUS_EXPR), leading to failures when reduction operands appeared in different commutative positions. This change improves performance (7.1% on EMR, 2.48% on Znver5 for 731.astcenc_r with -Ofast).

In Details

Scalar replacement via SLP (straight-line-program) vectorization groups scalars into vectors. In vect_build_slp_tree_1, commutative operand swapping was limited to tree_code operations. The patch extends recognition to internal functions (IFN) like .COND_ADD using first_commutative_argument. This matters because missed SLP optimizations can prevent inlining, but a toolchain dev outside SLP might not know the internal functions produced by if-conversion need special handling in the commutative swap logic.

For Context

SLP vectorization in GCC identifies opportunities to perform the same operation on multiple data elements simultaneously using SIMD instructions — e.g. replacing four float additions with a single vector addition. If-conversion is a compiler optimization that replaces conditional branches with conditional selects (or predicated instructions), often resulting in internal functions. This commit fixes a limitation where the SLP vectorizer would fail to recognize when it could reorder the operands of commutative operations (like addition or multiplication) in these internal functions, preventing some vectorizations. By enabling operand swapping, GCC can now vectorize a broader range of code patterns, resulting in performance improvements.

Filed Under: optimizationvectorizationslp