GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
phiopt Performance Win

Replicate conditionals over a PHI of comparisons

Restores an optimization that replicates conditional logic over PHI nodes.

This commit reintroduces an optimization in the phiopt pass that replicates conditional logic over a PHI node formed by comparisons. This optimization was lost during a rewrite of GCC’s jump threading machinery but was partially recovered by the DOM (Dominator) pass. The phiopt pass now handles these cases directly, improving performance by avoiding unnecessary conditional merges. The optimization is deliberately not applied to loop boundaries to preserve loop structure, though the DOM pass’s version remains available for such cases. This change recovers over 94% of the joins previously handled by DOM’s special case.

In Details

The phiopt pass in tree-ssa-phiopt.cc now implements replicate_conds_over_phis. This pass identifies patterns where a PHI node merges boolean results of comparisons (e.g., t_1 = PHI <t_9(3), t_6(4)> where t_9 and t_6 are comparison results), and replicates the subsequent conditional test across the predecessors of the PHI. This avoids the overhead of merging comparisons into a single PHI before testing. The optimization is restricted by preserves_loop_structure_p to avoid altering loop invariants, leaving loop-related cases to the DOM pass's jump threading.

For Context
PHI Node
In SSA (Static Single Assignment) form, a PHI node is used at control flow join points to merge values from different preceding basic blocks. It represents a value that could have originated from multiple paths.
phiopt
GCC's SSA Phi-node optimization pass, which performs various optimizations related to PHI nodes.
DOM
Dominator pass in GCC, which analyzes the control flow graph to determine dominance relationships between basic blocks. It includes jump threading optimizations.
Jump Threading
An optimization technique that simplifies control flow by removing redundant conditional jumps and collapsing basic blocks. It analyzes jump targets to find opportunities for simplification.
SSA
Static Single Assignment form, an intermediate representation where every variable is assigned a value exactly once. This simplifies many compiler analyses and optimizations.
Control Flow Graph
A representation of a program's execution paths, consisting of basic blocks (nodes) and edges indicating possible transfers of control.
Filed Under: optimizationphioptcontrol flow