Vector pattern matching handles non-mode precision types for popcount/clz/ctz.
Fixes vectorization pattern matching for bit integer types to correctly handle operations like popcount, clz, and ctz.
This commit corrects the vectorization pattern matching for built-in functions such as popcount, clz, ctz, and ffs when used with non-standard integer types (like _BitInt). Previously, the pattern matching in vect_recog_popcount_clz_ctz_ffs_pattern did not adequately check for type_has_mode_precision_p, leading to incorrect vectorization and miscompilation on architectures like AArch64. The fix ensures that these operations are correctly matched by casting to the appropriate vector type, thus preserving padding bit behavior and resolving PR 127149.
In Details
The vect_recog_popcount_clz_ctz_ffs_pattern in tree-vect-patterns.cc is updated to correctly handle types without standard mode precision, such as _BitInt(N). Previously, for builtins other than clz, it did not require type_has_mode_precision_p(lhs_type), allowing it to match patterns with arguments of types like _BitInt(7). This led to incorrect vectorization and issues with padding bits. The patch adds casts to the TREE_TYPE (the actual mode precision vector type) to ensure correct handling, resolving PR 127149. A new test gcc.dg/bitint-142.c is added.
- vectorization
- An optimization technique that allows the compiler to perform the same operation on multiple data elements simultaneously using special vector instructions (SIMD).
- vect-patterns
- A component within GCC's vectorization framework responsible for recognizing specific code patterns that can be vectorized. This involves matching source code constructs against a predefined set of vectorizable operations.
- popcount, clz, ctz, ffs
- Built-in functions that perform specific bitwise operations: population count (number of set bits), count leading zeros, count trailing zeros, and find first set bit, respectively.
- mode precision
- Refers to whether a data type has a well-defined and supported representation within the compiler's internal modes, which are crucial for efficient hardware operations, especially for vectorization.
- _BitInt(N)
- A non-standard C++ integer type that allows users to specify arbitrary bit widths for integers, going beyond standard types like int or long long.