GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
gcc/match

Fix match pattern for `((a ^ b) & c) cmp d || a != b`

Improved pattern matching for logical operations to correctly handle non-short-circuiting evaluation.

This commit refactors a pattern matching rule in GCC’s match.pd to correctly handle logical operations when short-circuiting is disabled. It specifically addresses the ((a ^ b) & c) cmp d || a != b construct by adding support for the && (AND) case, which simplifies to !(((a ^ b) & c) cmp d || a != b), and also fixes operand constraints.

In Details

The match.pd file, which defines patterns for optimization transformations, has been updated to correctly handle logical operations when the --param=logical-op-non-short-circuit=0 flag is used. This commit fixes a pattern that was not correctly folding for the || (OR) case and adds support for the equivalent && (AND) case by introducing a bit_and pattern. It also corrects the placement of :c constraints on operands within the pattern definitions.

For Context
match.pd
A file in GCC that defines pattern matching rules used by the compiler's optimization passes, particularly for simplifying and transforming expressions.
logical-op-non-short-circuit
A GCC parameter that controls whether logical operators (&&, ||) are evaluated using short-circuiting rules. When disabled (set to 0), the right-hand operand is always evaluated, regardless of the left-hand operand's value.
Pattern matching
A compiler technique where specific code structures or expressions are identified and replaced with equivalent, often more efficient, forms.
:c constraint
A constraint used in GCC's pattern matching to indicate that the order of operands for a particular operator should be preserved or that a comparison is involved.
Filed Under: optimizationpattern matchinggcctree-ssa