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

genmatch: Share transform copies for non-delayable for-iterators

Optimizes generated code by sharing identical transform results for non-delayable iterators.

This change optimizes the generated code in genmatch by sharing transform copies for non-delayable for-iterators. Previously, even when the result trees were structurally identical, distinct pointers were created, leading to duplicated code generation. By guarding the copy operation and checking for iterator references, identical results are now shared, reducing the generated GIMPLE and GENERIC matcher size. A fix for contains_id ensures correct tracking of captures in C expressions.

In Details

The genmatch pass optimizes pattern matching by generating C code. For non-delayable for loops, it previously created distinct copies of the result tree for each operator, even if structurally identical. This commit modifies genmatch.cc to share these identical results when the iterator is not referenced in the result, preventing redundant code generation. This optimization is particularly relevant for match.pd, which mixes tcc_binary and tcc_comparison codes, blocking delayed substitution. Additionally, contains_id was fixed to correctly scan CPP_NAME tokens in C expressions, n…

For Context
genmatch
A GCC pass that generates C code for pattern matching, used for optimizing specific code structures.
non-delayable for-iterator
An iterator in a loop construct where substitutions cannot be deferred, requiring immediate processing.
GIMPLE
GCC's internal representation of code, used between the front-end and the optimizer.
GENERIC
An intermediate representation in GCC, representing code in a high-level, tree-based format.
CPP_NAME
A token representing an identifier in the C preprocessor's output.
Filed Under: optimizationgenmatch