GCC Newspaper
OCTOBER 6, 2026
gcc — Proposed

redundant return-only BB not eliminated

Discussion on the complexities of eliminating redundant return-only basic blocks in GCC, considering different optimization modes.

Jeff Law provides guidance on eliminating redundant return-only basic blocks in GCC, explaining that it can be done after prologue/epilogue threading. The discussion touches on the differences between CFGRTL and CFGLAYOUT modes and how the optimization should conceptually work by examining predecessors of the exit block.

In the Thread 2 participants
  1. Jeff Law <jeffrey.law@oss.qualcomm.com> proposer

    Explains that eliminating a redundant return-only block is feasible after prologue/epilogue threading and can be done by modifying CFG edges to point to a new target block.

    “Conceptually a block ending in a return can have its return removed and the cfg altered so that it has a fallthru edge to a block that has a return and nothing else. This is true before and after cfg layout mode. The refined wrinkle is you have to be past threading the prologue/epilogue. It's only after that point that you know if you have a trivial return or not. So conceptually you could e…”
  2. Robert Guthrie contributor

    Acknowledges the complexity and describes encountering issues with infinite loops and differing behavior between CFGRTL and CFGLAYOUT modes when modifying `cleanup_cfg`.

    “That is true: it has been a little harder than I expected! Since I am modifying cleanup_cfg, and it is called so many times, I am getting a lot of weird interactions leading to infinite loops or other errors. Or getting different behavior when it is called in CFGRTL vs. CFGLAYOUT mode (I spent last evening trying to grok the difference).”

Technical Tradeoffs

  • Complexity of CFG manipulation across different optimization modes.
  • Ensuring correctness of edge redirection and fall-through handling.

In Details

This discussion pertains to optimizing the control flow graph (CFG) in GCC by eliminating redundant basic blocks that solely contain a return statement. It delves into the intricacies of when this optimization can be safely applied, particularly concerning the stages of CFG manipulation (CFGRTL vs. CFGLAYOUT) and the impact of prologue/epilogue threading, suggesting a strategy involving predecessor analysis and edge redirection.

For Context
basic block
A sequence of instructions with a single entry point and a single exit point. Control flow enters at the beginning and exits at the end without halt or possibility of branching except at the exit.
CFG
Control Flow Graph, a representation of all execution paths in a program, typically used by compilers for analysis and optimization.
CFGRTL
A stage in GCC's compilation pipeline where the code is represented in RTL (Register Transfer Language), a low-level intermediate representation.
CFGLAYOUT
Likely refers to a phase in GCC's CFG manipulation where basic blocks are laid out and fall-through edges are established.
prologue/epilogue threading
A compiler optimization step that standardizes the entry (prologue) and exit (epilogue) code of functions, often simplifying subsequent analyses and optimizations.
Filed Under: gccoptimizationcfgrisc-v