binutils Newspaper
NOVEMBER 30, 2026
risc-v — Proposed

RISC-V: Compress jr and jalr with a zero offset

Enhances RISC-V assembler to compress `jr` and `jalr` instructions when they have a zero offset, aligning with LLVM and improving code density.

This patch modifies the RISC-V assembler in binutils to correctly compress jr and jalr instructions when they have an explicit zero offset or target specific registers like x0 or ra. Previously, only simpler forms of jr and jalr were compressed. This update introduces Zca aliases for these forms, allowing them to be encoded as c.jr and c.jalr, similar to LLVM’s behavior, thus improving code density.

In the Thread 1 participant
  1. Kito Cheng <kito.cheng@sifive.com> proposer

    Submits patches to enable compressed encoding for RISC-V `jr` and `jalr` instructions with zero offsets and specific register targets, matching LLVM's behavior.

    “gas compressed "jr a2" and "jalr a2", but not the same jumps written with an explicit zero offset or an explicit x0 or ra destination, such as "jalr x0, 0(a2)". Add Zca aliases for those forms so they become c.jr and c.jalr too, which matches LLVM.”

In Details

This series of patches targets the RISC-V assembler (gas) to improve the compression of jump instructions (jr and jalr). It introduces new operand types (r for ra, z for x0) and associates them with the Zca instruction alias. This ensures that jumps with zero offsets or jumps to the zero register (x0) or return address register (ra) are correctly encoded using their compressed forms (c.jr, c.jalr), enhancing code size optimization.

For Context
RISC-V
An open-standard instruction set architecture based on RISC principles.
gas
The GNU Assembler, part of the GNU Binutils package.
jr
Jump Register, an instruction that jumps to an address specified in a register.
jalr
Jump and Link Register, an instruction that jumps to an address specified in a register and saves the return address.
Zca
A proposed RISC-V extension that provides compressed aliases for jr and jalr instructions.
Filed Under: RISC-Vbinutilsgascompressionoptimization