GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
match-sat-alu.pd Performance Win

AArch64 recognizes unsigned saturating subtraction.

Optimizes unsigned saturating subtraction on AArch64, reducing instruction count.

GCC can now recognize patterns for unsigned saturating subtraction on AArch64, such as R = X - Y; R > X ? 0 : R. This optimization replaces sequences of three instructions with a single uqsub (unsigned saturating subtract) instruction. The change also removes several expected-failure test cases for these patterns.

In Details

This commit enhances match-sat-alu.pd by adding patterns that identify unsigned saturating subtraction. Unsigned subtraction X - Y saturates to 0 if X < Y (i.e., if the subtraction borrows). The patterns recognize this by checking if the result R is greater than the minuend X, or by comparing R against X. The optimization transforms complex sequences involving comparisons and conditional selections into a single efficient vector saturating subtract instruction on AArch64.

For Context
saturating subtraction
An arithmetic operation where the result is capped at the minimum representable value (zero for unsigned integers) if the true difference falls below it.
unsigned integer
An integer data type that can only represent non-negative values.
AArch64
The 64-bit ARM architecture, commonly used in mobile devices and servers.
match-sat-alu.pd
A GCC machine description file that defines patterns for recognizing and optimizing saturating arithmetic operations on various ALUs.
borrow
In unsigned subtraction, a borrow occurs when the minuend is smaller than the subtrahend, indicating that the result would underflow if not for the unsigned representation's wrap-around behavior.
uqsub
The AArch64 instruction for unsigned saturating subtraction.
Filed Under: optimizationaarch64saturating arithmeticvector