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

AArch64: Classify left fold reductions as single cycle for optimization.

Optimizes vector reductions on AArch64 by correctly modeling their latency.

This commit improves AArch64 vectorization of reduction operations, particularly those involving left folds. Previously, the compiler’s cost model did not always accurately account for the serial chain of additions created by fold-left reductions, which share a single accumulator. By classifying these reductions as having a single def-use cycle, the compiler can better estimate their latency. This allows it to select more appropriate vectorization modes, such as VNx4QI for byte-element vectors, which avoids unnecessary widening operations and potentially improves performance.

In Details

This patch modifies aarch64_force_single_cycle to include FOLD_LEFT_REDUCTION. This is crucial because fold-left reductions, especially when vectorizing operations like conditional sums, create a serial chain of dependent additions using a single accumulator. The existing cost model, when applied to reductions not explicitly marked as single-cycle (via def-use chains), might not correctly account for this serial latency. By flagging fold-left reductions, the cost model can correctly multiply the reduction latency by the number of elements, leading to better mode selection (e.g., preferrin…

For Context
AArch64
The 64-bit ARM architecture, commonly used in mobile devices, servers, and embedded systems.
vectorization
The process by which a compiler transforms scalar code into vector instructions, enabling operations on multiple data elements simultaneously for performance gains.
reduction
An operation that combines a sequence of values into a single result, such as summing elements in an array or finding the maximum value.
fold-left reduction
A type of reduction where operations are applied sequentially from left to right, often accumulating results in a single variable. This can create data dependencies that impact parallelization.
cost model
A component within the compiler that estimates the execution cost (e.g., latency, throughput) of different code sequences or instruction choices to guide optimization decisions.
def-use chain
A data structure that tracks where a variable's definition (written value) is used (read value) within the program. This helps in analyzing data dependencies.
SVE
Scalable Vector Extension, an optional feature for ARM architectures that allows vector registers to vary in size, enabling code to adapt to different hardware capabilities.
Filed Under: aarch64vectorizationoptimizationperformance