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

RISC-V: Fix even-odd pattern matching for narrowing shifts

Corrects RISC-V vector instruction selection for narrowing shifts.

This commit addresses an issue in RISC-V vector code generation related to narrowing shifts by fixing the ‘even-odd’ pattern matching. Previously, the compiler could miss opportunities to use efficient narrowing shift instructions due to an unnecessary check on register natural size and a missing clobber for temporary destinations. The fix removes the redundant check and adds necessary clobbers, ensuring all applicable cases for narrowing shifts are correctly handled.

In Details

The shuffle_even_odd_patterns function in riscv-v.cc is updated to fix PR124996. The regmode_natural_size check, which was no longer necessary after recent fixes, is removed. Additionally, clobbers are introduced for the destination and temporary target (like vec_concat) before they are written, preventing incorrect instruction selection. The temporary variable tmp is also renamed to low and hi for clarity, aligning with vec_concat's naming.

For Context
narrowing shift
A bit shift operation that results in a value smaller than the original operand, often used in vector processing to reduce data width.
pattern matching
A compiler technique where specific code structures (patterns) are recognized and replaced with optimized code sequences.
clobber
In compiler intermediate representations, a clobber indicates that a register or memory location will be modified by an instruction, making its previous value invalid.
vector extension (RVV)
RISC-V Vector Extension, a set of instructions designed for high-performance vector processing.
Filed Under: risc-vvectorizationcodegenbugfix