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

RISC-V: Improve cost modeling for word packing with Zbkb

Optimized instruction selection for RISC-V word packing operations, improving performance.

This commit enhances the RISC-V backend by generalizing cost modeling for word packing instructions, specifically with the Zbkb extension. It extends the cost calculations for packh to also cover pack operations, enabling the combine pass to select these instructions when Zba is enabled. Performance improvements were observed in microbenchmarks and benchmarks like the SQLite varint decoder.

In Details

The riscv_rtx_costs function in GCC's RISC-V backend now uses a new helper riscv_pack_expr_p to generalize and share cost calculations for packh instructions to cover pack instructions as well. This allows the combine pass to better select packing operations when the Zba extension is enabled, improving instruction selection and performance for word packing sequences.

For Context
Zbkb
A RISC-V extension that provides bit manipulation instructions, including byte packing and unpacking operations.
Zba
A RISC-V extension that provides arithmetic instructions, including addition, subtraction, and packing operations.
packing
An operation that combines multiple smaller data elements (e.g., bytes) into a larger data type (e.g., a word).
combine pass
A GCC optimization pass that performs instruction combining and selection based on machine-specific costs.
Filed Under: risc-voptimization