match.pd: Correct parity(~x) simplification for odd bit-widths.
Fixes incorrect parity calculation for bitwise NOT on odd-width integers.
A simplification rule in match.pd incorrectly assumed that parity(~X) is always equivalent to parity(X). This commit corrects that rule, noting that for integer types with an odd number of bits, parity(~X) is actually equivalent to parity(X) ^ 1. This ensures accurate parity calculations for bitwise NOT operations on types with odd precision, fixing PR126471.
In Details
The match.pd optimization patterns include a simplification for parity(~X). This pattern incorrectly assumed that flipping all bits (~X) results in the same parity as the original value X. However, this is only true for even-width types. For odd-width types, flipping each bit changes the parity of the set bits, hence parity(~X) equals parity(X) ^ 1. The patch adds this condition to the match.pd rule.
- 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.
- _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.