GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
vect

Vectorization patterns check CLZ/CTZ value at zero for all precisions

Vectorizer patterns for count leading/trailing zeros now correctly handle the case where the second argument is zero, improving code generation for specific pr…

The vectorizer’s pattern recognition for popcount, clz, ctz, and ffs intrinsics has been updated. Previously, it only checked the second argument against the target value when the argument and result precisions differed. This commit modifies the logic to perform this check for all precisions, ensuring that scalar calls remain scalar even when lanes produce zero, which is crucial for correctness on platforms like AArch64.

In Details

The vect_recog_popcount_clz_ctz_ffs_pattern function in tree-vect-patterns.cc identifies opportunities to replace scalar clz and ctz operations with vector instructions. This commit corrects a condition where differing operand and result precisions could lead to incorrect scalar emulation when the second argument was zero, specifically impacting AArch64 by producing an incorrect width (32 instead of the intended value). The fix ensures the check is performed universally, preventing incorrect scalarization.

Filed Under: vectorizationaarch64