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

Match: Simplify patterns for `a != b` implies a or b is non-zero

The compiler's pattern-matching code for simplifying logical expressions is now more concise.

The compiler’s pattern-matching rules for expressions of the form (a != b) &| ((a|b) ==/!= 0) are now defined using a for loop, which simplifies the code and shrinks the generated gimple-match*.cc files by about 300 lines. The c: constraint in the inner ne/eq pattern is now redundant and has been removed.

In Details

This change refactors the pattern matching definitions in match.pd, specifically for expressions involving inequality and bitwise operations. The :c constraint was removed from the inner ne/eq pattern because it duplicates the canonicalization already performed by the bit_ior pattern, reducing code duplication in the generated matchers.

For Context

Compilers use pattern matching to recognize specific code structures and apply optimizations or transformations. This commit simplifies the rules the compiler uses to recognize logical expressions, reducing the size of the generated compiler code. This can make the compiler code easier to maintain and potentially improve compilation speed.

Filed Under: optimizationpattern matchingcode generation