Two RISC-V bit manipulation bugs fixed, one related to LLM review
Two bugs in RISC-V bit manipulation patterns are fixed, addressing issues with sign extension preservation and potential negative shift counts.
This commit corrects two bugs in GCC’s RISC-V bit manipulation patterns. The first fix ensures that a pattern rewriting ‘and+bclr+addiw’ to ‘bclr+ior’ properly preserves the sign extension from 32-bit to 64-bit integers. The second fix addresses a pattern that transforms ‘slli+zext+shNadd’ into ‘slli+shNadd.uw’, preventing the generation of negative shift counts, which could occur if costs for certain shifts were reduced in the future.
In Details
Two bugs in gcc/config/riscv/bitmanip.md are corrected. The first addresses an optimization that rewrites and+bclr+addiw to bclr+ior. The original pattern incorrectly handled sign extension preservation when the and operation involved the sign bit of a 32-bit operand being extended to 64 bits. The corrected pattern now ensures this sign extension is maintained. The second fix concerns a transformation from slli+zext+shNadd to slli+shNadd.uw. This pattern is now guarded to prevent generating negative shift counts, which could become an issue if the cost model for shNadd operation…
- bitmanip.md
- A file within the GCC source code containing machine description patterns for bit manipulation instructions and optimizations specific to the RISC-V architecture.
- SI mode
- Single Integer mode, typically representing a 32-bit integer in GCC's internal representation.
- DI mode
- Double Integer mode, typically representing a 64-bit integer in GCC's internal representation.
- sign extension
- The process of copying the most significant bit (sign bit) of a number to extend it to a larger data type, preserving its signed value.
- bclr
- Bit Clear instruction, often used in bit manipulation operations.
- ior
- Inclusive OR operation, a bitwise logical operation.
- slli
- Shift Left Logical Immediate instruction, shifts bits to the left by a constant amount.
- zext
- Zero Extend, an operation that extends a smaller integer to a larger one by filling the most significant bits with zeros.
- shNadd
- A fused instruction that combines a shift operation with an addition, often found in bit manipulation instruction sets.