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

Improve selects between , and for RISC-V

RISC-V: Optimizes specific conditional select patterns, reducing instruction count in x264.

This commit enhances the RISC-V port by improving the generation of code for specific conditional select patterns involving constants 0, 3, 5, and 9. These patterns often arise when using the output of a comparison instruction as arguments to a shift-add operation. The changes introduce a new predicate int_cmp_operator and a new function riscv_single_scc_p to better detect and optimize these cases, leading to a reduction in instruction count, particularly noted in the x264 benchmark. This work also paves the way for potentially cleaning up other related patterns in zicond.md.

In Details

This patch targets specific if-then-else patterns on RISC-V where one branch is 0 and the other is 3, 5, or 9. These arise from utilizing the output of SCC (Set Conditional) instructions as operands for shift-add patterns. It introduces riscv_flag_select_code and riscv_single_scc_p functions, along with int_cmp_operator in predicates.md, to recognize and optimize these Select patterns using a single instruction where possible. This is part of a larger effort to improve RISC-V's instruction selection for conditional operations, potentially impacting zicond.md.

For Context
RISC-V
An open-standard instruction set architecture (ISA) based on Reduced Instruction Set Computing principles.
select
In this context, refers to conditional operations that select one of two values based on a condition. Often implemented using conditional move or branch instructions.
SCC
Set Conditional. A type of instruction that sets a register based on the result of a comparison, often used for condition codes.
shift-add pattern
A common sequence of instructions involving bit shifts and additions, often used for arithmetic operations or memory address calculations.
x264
A popular open-source software library for encoding video into the H.264/AVC format.
predicate
In instruction selection, a condition that must be met for a particular pattern or instruction to be applicable.
zicond.md
A GCC machine description file for the RISC-V architecture, likely containing patterns for conditional instructions.
Filed Under: RISC-Voptimizationinstruction selectionx264