[RISCV] redundant return-only BB not eliminated

Project / Subsystem

gcc / gcc

Date

2026-08-30

Proposer

Robert Guthrie <forkbombidable@gmail.com>

Source type

public_inbox

Consensus

Proposed

Sentiment

8/10

Technical tradeoffs

  • • The author's custom fix is overly specific and might not generalize.
  • • Incorrectly modifying CFG passes like `try_optimize_cfg` can lead to infinite loops or break other optimizations.

All attributes

project
gcc
subsystem
gcc
patch_id
—
discussion_id
apSEEAiw9CP262re@bertguix
source_type
public_inbox
title
[RISCV] redundant return-only BB not eliminated
headline
RISCV: redundant return-only BB not eliminated
tldr
A factorial function compiled for RISCV produces an unnecessary return instruction, and the contributor seeks guidance on optimization passes.
proposer
Robert Guthrie <forkbombidable@gmail.com>
consensus
Proposed
outcome
proposed
sentiment_score
8
technical_tradeoffs
  • • The author's custom fix is overly specific and might not generalize.
  • • Incorrectly modifying CFG passes like `try_optimize_cfg` can lead to infinite loops or break other optimizations.
series_id
—
series_role
standalone
series_parts
[]
tags
  • • riscv
  • • optimization
  • • compiler-internals
  • • cfg
bugzilla_url
—
date
2026-08-30T00:00:00.000Z

[RISCV] redundant return-only BB not eliminated

The author reports an unnecessary return instruction generated for a RISC-V factorial function due to loop unrolling and fall-through. They investigated optimization passes like ‘bbro’ and ‘cleanup_cfg’ but couldn’t pinpoint the exact pass responsible for not eliminating the redundant basic block. The contributor, new to compiler development, added a custom fix and seeks advice on the correct approach.