GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc

RISC-V: Improve bitmanip instruction selection with stricter operands

Corrects RISC-V bit manipulation instruction selection by using more specific operand types to prevent ICEs.

This commit strengthens the RISC-V bit manipulation instruction selection by replacing overly permissive operand matchers with stricter ones. It changes immediate_operand and arith_operand to const_int_operand and reg_operand respectively, preventing the compiler from incorrectly attempting to use immediate values or registers in contexts where only constant integers are valid. This resolves potential ICEs and unexpected behavior.

In Details

This patch refines the instruction patterns in config/riscv/bitmanip.md and associated predicates. It addresses cases where accessor macros like UINTVAL could be applied to non-CONST_INT operands (e.g., immediate_operand, arith_operand), potentially leading to ICEs or incorrect code generation. By switching to const_int_operand and reg_operand where appropriate, it ensures that the instruction predicates correctly constrain the operands, improving robustness and preventing erroneous matching.

For Context
ICE
Internal Compiler Error. A severe error within the compiler itself, typically indicating a bug in the compiler's logic.
operand
A value or reference on which an instruction or function operates.
const_int_operand
An operand that is specifically a constant integer value, used to constrain instruction patterns to only accept immediate integer constants.
immediate_operand
An operand that can be either a constant integer or a register, which can be less restrictive than desired for certain instructions.
bitmanip
Refers to instructions that perform bitwise operations, such as shifts, rotations, and bit manipulation.
Filed Under: risc-voptimizationbackend