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

Match: Corrected merged patterns for a!=b implying a and b are not zero.

Fixes a bug in pattern matching that caused incorrect boolean results when comparing variables against zero.

This commit fixes an issue in GCC’s pattern matching that caused the wrong constant to be generated for expressions like (a != b) & ((a | b) == 0). The bug was introduced in a previous commit and resulted in swapped true/false values. A new test case ensures this doesn’t regress.

In Details

The match.pd file defines patterns for simplifying expressions during compilation. This commit corrects a mistake in one of these patterns that handle comparisons and bitwise operations, specifically (a !=/== b) &\| ((a|b) ==/!= 0). The fix ensures that the correct constant form is generated, preventing miscompilations. A new test case in gcc.dg/torture/pr125234-1.c validates the fix.

For Context

Pattern matching in compilers helps simplify code by recognizing common expression forms and replacing them with simpler equivalents. This commit fixes a bug in GCC's pattern matching rules, specifically when dealing with comparisons (like a != b) combined with bitwise operations (like a | b). The fix ensures that these expressions are correctly evaluated. The corrected patterns will help reduce the complexity of generated code.

Filed Under: optimizationbugfixpattern matching