RISC-V: Optimize bitfield extraction by dropping unnecessary shifts.
RISC-V compiler optimizes bitfield extraction by removing redundant shifts when high bits are unused.
This change optimizes RISC-V bitfield extraction by removing unnecessary shifts when the upper bits of the extracted field are not read by subsequent instructions. This optimization, inspired by LLM analysis of the x264 benchmark, simplifies code generation and can eliminate redundant operations. While the performance impact on x264 is minimal, the change aims to benefit other scenarios where this pattern appears.
In Details
This commit modifies gcc/config/riscv/riscv.md to introduce a new splitter for bitfield extraction. When a bitfield extraction (e.g., using srl and sra or similar) creates a field wider than the subsequent use, the unread upper bits are irrelevant. This optimization avoids generating unnecessary shift instructions by recognizing that these high bits are don't-cares, similar to how DCE might operate but implemented directly in the instruction selection.
This is relevant to RISC-V backend code generation and instruction selection.