RISC-V combines shift-add with word rotations for performance
GCC now combines RISC-V Zba shift-add operations with word rotations, reducing instruction count and improving performance.
GCC has gained the ability to combine shift-add operations (from the RISC-V Zba extension) with word rotations. This optimization targets specific instruction sequences, particularly when performed at XLEN width before a word rotation. Benchmarks show significant reductions in retired instructions and execution cycles on RV64 systems, with improvements up to ~10% in some microbenchmarks.
In Details
This commit enhances the RISC-V backend's pattern matching in config/riscv/bitmanip.md. It adds a new split for sequences where a shift-add operation (e.g., shNadd) is immediately followed by a word rotation. This is particularly relevant for the Zba and Zbb extensions. The optimization aims to recognize and fuse these patterns, which can be common in bit manipulation routines, leading to better instruction scheduling and reduced execution time. The impact on microbenchmarks and specific alignment cases is detailed.
- RISC-V Zba
- A standard extension for the RISC-V instruction set architecture that adds bit manipulation instructions, including shifts and additions.
- word rotation
- A bitwise operation that shifts the bits of a word to the left or right, with the bits shifted out wrapping around to the other end.
- XLEN
- The native word size of the RISC-V architecture, which is typically 32 bits (RV32) or 64 bits (RV64).
- microbenchmark
- A small, highly optimized program designed to measure the performance of a specific instruction or sequence of instructions.