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

match.pd: Fix simplification for bitwise AND and XOR comparison

Corrects a simplification rule for bitwise operations involving equality checks on truth-valued operands.

This commit fixes a miscompilation caused by an incorrect simplification rule in match.pd. The rule (a & b) == (a ^ b) -> !(a | b) was applied too broadly, especially when operands had different types or were not strictly boolean. The fix ensures the simplification correctly handles type conversions and uses bitwise NOT (~) for 1-bit precision types while employing XOR with 1 for wider types, thus preserving correctness.

In Details

The match.pd file contains pattern-matching rules for optimizing expressions. This change corrects a simplification that rewrites (a & b) == (a ^ b) to ~(a | b). The issue arose when operands a and b had different types (e.g., _BitInt(1) vs. int) or were truth-valued but not strictly boolean. The fix now correctly handles type promotion and uses bit_xor with 1 for non-1-bit types, avoiding incorrect bit_not operations.

For Context
match.pd
A file in GCC that defines pattern-matching rules used by the tree-ssa-ccp and other optimization passes to simplify and rewrite expressions.
truth_valued_p
A predicate in GCC that checks if an expression can be evaluated in a boolean context, such as the result of a comparison or a one-bit integer type.
_BitInt(N)
A GCC extension for arbitrary-width integers, where N specifies the number of bits.
bit_not
The bitwise NOT operation (~) which inverts all bits of its operand.
bit_xor
The bitwise XOR operation (^).
Filed Under: compileroptimizationpattern matchingbit-int