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

vect: Defined-at-zero value for .CLZ/.CTZ

Vectorization patterns now correctly consider the defined-at-zero value for CLZ/CTZ operations in vector modes.

This commit improves vectorization of CLZ and CTZ operations by correctly handling the ‘defined-at-zero’ value. It ensures that during pattern matching for vectorization, the defined-at-zero value for the natural vector mode is used, rather than a scalar mode’s value, as these can differ. A final check is performed during vectorizable_call to ensure consistency between the natural and final vector modes.

In Details

This change refines the vectorization component (tree-vect-patterns.cc, tree-vect-stmts.cc) of GCC. It addresses subtleties in CLZ/CTZ intrinsics where the result for an input of zero can vary. By using GET_MODE_UNIT_BITSIZE and considering vector mode-specific zero values (e.g., in i386.h, rs6000.h), the vectorizer can more accurately identify and optimize these operations, especially when the target vector mode's element size differs from scalar modes. The vectorizable_call function includes a safeguard for cases where natural and final vector modes might have different at-zero…

For Context
vect
The GCC optimization pass responsible for vectorization, which transforms scalar code into SIMD (Single Instruction, Multiple Data) code to process multiple data elements in parallel.
.CLZ
An intrinsic or pattern representing the count-leading-zeros operation, which calculates the number of zero bits from the most significant bit down to the first set bit.
.CTZ
An intrinsic or pattern representing the count-trailing-zeros operation, which calculates the number of zero bits from the least significant bit up to the first set bit.
defined-at-zero value
The specific value returned by an operation (like CLZ or CTZ) when its input is zero. This value can be architecture- or mode-dependent.
SIMD
Single Instruction, Multiple Data. A class of parallel computing in which a single operation is performed on multiple data points simultaneously.
Filed Under: optimizationvectorization