match.pd: Optimize parity of bit-reversed values.
Improves optimization for `parity(bitreverse(x))` by handling generic bit-reverses.
This commit enhances the match.pd pattern matching to correctly optimize the parity of bit-reversed values. Previously, certain bit-reversal operations, particularly for generic _BitInt types and all bit-reverse builtins, were not recognized. This update allows the compiler to simplify expressions like parity(bitreverse(x)) more effectively, similar to how it handles parity(bswap(x)).
In Details
The match.pd file contains patterns for optimizing built-in functions. This patch extends the parity(bswap(x)) optimization rule to also cover BITREVERSE operations, not just BSWAP builtins, and applies it to generic _BitInt types. Since both bswap and bitreverse permute bits without changing their count, the parity (or popcount) remains invariant, enabling this optimization.
- match.pd
- A file containing pattern-matching rules used by GCC's optimization passes to recognize and simplify specific code structures involving built-in functions.
- parity
- In computing, parity refers to whether the number of set bits (1s) in a binary number is even or odd. Calculating parity is often used in error detection.
- BITREVERSE
- A built-in operation that reverses the order of bits within a value. For example,
BITREVERSE(0b1011)might result in0b1101(depending on bit width). - _BitInt
- A GCC extension for arbitrary-precision integer types, allowing integers of any specified bit width, not limited to standard 8, 16, 32, or 64 bits.