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

genmatch: Relaxed ordering barrier for GIMPLE/GENERIC pairs

Reduces redundant ordering barriers in pattern matching, improving generated code size.

This commit relaxes an ordering barrier in GCC’s pattern matching system, specifically for pairs of GIMPLE and GENERIC code forms. Previously, the system prevented later patterns from merging with earlier ones if a specific blocking node existed between them. This was often redundant when matching GIMPLE and GENERIC forms derived from the same source construct, as they cannot match the same input simultaneously. The change makes the matching more efficient, reducing the size of generated matchers.

In Details

The nodes_overlap_p function in genmatch.cc previously returned true for any two DT_OPERAND nodes whose operand cases overlapped, setting an overlap_node barrier in decision_tree::find_node. This blocked later nodes from merging with earlier siblings. Of the barrier refusals, 83% involved GIMPLE and GENERIC forms of COND_EXPR conditions, which have distinct dispatch mechanisms (SSA_NAME vs. TREE_CODE) and thus cannot match the same input. The patch modifies nodes_overlap_p to return false when is_generic differs between nodes, eliminating these spurious GIMPLE/GENERIC overlaps…

For Context
genmatch
The GCC component responsible for generating efficient pattern matching code. It compiles a set of rules (patterns) into a decision tree or similar structure to quickly identify matching code sequences.
GIMPLE
GCC's internal three-address code representation. It's a simplified form of Abstract Syntax Tree (AST) designed for easier optimization passes.
GENERIC
An intermediate representation in GCC that is higher-level than GIMPLE and closer to the original source code structure. It serves as a common representation before lowering to GIMPLE.
Decision Tree (DT)
A data structure used by genmatch to represent pattern matching logic. Nodes in the tree represent conditions or operations, guiding the matcher to the appropriate pattern.
Ordering barrier
A mechanism in genmatch that prevents certain patterns from being reordered or merged, typically to preserve the source code order of equally matching patterns.
Filed Under: genmatchoptimizationcode generationperformance