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

tree-optimization: Fix missed FRE in loop

Improves loop optimizations by ensuring FRE does not abort prematurely on PHI nodes in CFG cycles.

This commit fixes a missed optimization in the Free Register Elimination (FRE) pass for loops. A previous correctness fix caused FRE to incorrectly abort when encountering a loop PHI node within a control flow graph (CFG) cycle. The change modifies the maybe_skip_until function to stop the traversal when it revisits the original PHI node, allowing constant propagation and avoiding the bug.

In Details

The ssa-fre.cc pass, specifically maybe_skip_until, was too aggressive in aborting traversals when encountering PHI nodes in CFG cycles due to a PR54498 fix. This commit refines the logic to correctly handle re-visiting a PHI node within a loop, preventing premature aborts and enabling further optimizations like constant propagation for __builtin_constant_p.

For Context
FRE
Free Register Elimination, a compiler optimization pass that identifies and removes unnecessary register allocations.
PHI node
In SSA (Static Single Assignment) form, a PHI node is used to merge values from different control flow paths. It selects one of its incoming values based on which path was taken to reach it.
CFG
Control Flow Graph, a representation of a program's execution flow where nodes are basic blocks and edges represent possible transfers of control.
SSA
Static Single Assignment, an intermediate representation property where every variable is assigned exactly once. PHI nodes are used to resolve merges at join points.
Filed Under: optimizationloopbugfix