GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
phiopt

Preserve debug information across removed blocks in phiopt.

Ensures debug information remains correct when blocks are removed by phiopt.

This commit fixes a bug in the phiopt optimization pass where the removal of middle blocks in diamond or triangle control flow structures could lead to incorrect debugger output. When blocks were deleted, their associated debug binds were also removed, causing variables to retain outdated values on certain code paths. The fix ensures that debug binds of removed blocks are properly reset before the conditional logic, similar to how CFG cleanup handles forwarder blocks, thus maintaining accurate variable states for debuggers.

In Details

The replace_phi_edge_with_variable function in tree-ssa-phiopt.cc was deleting middle blocks and their debug binds. This led to variables retaining stale values after optimization, visible to debuggers. This commit introduces move_reset_debug_binds to move and reset debug binds of removed blocks *before* the conditional merge point. This ensures that variables are correctly updated on all paths, including those that went through the now-removed blocks, aligning with the behavior of CFG cleanup for forwarder blocks.

For Context
phiopt
A GCC optimization pass that operates on Static Single Assignment (SSA) form, often simplifying control flow and optimizing PHI nodes.
debug binds
Information maintained by the compiler that associates program variables with their corresponding values or register locations at specific points in the code for debugging purposes.
control flow graph (CFG)
A representation of the possible execution paths through a program, used by compilers for analysis and optimization.
Static Single Assignment (SSA)
An intermediate representation property where every variable is assigned exactly once, simplifying many compiler optimizations.
Filed Under: phioptdebuggingcompiler optimizationCFG