vect: Handle zero values in bit count patterns for CLZ/CTZ.
Vectorization of CLZ/CTZ instructions now correctly handles cases where the value at zero is not the target value.
The vectorization recognition pattern for count-leading-zeros (CLZ) and count-trailing-zeros (CTZ) instructions now correctly handles scenarios where the ‘value at zero’ is not equal to the target value for the vector mode. A select operation is employed, similar to existing patterns, to ensure correct results when dealing with zero lanes. This fix enables vectorization for certain AArch64 code sequences.
In Details
The vect_recog_popcount_clz_ctz_ffs_pattern in tree-vect-patterns.cc previously punted on two-argument .CLZ or .CTZ operations if the 'value at zero' (the result when the input is zero) did not match the expected vector mode target plus the CLZ addend. This commit introduces a select mechanism, mirroring vect_recog_ctz_ffs_pattern, to handle this discrepancy. If the count is needed, it uses the value at zero of the call, and the select then correctly chooses between the calculated count and the value at zero for lanes where the input is zero. This enables vectorization for code…
- vectorization
- The process of transforming scalar code into vector code, where a single instruction operates on multiple data elements simultaneously.
- CLZ
- Count Leading Zeros. An instruction that counts the number of zero bits from the most significant bit up to the first set bit.
- CTZ
- Count Trailing Zeros. An instruction that counts the number of zero bits from the least significant bit up to the first set bit.
- vector mode
- Refers to the data type and size used by SIMD (Single Instruction, Multiple Data) or vector instructions, which operate on multiple data elements in parallel.
- AArch64
- The 64-bit execution state of the ARMv8-A architecture.