GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
bb-reorder Performance Win

bb-reorder unfactors loop switch dispatches for better indirect prediction

Loop switch dispatches are unfactored to give each predecessor its own computed goto, improving indirect target prediction.

The block reordering pass now unfactors loop switch dispatches, a common pattern in bytecode interpreters. Instead of a single jump table dispatch at the loop head, each eligible predecessor is given its own computed goto. This transformation aims to improve indirect target prediction by making the dispatch targets more explicit. The pass copies single-predecessor fall-through chains, using shared table representations and respecting existing constraints like function partitioning and stack register usage.

In Details

The bb-reorder pass now transforms loop-head switch dispatches into computed gotos. This optimization targets interpreter-style code where a single indirect branch dispatches to multiple handlers. By duplicating the guarded tablejump sequence (handler -> range check -> tablejump) for each eligible predecessor, it effectively replaces a single dispatch with multiple computed gotos. This is achieved by copying single-predecessor fall-through chains, ensuring the shared table representation is maintained, and adhering to constraints such as direct DFS back edges to the chain head and the `ca…

For Context
basic block
A sequence of instructions with a single entry point and a single exit point. Control flow only enters at the beginning and leaves at the end.
loop switch dispatch
A control flow structure, often at the head of a loop, that uses a jump table or computed goto to select one of several execution paths based on a computed index.
computed goto
A control flow mechanism where the target of a jump is determined at runtime by an expression, rather than being a statically known label.
indirect target prediction
A CPU feature where the branch predictor attempts to guess the target of indirect branches (like those involving jump tables or computed gotos) to improve performance.
jump table
A data structure used to implement efficient multi-way branching. It typically contains addresses of target code blocks, allowing a program to jump to a specific block based on an index.
Filed Under: bb-reorderoptimizationbytecode interpreter