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

Vectorizer: Ensure unsigned arguments for .CLZ, .CTZ, and .POPCOUNT

Corrects vectorizer patterns to ensure unsigned arguments for bitwise intrinsics.

This commit modifies vectorizer patterns to guarantee that signed arguments are converted to unsigned types before being passed to internal functions .CLZ, .CTZ, and .POPCOUNT. Previously, some patterns could incorrectly pass signed arguments, leading to potential issues. The changes ensure type correctness by introducing explicit conversions, maintaining the bitwise integrity of the operations. This work complements GIMPLE verifier changes that reject signed arguments for these intrinsics.

In Details

The vectorizer's pattern matching routines, specifically vect_recog_ctz_ffs_pattern and vect_recog_popcount_clz_ctz_ffs_pattern, had a flaw where signed integer types could be passed to internal functions .CLZ, .CTZ, and .POPCOUNT. These IFNs are defined only for unsigned types. This patch introduces explicit conversions from signed to unsigned types within these patterns before the IFNs are invoked. This ensures type safety and compliance with the IFNs' requirements, preventing later verification failures and potential misinterpretations of bitwise operations on signed values.

For Context
Vectorizer
A compiler pass that transforms scalar code into vector (SIMD) code to improve performance on multi-core processors by performing the same operation on multiple data elements simultaneously.
.CLZ
An internal function representation for 'count leading zeros'.
.CTZ
An internal function representation for 'count trailing zeros'.
.POPCOUNT
An internal function representation for 'population count' (counting set bits).
GIMPLE
GCC's internal three-assignment representation, an intermediate language used for optimization.
Filed Under: vectorizationcompilerintrinsicstype safety