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

match-sat-alu.pd: Recognize strict widened unsigned saturation clamps

GCC optimizes unsigned saturating additions where the clamp uses a strict inequality.

GCC’s match-sat-alu.pd pattern matcher now recognizes unsigned saturating additions where the clamping condition uses a strict inequality (< MAX instead of <= MAX). This strict form is equivalent to clamping at MAX - 1 and is now correctly handled, enabling more efficient code generation. An AArch64 example shows a simplification from multiple instructions to a single csinv with a condition code.

In Details

The match-sat-alu.pd pattern now correctly handles widened unsigned saturating additions that employ a strict comparison (e.g., SUM < MAX) for clamping. This strict comparison is semantically equivalent to clamping at MAX - 1 because if SUM == MAX, both arms of the conditional produce MAX. The matcher accepts both MAX and MAX - 1 as the comparison limit. This enhancement improves the optimization of saturation operations, particularly on architectures like AArch64, as illustrated by an example reducing a sequence involving adds and csinv with condition codes.

For Context
unsigned saturating addition
An addition operation where, if the sum exceeds the maximum representable value for the unsigned result type, the result is clamped to that maximum value. This prevents overflow by capping the result.
widened
An operation where the intermediate result is stored in a data type that has more bits (higher precision) than the final result type. This is often done to perform calculations without overflow before clamping or converting to the final narrower type.
strict inequality
A comparison operator that checks if one value is strictly less than (<) or strictly greater than (>) another, excluding equality.
pattern matcher
A component within a compiler that identifies specific sequences of intermediate representation (IR) operations that can be replaced by more efficient instructions or simpler IR forms. This is crucial for optimization.
Filed Under: optimizationgccaarch64