GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
loongarch

LoongArch: Correct immediate range for bit reversal instructions

Fixes immediate value range for LoongArch's `vbitrevi` instructions, preventing assembler errors.

This commit corrects the operand validation for LoongArch’s lsx_vbitrevi instructions. Previously, these instructions incorrectly used a predicate designed for branch offsets (const_lsx_branch_operand) to validate their immediate values. The immediate for vbitrevi represents a bit index, and its valid range depends on the element size (3-6 bits). By switching to the correct const_<bitimm>_operand predicate, the compiler now accurately checks the immediate range, preventing out-of-range values from being emitted and causing assembler errors.

In Details

The LoongArch backend's SIMD instruction set (LASX/LSX) includes bit reversal instructions like vbitrevi. The immediate operand for these instructions specifies the bit index. The machine description (.md files) incorrectly used const_lsx_branch_operand, which has a range of -1024 to 1023, intended for branch offsets. This commit rectifies this by using const_<bitimm>_operand, which correctly constrains the immediate to the size of the element type (e.g., 3 bits for byte elements, 6 bits for doubleword elements). This change also involves cleaning up unused predicates and updating ins…

For Context
SIMD
Single Instruction, Multiple Data. A type of parallel processing where a single instruction operates on multiple data points simultaneously, typically using dedicated vector registers and instructions.
Immediate value
A constant value embedded directly within an instruction, as opposed to a value read from a register or memory.
RTL
Register Transfer Language, an intermediate representation used within GCC.
Predicate
In GCC's machine description files, a predicate is a condition or test used to determine if an instruction pattern is valid for a given set of operands or target architecture features.
Filed Under: loongarchsimdcompiler-backendinstruction-set