GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
tree-optimization

SLP optimization: Fix basic block constraint for trapping statements

Improves SIMD Local Search (SLP) optimization by correctly handling trapping statements within basic blocks.

This commit addresses an issue in the SLP (SIMD Local Search) optimization pass where the compiler failed to ensure that all statements within a node belonged to the same basic block when a trapping statement was present. The fix modifies vect_build_slp_tree_1 to track the common basic block and detect trapping statements. It then verifies that all statements in a potential SLP vectorization candidate reside in the same basic block after all statements have been processed, preventing incorrect vectorization that could lead to runtime errors.

In Details

The SLP vectorizer in tree-vect-slp.cc must ensure that all statements forming a potential vector are in the same basic block (BB) to guarantee correct execution and avoid issues with control flow or trapping instructions. This patch corrects vect_build_slp_tree_1 by introducing logic to track the common BB and a flag for any trapping statement encountered within a candidate set. After scanning all statements for a potential vector, it verifies the common BB constraint. This resolves PR tree-optimization/126865, where the absence of this check allowed SLP to create vectors from statements…

For Context
SLP (SIMD Local Search)
An optimization technique in GCC that identifies sequences of identical operations in the code that can be combined into a single instruction operating on multiple data elements (SIMD - Single Instruction, Multiple Data). It operates on the tree-IR.
trapping statement
An operation or instruction that, if it occurs, causes a program exception or interrupt (a trap). Examples include division by zero, null pointer dereference, or integer overflow in some contexts.
basic block (BB)
A sequence of consecutive instructions in a program for which flow of control enters at the beginning and leaves at the end without halt or possibility of branching except at the end. Basic blocks are fundamental units for compiler analysis and optimization.
tree-optimization
The phase in GCC where optimizations are applied to the intermediate representation, known as the GCC Tree. This pass focuses on vectorization using SLP.
Filed Under: optimizationvectorizationSLPtree-optimization