GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
ext-dce

ext-dce: Fix Off-By-One in Subreg Liveness for 32-Bit Modes

Corrects a bit liveness calculation in ext-dce, enabling lw -> lwu narrowing on RV64.

This commit fixes an off-by-one error in the ext-dce pass that affected the liveness analysis of subregisters, specifically for 32-bit modes. The incorrect liveness information prevented the pass from recognizing when the upper half of a 64-bit register was unused, blocking optimizations like lw -> lwu narrowing on RV64 (RISC-V 64-bit).

In Details

The commit corrects a flaw in ext_dce_process_uses within ext-dce.cc. The condition size >= 32 incorrectly marked bits 32-63 as live for SImode subregs (size == 32), hindering the detection of dead upper halves of DImode registers. The change replaces the condition with size > 32 to align with other thresholds, enabling optimizations such as lw -> lwu on RV64.

For Context

The ext-dce pass identifies and eliminates code that doesn't affect the final result. This requires precise tracking of which bits of a value are actually used (liveness analysis). This commit fixes a bug where the analysis incorrectly assumed some bits were live, preventing it from optimizing code on 64-bit RISC-V systems. Specifically, it enables the compiler to replace a 32-bit load that sign-extends the value (lw) with one that doesn't (lwu) when the upper 32 bits are known to be unused.

Filed Under: optimizationdead code eliminationrisc-v