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

tree-optimization/126760 - Fix vectorization of switches

Corrects CFG shape check for switch statement vectorization after if-conversion.

This commit fixes a bug in GCC’s vectorization of switch statements that are converted using if-conversion. The check if_convertible_switch_p was incorrectly elided for blocks dominating loop latches, leading to faulty conversion. The fix delays the switch validation until the loop iterating over PHIs, ensuring correct CFG shape analysis and enabling reliable vectorization for such constructs, addressing PRs tree-optimization/126760 and tree-optimization/127391.

In Details

This patch corrects the if_convertible_switch_p check in tree-if-conv.cc which was too eager. By delaying the switch validation to within if_convertible_loop_p_1, specifically after the loop over PHIs, it ensures that the check correctly assesses the CFG shape required for if-conversion of switch statements, resolving issues where the check was elided for dominating blocks and causing incorrect vectorization (PRs tree-optimization/126760, tree-optimization/127391).

For Context
vectorization
An optimization technique that allows a single instruction to operate on multiple data elements simultaneously, significantly improving performance for data-parallel operations.
switch statement
A control flow statement in C/C++ that selects one of many code blocks to execute based on the value of an expression.
if-conversion
A compiler optimization that replaces conditional control flow (like if statements or branches) with conditional execution of instructions, often enabling better instruction-level parallelism.
CFG
Control Flow Graph, a representation of all execution paths through a program, used by compilers for analysis and optimization.
PHI node
In SSA (Static Single Assignment) form, a PHI node is used to merge values from different control flow paths. It represents a value that may have come from one of several preceding basic blocks.
Filed Under: vectorizationoptimizationswitch statementbugfix