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

Correct signed saturating add pattern for X + IMM

Fixes incorrect folding of signed saturating add operations involving immediate values.

A pattern in match-sat-alu.pd that folds signed saturating additions of a register to an immediate value has been corrected. The previous check for operand signs was too permissive, leading to incorrect results for certain inputs, notably with the vectorizer. The fix ensures the pattern correctly identifies when the immediate value has the opposite sign of the register operand’s sign bit, preventing incorrect saturations.

In Details

The signed_integer_sat_add pattern in match-sat-alu.pd incorrectly folded T SUM = (T)((UT)X + (UT)IMM) when (X ^ SUM) & (X ^ C3) < 0. This condition was meant to check if X and IMM have opposite signs, but the C3 == ~IMM equality was insufficient. The fix replaces it with a direct comparison of the sign bits of the two constants, improving correctness for saturating add operations and fixing issues in the vectorizer.

For Context
signed saturating add
An arithmetic operation that adds two signed numbers. If the result exceeds the maximum representable value for the type, it is clamped to the maximum; if it falls below the minimum, it is clamped to the minimum. This is also known as saturation arithmetic.
vectorizer
A compiler component that transforms code to use SIMD (Single Instruction, Multiple Data) instructions, allowing a single operation to be performed on multiple data elements simultaneously for performance gains.
immediate value
A constant value embedded directly within an instruction, rather than being fetched from memory or a register.
Filed Under: optimizationRISC-Vbugfix