RISC-V Zbs bclr instructions avoid redundant masks
RISC-V bit manipulation extension (Zbs) bclr instructions now recognize and eliminate redundant masks on indices.
This commit optimizes the RISC-V Zbs extension by eliminating redundant masks in bit clear (bclr) instructions. The bclr instruction inherently uses only the necessary lower bits of its index. The compiler now recognizes rotate forms with explicit masks and directly emits the bclr instruction, avoiding unnecessary masking operations on RV32 and RV64 architectures. This simplifies generated code and potentially improves performance.
In Details
The RISC-V Zbs extension's bclr instruction operates on bit indices using only the lower log2(XLEN) bits. This commit modifies gcc/config/riscv/bitmanip.md to recognize patterns where an XLEN - 1 mask is applied to the index before the bclr operation. Instead of generating the masked index and then bclr, the compiler now directly emits bclr when it detects this redundant masking, particularly in rotate-with-mask scenarios.
- RISC-V
- An open-standard instruction set architecture based on Reduced Instruction Set Computing principles. It is modular and extensible, allowing for custom extensions like bit manipulation.
- Zbs
- A standard RISC-V extension that adds bit manipulation instructions to the architecture, including operations like bit clear (bclr), bit set (bset), bit invert (binv), and bit test (btst).
- bclr
- A RISC-V Zbs instruction that clears (sets to 0) a specified bit in a register. It takes a register and a bit index as operands.
- RV32/RV64
- Specific base integer instruction set variants of RISC-V. RV32 uses 32-bit registers and addresses, while RV64 uses 64-bit registers and addresses.
- XLEN
- A parameter in the RISC-V architecture that defines the register and memory address size. For RV32, XLEN is 32; for RV64, XLEN is 64.