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

RISC-V handles SImode for masked bit and rotate counts

RISC-V support in GCC now correctly handles SImode for masked bit indices and rotate counts, fixing redundant masks and improving performance.

GCC’s RISC-V backend now properly supports SImode (single integer precision) for masked bit indices and rotation counts. Previously, unsigned-short promotion on RV64 led to redundant masks. This change eliminates those masks, enabling native rotations and improving performance. Microkernels show reduced retired instructions and execution cycles, with gains up to ~14% in instruction count and ~20% in cycles.

In Details

This commit modifies the RISC-V backend's machine description (config/riscv/bitmanip.md) to correctly handle SImode for operands representing masked bit indices and rotation counts. On RV64, there was an issue where these counts, if smaller than XLEN, were incorrectly promoted, leading to unnecessary masking operations. The change ensures that native SImode counts are used where appropriate, especially for bit manipulation instructions in the Zbs and Zbb extensions. This improves efficiency and correctness, particularly for operations involving rotate and bit set/clear instructions.

For Context
SImode
GCC's internal representation for a single-precision signed integer, typically 32 bits.
DI mode
GCC's internal representation for a double-precision integer, typically 64 bits.
masked bit index
An index used in bit manipulation operations where only a subset of bits is relevant, often determined by a mask.
rotation count
The number of positions by which bits in a word are rotated.
Zbs
A standard extension for the RISC-V instruction set architecture that adds bit manipulation instructions for setting, clearing, and testing bits.
Zbb
A standard extension for the RISC-V instruction set architecture that adds bit manipulation instructions for common bitwise operations like AND, OR, XOR, shifts, and rotations.
Filed Under: risc-voptimizationbit manipulation