match.pd: Fix popcount (~X) ICE on vector types
match.pd: Fixes an ICE when simplifying popcount of a bitwise NOT on vector types.
This commit resolves an Internal Compiler Error (ICE) occurring in the match.pd optimization pass when simplifying popcount(~X) for vector types. The simplification rule popcount (~X) -> PREC - popcount (X) incorrectly tried to access the type precision before verifying if the operand was an integral type. This caused a failure when popcount was applied to a vector type, as TYPE_PRECISION is not defined for vectors. The fix ensures the integral type check precedes the precision query, preventing the ICE.
In Details
The popcount (~X) optimization in match.pd previously computed TYPE_PRECISION of the operand before checking INTEGRAL_TYPE_P. This caused an ICE when the operand was a vector type, as TYPE_PRECISION is undefined for vectors and fails the tree check. The fix reorders these checks, ensuring that TYPE_PRECISION is only accessed after confirming the operand is integral. This preserves the scalar-only nature of the fold, avoiding unnecessary vector operations.
- match.pd
- A pattern-matching component within GCC, likely related to instruction selection or optimization, that uses pattern descriptions to guide transformations.
- popcount
- A function that counts the number of set bits (1s) in the binary representation of an integer.
- ICE
- Internal Compiler Error. An unrecoverable error encountered by the compiler during the compilation process, typically indicating a bug in the compiler itself.
- vector types
- Data types that hold multiple elements of the same base type, designed to be processed in parallel by SIMD (Single Instruction, Multiple Data) instructions.
- TYPE_PRECISION
- A GCC internal representation macro or function that returns the number of bits in a given data type.
- INTEGRAL_TYPE_P
- A GCC internal predicate that checks if a given data type is an integral type (e.g., int, long, char).
- scalar fold
- An optimization that simplifies an expression involving scalar (non-vector) values.