GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc/risc-v Performance Win

Add scalar memset for RISC-V

RISC-V now includes a scalar memset implementation, avoiding library calls when vector expansion fails or is unsuitable.

This patch introduces a scalar memset implementation for RISC-V, improving code generation when vector memset expansion is not possible or efficient. It adds a test mode for expanders to check for support without emitting code and a new scalar memset expander for non-zero values and known lengths, preventing unnecessary libcalls.

In Details

This change enhances RISC-V's string operation support by adding a scalar memset expansion. It introduces a testing_p parameter to expand_vec_setmem and riscv_expand_setmem to query expander capabilities without code emission, used by riscv_use_by_pieces_infrastructure_p. A new expand_scalar_setmem function handles non-zero values and known lengths, specifically targeting scenarios where vector expansion fails or falls back to libcalls, especially when by-pieces infrastructure rejects synthesized splat constants.

For Context
memset
A standard C library function that fills a block of memory with a specified byte value.
libcall
A call to a function in an external library, often used as a fallback when the compiler cannot generate inline code for an operation.
by-pieces infrastructure
A GCC internal mechanism for generating code by assembling smaller, known pieces, likely used for string operations or other complex sequences.
splat constant
A constant value that is replicated or 'splatted' across a larger data structure or register, often used in vector operations.
Pmode
A GCC internal register mode, typically used for general-purpose registers that can hold pointers or integral types.
Filed Under: risc-voptimizationstring-operations