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

Improve replace_phi_edge_with_variable for diamond shaped bb (again)

PHIOPT optimization pass is improved to better handle diamond-shaped basic blocks.

This patch refines the replace_phi_edge_with_variable function within the PHIOPT optimization pass, specifically addressing diamond-shaped basic blocks. Instead of checking if intermediate basic blocks are empty, it now checks if the new phi entry depends on either branch. This change, while not affecting current single-statement PHIOPTs, prepares the pass for supporting multiple statements per PHIOPTed block and prevents potential issues with unused statements remaining.

In Details

This commit revisits the replace_phi_edge_with_variable function in tree-ssa-phiopt.cc. The previous implementation checked if the two intermediate basic blocks (B1, B2) in a diamond pattern (entry -> B1 -> merge, entry -> B2 -> merge) were empty. This version refactors the check to determine if the new phi entry at the merge block depends on either B1 or B2. This is a preparatory change for supporting multiple statements within PHIOPT, ensuring that intermediate blocks are correctly handled when they might not be removed even if they contain only the phi node. It also marks phi arguments…

For Context
PHIOPT
An optimization pass in GCC that aims to simplify or eliminate PHI nodes in SSA form. PHI nodes are used to represent control flow merging in Static Single Assignment (SSA) form.
basic block
A contiguous sequence of code within a program in which control flow enters at the beginning and leaves at the end without halt or possibility of branching except at the end.
diamond shaped bb
A control flow graph pattern where a basic block has two distinct predecessor blocks, and these two blocks have a common successor block, forming a diamond shape.
SSA form
Static Single Assignment form. An intermediate representation used in compilers where every variable is assigned a value exactly once. PHI nodes are used to handle control flow merges.
DCE
Dead Code Elimination. An optimization pass that removes code that does not affect the program's output.
Filed Under: optimizationphioptssa