GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
tree-optimization

Tighten matching for unsigned narrow clip patterns.

Refines pattern matching for unsigned integer narrow clips to correctly handle signed comparisons and unsigned right shifts.

This commit improves the unsigned_integer_narrow_clip pattern matching by requiring the comparison to be unsigned and the right shift to be signed. Previously, the pattern incorrectly assumed these conditions, potentially leading to incorrect transformations when a signed comparison preserved negative inputs or an unsigned right shift produced an incorrect result. The change captures both expressions and checks their result types before applying the transform, with new tests covering rejected forms.

In Details

Tightens the unsigned_integer_narrow_clip pattern in match-sat-alu.pd. It now explicitly requires the comparison operand to be unsigned and the right shift operand to be signed. This addresses cases where nop_convert? might not enforce an unsigned conversion and where signed comparisons could lead to negative inputs or where an unsigned right shift would yield 0 or 1 instead of the expected clip value.

For Context
pattern matching
In compilers, a technique used in optimization passes to recognize specific code structures (patterns) in the intermediate representation and replace them with more efficient equivalents.
unsigned integer narrow clip
An operation that takes a wider unsigned integer and converts it to a narrower unsigned integer, clamping the value to the maximum of the narrower type if it exceeds that limit.
intermediate representation
A data structure or code format used internally by a compiler to represent the source code during various stages of translation. Examples include Gimple and RTL in GCC.
Filed Under: optimizationcompiler