GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
tree-optimization Performance Win

forwprop: Fold BIT_INSERT_EXPR chains into CONSTRUCTOR

Optimizes chains of vector element insertions into single CONSTRUCTOR operations.

This commit optimizes chains of BIT_INSERT_EXPR operations that sequentially update vector elements. Instead of generating multiple instructions for each insert, the compiler now transforms such chains into a single CONSTRUCTOR (or VECTOR_CST for constants). This optimization significantly reduces instruction count for vector splats, translating to better performance on target architectures like x86-64 and aarch64.

In Details

The forward propagation pass (pass_forwprop) now identifies and simplifies chains of BIT_INSERT_EXPRs. These chains often arise from element-wise vector initialization loops. The new simplify_bit_insert_chain function recognizes when such a chain effectively creates a vector where each element is assigned the same scalar value or when the initial vector is a CONSTRUCTOR or VECTOR_CST and the inserts complete it. It then replaces the chain with a single CONSTRUCTOR or VECTOR_CST, which can be more efficiently expanded by downstream passes into vector splat instructions (e.g., `sh…

For Context
BIT_INSERT_EXPR
A GCC intermediate representation (tree) node representing an operation that inserts a value into a specific bitfield within a larger integer or vector type.
CONSTRUCTOR
A GCC intermediate representation (tree) node used to represent the initialization of aggregate types, including vectors, by listing their element values.
VECTOR_CST
A GCC intermediate representation (tree) node representing a constant vector.
SLP vectorizer
Short, Loop, and Parallelism vectorizer; a GCC optimization pass that identifies opportunities to vectorize code by finding sequences of operations that can be performed on multiple data elements simultaneously.
SSA
Static Single Assignment form, an intermediate representation where every variable is assigned exactly once. This simplifies many optimization passes.
PHI node
In SSA form, a node that merges values from different control flow paths. An 'abnormal' PHI node might indicate complex control flow or potential issues.
Filed Under: optimizationvectorizationtree-ssaperformance