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

Fix RISC-V code quality regression for bit manipulation

Restores correct code generation for RISC-V bit manipulation sequences involving AND and OR operations.

This commit corrects a code quality regression on the RISC-V port stemming from a change in instruction steering. The previous steering towards PLUS for certain bit manipulation sequences, which involved an outer OR and an inner AND, caused incorrect code generation. The fix adjusts the bit manipulation logic to use IOR as the outer operation and modifies the AND mask, ensuring semantic correctness and improving code quality by avoiding unnecessary instructions.

In Details

A regression in RISC-V code generation occurred because the steering towards PLUS for sequences like AND(mask, OR(bits, cleared_bits)) was incorrect. The previous AND mask would clear bits that were then turned on by the outer OR. This change in config/riscv/bitmanip.md corrects this by using an outer IOR and adjusting the AND mask, effectively reverting to a more correct sequence that avoids turning bits back on unnecessarily. This addresses a code quality issue related to PR58727.

For Context
RISC-V
An open-standard instruction set architecture (ISA) based on Reduced Instruction Set Computer principles.
AND
Logical AND operation. Returns true only if both operands are true.
OR
Logical Inclusive OR operation. Returns true if at least one of the operands is true.
PLUS
Likely refers to the ADD instruction or a similar arithmetic operation.
IOR
Inclusive OR. A logical operation that results in true if at least one of the operands is true.
bclr
Bit Clear. An instruction that clears a specific bit in a value.
Filed Under: risc-voptimizationcode quality