GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
match.pd Performance Win

match.pd: Add rule for masked OR comparisons.

Adds a new pattern matching rule for optimizing masked OR comparisons.

This commit introduces a new optimization rule to GCC’s pattern matching system (match.pd) for simplifying masked OR comparisons. It addresses the dual of an existing rule: (X | C) == (Y | C) now folds to ((X ^ Y) & C) == 0. This optimization is demonstrated with an example of case-insensitive ASCII comparison, allowing for more efficient code generation on architectures like aarch64.

In Details

Adds a new simplification rule to match.pd: (X | C) ==/!= (Y | C) now simplifies to ((X ^ Y) & C) == 0. This is the dual of the existing (X & C) == (Y & C) rule. The rule is placed alongside its bit_and dual within the eq and ne iterators. Tested on aarch64-none-linux-gnu.

For Context
match.pd
A file in GCC containing pattern-matching rules used for instruction selection and optimization. It defines how to recognize and transform specific code patterns.
masked OR comparison
A comparison operation where two values are first bitwise ORed with a mask constant, and then the results are compared for equality or inequality.
dual
In this context, the dual refers to a complementary mathematical or logical operation. If a rule applies to AND, its dual might apply to OR, XOR, etc.
aarch64
The 64-bit ARM architecture. Compilers generate code specifically optimized for this processor family.
XOR
Exclusive OR. A bitwise logical operation that outputs true only when inputs differ.
TST
Test bits. An instruction that performs a bitwise AND between a register and an immediate value, and sets the condition flags based on the result.
Filed Under: optimizationmatch.pdpattern matchingaarch64