https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64084
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Kyrylo Tkachov <[email protected]>: https://gcc.gnu.org/g:8a312e7a448a81d5447729c2743ec7b69b581402 commit r17-4935-g8a312e7a448a81d5447729c2743ec7b69b581402 Author: Kyrylo Tkachov <[email protected]> Date: Mon Oct 5 22:47:09 2026 +0200 genmatch: Relax DT_TRUE ordering barrier in decision_tree::find_node The DT_TRUE merge barrier in find_node prevents a later pattern from merging into an earlier equal sibling when a DT_TRUE node lies between them. The barrier was introduced for PR 64084 (r218141) to preserve source order in cases where multiple patterns can match the same input. Today's match.pd is protected at a finer grain by the gen_kids flush: DT_TRUE and DT_MATCH kids each force a flush of collected alternatives before emitting their own subtrees. The flush guarantees that patterns before a DT_TRUE are tried before patterns after it, so the barrier in find_node is redundant for most cases. The remaining cases where the barrier is necessary are those where an intermediate sibling (between the earlier and later equal nodes) has a DT_MATCH descendant. A DT_MATCH descendant means the sibling's subtree can match any input value, including inputs matched by the later node's subtree. If the later node merged into the earlier one, it would be tried before the DT_MATCH sibling, violating source order for those inputs. When no intermediate sibling has a DT_MATCH descendant, every sibling matches a disjoint set of inputs (since the top-level operand overlap check already ensures no sibling's top-level operation overlaps with p's, and DT_MATCH is the only construct that can widen the match beyond a specific operation). In this case the merge is safe. Replace the unconditional DT_TRUE barrier refusal with a scan of the intermediate siblings: refuse only when at least one non-DT_TRUE sibling between the candidate and the insertion point has a DT_MATCH descendant. This reduces the generated GIMPLE matcher by about 0.4% and the GENERIC matcher by about 0.2%. gcc/ChangeLog: * genmatch.cc (subtree_has_match_p): New function. (decision_tree::find_node): Replace unconditional DT_TRUE barrier with a scan for DT_MATCH descendants in intermediate siblings. Signed-off-by: Kyrylo Tkachov <[email protected]>
