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

cfgcleanup: Keep computed goto predecessors apart for tail merging

Avoids merging computed goto predecessors, improving code size for some cases and enabling tail duplication.

This change modifies the cfgcleanup pass to prevent tail merging for the predecessors of computed gotos. Previously, these tails were merged unconditionally, which interfered with the pass_duplicate_computed_gotos pass. By gating tail merging on the same condition as tail duplication (!optimize_function_for_size_p && flag_expensive_optimizations), this commit ensures that tail duplication can occur when beneficial. This results in smaller code size for certain computations and enables better optimization in specific scenarios, as demonstrated by aarch64 code size reductions.

In Details

The cfgcleanup pass is responsible for various control flow graph transformations. This commit modifies try_crossjump_bb to avoid merging the tails of basic blocks that are predecessors of a computed goto. This is necessary because the pass_duplicate_computed_gotos pass relies on these tails being distinct to duplicate them. The gate for this behavior is now aligned with !optimize_function_for_size_p && flag_expensive_optimizations, ensuring that tail merging is avoided only when expensive optimizations like computed goto tail duplication are enabled and not optimizing for size. A sim…

For Context
computed goto
A control flow construct where the target of a goto statement is determined at runtime, often through an indirect jump instruction. This allows for dynamic branching based on computed values, commonly used for implementing switch statements or state machines.
tail merging
An optimization technique that combines identical sequences of basic blocks at the end of multiple control flow paths into a single block. This reduces code duplication and can improve instruction cache performance.
basic block
A sequence of consecutive instructions in a program that has exactly one entry point and one exit point. Control flow can only enter at the beginning and leave at the end.
control flow graph (CFG)
A representation of all the paths a program's control flow might take. It is a directed graph where nodes represent basic blocks and edges represent possible transfers of control between them.
pass_duplicate_computed_gotos
A GCC compiler pass that duplicates the code following a computed goto into each predecessor basic block. This can enable further optimizations by making the control flow more linear and exposing opportunities for instruction-level parallelism.
Filed Under: optimizationcfgcleanupaarch64