GCC Newspaper
OCTOBER 6, 2026
gcc — Proposed

Redundant return-only BB not eliminated

A patch to optimize CFG cleanup by removing redundant return-only basic blocks is discussed, with suggestions on implementation details.

Robert Guthrie proposes a patch to eliminate redundant consecutive return-only basic blocks in the CFG cleanup pass. He initially struggled with debugging but found the solution straightforward after resolving misunderstandings. Another participant (implied by the quote) suggests a different approach, focusing on predecessor and successor lists rather than prev_bb/next_bb for block ordering.

In the Thread 2 participants
  1. Robert Guthrie proposer

    Submitted a patch to optimize CFG cleanup by removing redundant consecutive return-only basic blocks and explained his debugging process.

    “Thanks -- I didn't want to ask anyone to debug my stuff, and anyways it took a bit of time but was straightforward. Most of the debugging has just been me resolving my misunderstandings about what certain functions do or variables are for, which is helpful for me.”
  2. unknown reviewer

    Critiqued the patch's approach of using `prev_bb`/`next_bb`, suggesting that predecessor and successor lists are more relevant for block ordering in CFG cleanup.

    “So in general you don't want to be looking at prev_bb/next_bb. Yes, blocks are kept in a chain, but there's really no meaning to the order of the chain until after block layout. What really matters are the pred/succ lists.”

Technical Tradeoffs

  • Reliance on `prev_bb`/`next_bb` vs. predecessor/successor lists for CFG manipulation.

In Details

This discussion concerns the cfgcleanup.cc pass in GCC's middle-end. The patch proposes to optimize the Control Flow Graph (CFG) by removing redundant basic blocks that contain only a return instruction and immediately follow another such block. The core of the discussion revolves around the correct way to identify and manipulate these blocks within the CFG data structures, specifically whether to rely on the block's immediate predecessor/successor pointers or the more general predecessor/successor lists.

For Context
Basic Block (BB)
A sequence of instructions with 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 possible execution paths through a program. Nodes are basic blocks, and edges represent control flow transfers.
cfgcleanup.cc
A GCC source file containing functions for cleaning up and optimizing the control flow graph.
return-only BB
A basic block that contains only a return instruction and no other executable code.
Predecessor/Successor Lists
In a CFG, predecessor lists contain nodes that transfer control to the current node, while successor lists contain nodes that the current node transfers control to.
Filed Under: optimizationcfg