genmatch: Relax DT_TRUE ordering barrier for improved pattern merging
Reduces redundant ordering barriers in pattern matching, improving generated code size and efficiency.
This commit modifies GCC’s pattern matching generator (genmatch) to relax a specific ordering barrier related to DT_TRUE nodes. The barrier was preventing efficient merging of patterns when a DT_TRUE node separated them, even if the patterns didn’t truly depend on strict ordering. The change now only enforces the barrier when necessary to maintain source order, specifically when an intermediate sibling has a DT_MATCH descendant. This optimization reduces the size of generated GIMPLE and GENERIC matchers.
In Details
In genmatch.cc, decision_tree::find_node's unconditional DT_TRUE merge barrier (introduced for PR 64084) is replaced. The barrier prevented merging later equal siblings into earlier ones if a DT_TRUE node was between them. This was intended to preserve source order. However, with finer-grained flushing mechanisms (DT_TRUE and DT_MATCH kids force flushes), the barrier is often redundant. The new logic replaces it with a scan of intermediate siblings: the barrier is only enforced if a non-DT_TRUE sibling between the candidate and insertion point has a DT_MATCH descendant. This r…
- 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.
- Decision Tree (DT)
- A data structure used by
genmatchto represent pattern matching logic. Nodes in the tree represent conditions or operations, guiding the matcher to the appropriate pattern. - DT_TRUE
- A specific type of node within a
genmatchdecision tree, often representing a true branch or a condition that is always met. - DT_MATCH
- A node type in
genmatchdecision trees that can match any input value, effectively widening the scope of a pattern match. - Ordering barrier
- A mechanism in
genmatchthat prevents certain patterns from being reordered or merged, typically to preserve the source code order of equally matching patterns.