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

genmatch: Avoid replicating patterns over unused for-iterators.

Pattern matching generator avoids redundant pattern replication for unused loop variables.

The genmatch tool now prevents redundant replication of patterns that do not use any iterators from enclosing for loops. Previously, if a pattern’s match or result did not reference any for loop variables, the pattern would be instantiated multiple times unnecessarily, creating dead code in the decision tree. This change adds a check to detect such unused iterators, issues a diagnostic, and emits only a single copy of the pattern, improving the efficiency of pattern generation and reducing decision tree size.

In Details

The genmatch utility's lower_for function has been enhanced to avoid redundant pattern replication when the pattern's match or result does not depend on the for-level iterators. If a pattern does not reference any iterator IDs from the current for-level, all substituted copies of that pattern become structurally identical, leading to dead leaves in the generated decision tree. This commit introduces a check before operator substitution to see if any for-level iterator IDs appear in the pattern's match or result. If not, it emits a diagnostic and proceeds with only a single substitut…

For Context
genmatch
A tool used within GCC to generate pattern matching code. It takes definitions of patterns and transforms them into efficient decision trees for matching specific RTL or GIMPLE constructs.
Pattern Matching
A technique used in compilers to identify specific code structures or sequences. It's fundamental for optimizations like instruction selection and code generation.
RTL
Register Transfer Language. An intermediate representation used by GCC to represent code before it is translated into machine code.
Decision Tree
A data structure generated by pattern matching tools like genmatch. It represents a series of choices to efficiently determine if a given piece of code matches a defined pattern.
Iterator
In this context, a variable or symbol within a for loop construct in genmatch's definition language that represents the current element or index being processed.
Filed Under: genmatchpattern matchingoptimization