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

RISC-V: Improve czero instruction recognition

GCC now recognizes more patterns for the RISC-V czero instruction, improving optimization for conditional moves.

GCC has added new patterns and splitters for the RISC-V czero instruction, enhancing its ability to recognize and optimize conditional move operations. This update specifically targets cases where czero is formed using logical operations, including those involving negated values and bitwise operations, leading to more efficient code generation for RISC-V architectures.

In Details

This commit enhances config/riscv/zicond.md by adding a new define_insn for czero derived from logical operations and define_splits for cases where these patterns are used within an IOR for conditional selection. It addresses PR tree-optimization/127813 by improving pattern matching for (and (neg (reg1)) (reg2)) and (plus (reg1) (const_int -1)) when reg1 is zero/one, and handling them when wrapped by an IOR in combine.

For Context
czero
A RISC-V conditional move instruction that sets a destination register to zero if a condition is met, otherwise it's a no-op or sets the destination to a different value. It's used for efficient conditional assignments.
RISC-V
A RISC (Reduced Instruction Set Computer) instruction set architecture (ISA) that is open, extensible, and designed for modern computing systems from embedded to high-performance.
RTL
Register Transfer Language, an intermediate representation used within GCC to describe operations and data flow before code generation.
combine
A GCC optimization pass that performs local code optimizations, such as instruction combining and peephole optimizations, on the RTL generated by earlier passes.
IOR
Inclusive OR, a bitwise logical operation. In this context, it might be used as part of a sequence to construct conditional values or selections.
Filed Under: riscvoptimization