GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
match

Match: Reject non-integral types in `(smaller)a ==/!= (smaller) b` pattern.

The compiler avoids generating invalid GIMPLE when comparing pointers cast to smaller integer types.

The compiler’s pattern matching logic now rejects attempts to compare pointers cast to smaller integer types using equality or inequality operators. Previously, this could lead to invalid GIMPLE (the compiler’s intermediate representation) due to the unexpected operation of ptr ^ ptr. This fix avoids an invalid operation and ensures proper code generation.

In Details

The match.pd file defines patterns used during GIMPLE simplification. The pattern (smaller)a ==/!= (smaller) b was matching pointer comparisons after a cast to a smaller integer type, which resulted in ptr ^ ptr in GIMPLE. This commit adds a type check to ensure only integral types are considered, preventing invalid GIMPLE. This avoids a miscompilation.

For Context

The compiler uses pattern matching to simplify code during compilation. This optimization pass looks for opportunities to rewrite certain code patterns into more efficient or canonical forms. This commit fixes a flaw in one of these patterns that could lead to incorrect code generation when comparing pointers that have been converted to smaller integer types.

Filed Under: optimizationgimplebugfix