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

match.pd: Add patterns for (X ^ Y) & (X | Y) simplification.

New match.pd patterns simplify bitwise XOR and AND operations, particularly for boolean logic.

Several new patterns have been added to match.pd to simplify bitwise operations. The patterns (X ^ Y) & (X | Y) and its variants for boolean logic (using NE instead of XOR) are now simplified to X ^ Y (or X NE Y). This optimization is based on the principle that if X != Y, then X ^ Y is true, and X | Y will also be true if either X or Y is true. The patterns also handle chained bitwise ORs.

In Details

This commit adds new GIMPLE-level match.pd patterns to simplify expressions involving bitwise XOR (^), bitwise OR (|), and bitwise AND (&). Specifically, it targets the simplification of (X ^ Y) & (X | Y) to X ^ Y, and (X NE Y) & (X | Y) to X NE Y. It also handles cases with chained ORs, such as (X ^ Y) & (Z | X | Y). These patterns leverage the fact that if X != Y, then X ^ Y implies X | Y (unless Z affects it, but the structure of the pattern handles that). The patterns are applied at the GIMPLE level.

For Context
match.pd
A file within GCC that defines pattern-matching rules for simplifying intermediate representations of the code.
GIMPLE
GNU Intermediate Representation Form for Expressions, a higher-level, three-address-code intermediate representation used in GCC for optimizations.
XOR
Exclusive OR, a bitwise logical operation that outputs true only when inputs differ.
bitwise AND
A bitwise logical operation that outputs true only if both corresponding bits of the operands are true.
bitwise OR
A bitwise logical operation that outputs true if at least one of the corresponding bits of the operands is true.
Filed Under: optimizationbitwisematch.pd