From fdece243c0ea5935249b96e88ecc0011a2102497 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Mon, 31 Aug 2026 17:18:54 +0300 Subject: [PATCH] Stop asking one reducibility question with a quadratic dominator table The nesting structurizer decided reducibility from full dominator *sets*: a `BTreeSet` of every dominating block, per block. That is quadratic in the block count, and generated shaders reach block counts where it dominates the whole translation's memory. On an MPS convolution kernel with a 6301-block function it materialized ~40 million set entries -- peak RSS went 85 MB -> 502 MB inside `Graph::is_reducible` alone, and the module then finished at 535 MB, over the 500 MiB per-translation budget that AGENTS.md makes a correctness contract. Replaced it with the Cooper-Harvey-Kennedy immediate-dominator iteration over reverse postorder, numbered into one pre-order interval per block. Dominance is then two integer comparisons, and the structure is linear in the block count. The reducibility walk itself is untouched; only the question's answer moves. Measured on the 21 corpus sources the audit recorded as memory-limit failures, release build, `/usr/bin/time -l`: the 16 that reach the structurizer drop from 509-546 MB to 86-107 MB peak RSS, and are a little faster (2.6-3.0s vs 3.0-3.4s). The other 5 fall back early and are unchanged. Output is byte-identical on all 21, and on a 640-source corpus sample (0 of 640 differ). Two tests. `the_dominator_tree_agrees_with_the_dominator_sets` keeps the dense fixpoint as a test-only reference and cross-checks every ordered block pair on eight graph shapes, including the irreducible ones the verdict exists for. `the_dominator_structure_stays_linear_in_the_block_count` asserts the structure holds one number per reachable block on an 8001-block graph, which is the property that regressed here: the dense form would report n*(n+1)/2. --- src/native/reloop_nest/shape.rs | 326 ++++++++++++++++++++++++++++---- 1 file changed, 294 insertions(+), 32 deletions(-) diff --git a/src/native/reloop_nest/shape.rs b/src/native/reloop_nest/shape.rs index 5f6de1128..fb359427e 100644 --- a/src/native/reloop_nest/shape.rs +++ b/src/native/reloop_nest/shape.rs @@ -113,10 +113,7 @@ impl Graph { stack.push((target, 0)); } // A retreating edge: legal only when the target dominates the source. - 1 if !dominators - .get(&node) - .is_some_and(|doms| doms.contains(&target)) => - { + 1 if !dominators.dominates(target, node) => { return false; } _ => {} @@ -128,43 +125,169 @@ impl Graph { true } - /// Iterative dominator sets over the reachable subgraph. - fn dominators(&self) -> BTreeMap> { - let reachable = self.reachable(); - let mut dominators: BTreeMap> = reachable - .iter() - .map(|label| (*label, reachable.clone())) - .collect(); - if let Some(entry) = dominators.get_mut(&self.entry) { - *entry = BTreeSet::from([self.entry]); + /// The reachable subgraph in reverse postorder, entry first. + /// + /// Reverse postorder is what makes the dominator iteration below converge in a couple of passes + /// instead of one pass per graph depth: every node's predecessors along a forward edge are + /// already final when it is visited. + fn reverse_postorder(&self) -> Vec