From 7628d6c17e9186334b2b2bb24664dacdaa870403 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Mon, 16 Nov 2026 14:40:12 -0800 Subject: [PATCH] Only construct the dominator tree when checking SSA validity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The main register allocator doesn't use the dominator tree, and the SSA checker is disabled in production builds, so it was just wasted time. Shaves off about 0.14% of instructions retired during compilation: ``` compilation :: instructions-retired :: Geomean (29 benchmarks) 9d0fee7.dylib is 1.000x to 1.002x faster than 4a23344.dylib! (confidence = 99%, df = 819.5) ┌──────────────┬────────────┬───────────────┐ │ Geomean │ Benchmarks │ Engine │ ├──────────────┼────────────┼───────────────┤ │ 661861003.51 │ 29 │ 4a23344.dylib │ ├──────────────┼────────────┼───────────────┤ │ 660930660.88 │ 29 │ 9d0fee7.dylib │ └──────────────┴────────────┴───────────────┘ compilation :: instructions-retired :: shootout-heapsort 4a23344.dylib is 1.00x to 1.01x faster than 9d0fee7.dylib! (confidence = 99%, p = 0.0077) ┌───────────┬───────────┬──────────────┬──────────────┬────────┬───────────────┐ │ Min │ Max │ Mean │ Median │ Noise │ Engine │ ├───────────┼───────────┼──────────────┼──────────────┼────────┼───────────────┤ │ 112120411 │ 130453005 │ 125694766.04 │ 126015950.00 │ 1.593% │ 4a23344.dylib │ ├───────────┼───────────┼──────────────┼──────────────┼────────┼───────────────┤ │ 120388317 │ 131388733 │ 126634770.99 │ 126564898.00 │ 2.265% │ 9d0fee7.dylib │ └───────────┴───────────┴──────────────┴──────────────┴────────┴───────────────┘ compilation :: instructions-retired :: tinygo-regex 9d0fee7.dylib is 1.004x to 1.005x faster than 4a23344.dylib! (confidence = 99%, p < 0.0001) ┌────────────┬────────────┬───────────────┬───────────────┬────────┬───────────────┐ │ Min │ Max │ Mean │ Median │ Noise │ Engine │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 4052443891 │ 4067496012 │ 4060385228.30 │ 4060876340.50 │ 0.098% │ 4a23344.dylib │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 4036248826 │ 4052507891 │ 4042116005.08 │ 4042245702.00 │ 0.082% │ 9d0fee7.dylib │ └────────────┴────────────┴───────────────┴───────────────┴────────┴───────────────┘ compilation :: instructions-retired :: starlingmonkey-markdown 9d0fee7.dylib is 1.0037x to 1.0041x faster than 4a23344.dylib! (confidence = 99%, p < 0.0001) ┌─────────────┬─────────────┬────────────────┬────────────────┬────────┬───────────────┐ │ Min │ Max │ Mean │ Median │ Noise │ Engine │ ├─────────────┼─────────────┼────────────────┼────────────────┼────────┼───────────────┤ │ 66128551388 │ 66287952618 │ 66182121967.53 │ 66178815859.50 │ 0.069% │ 4a23344.dylib │ ├─────────────┼─────────────┼────────────────┼────────────────┼────────┼───────────────┤ │ 65849458708 │ 66096989674 │ 65928855710.54 │ 65922524250.00 │ 0.062% │ 9d0fee7.dylib │ └─────────────┴─────────────┴────────────────┴────────────────┴────────┴───────────────┘ compilation :: instructions-retired :: rust-json 9d0fee7.dylib is 1.002x to 1.004x faster than 4a23344.dylib! (confidence = 99%, p < 0.0001) ┌────────────┬────────────┬───────────────┬───────────────┬────────┬───────────────┐ │ Min │ Max │ Mean │ Median │ Noise │ Engine │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 1217653389 │ 1230541220 │ 1224535437.56 │ 1224666828.50 │ 0.338% │ 4a23344.dylib │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 1200776717 │ 1226153585 │ 1220094095.46 │ 1220115220.50 │ 0.338% │ 9d0fee7.dylib │ └────────────┴────────────┴───────────────┴───────────────┴────────┴───────────────┘ compilation :: instructions-retired :: dotnet-raytracer 9d0fee7.dylib is 1.003x to 1.004x faster than 4a23344.dylib! (confidence = 99%, p < 0.0001) ┌────────────┬────────────┬───────────────┬───────────────┬────────┬───────────────┐ │ Min │ Max │ Mean │ Median │ Noise │ Engine │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 6193459829 │ 6226656835 │ 6207051639.77 │ 6206444663.00 │ 0.126% │ 4a23344.dylib │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 6171528190 │ 6207802033 │ 6186007207.79 │ 6185075048.00 │ 0.090% │ 9d0fee7.dylib │ └────────────┴────────────┴───────────────┴───────────────┴────────┴───────────────┘ compilation :: instructions-retired :: gcc-loops 9d0fee7.dylib is 1.003x to 1.004x faster than 4a23344.dylib! (confidence = 99%, p < 0.0001) ┌────────────┬────────────┬───────────────┬───────────────┬────────┬───────────────┐ │ Min │ Max │ Mean │ Median │ Noise │ Engine │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 2017725378 │ 2034514101 │ 2025481702.64 │ 2025283779.00 │ 0.173% │ 4a23344.dylib │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 2007939455 │ 2034934997 │ 2018596759.86 │ 2018717487.50 │ 0.196% │ 9d0fee7.dylib │ └────────────┴────────────┴───────────────┴───────────────┴────────┴───────────────┘ compilation :: instructions-retired :: rust-protobuf 9d0fee7.dylib is 1.002x to 1.004x faster than 4a23344.dylib! (confidence = 99%, p < 0.0001) ┌───────────┬───────────┬──────────────┬──────────────┬────────┬───────────────┐ │ Min │ Max │ Mean │ Median │ Noise │ Engine │ ├───────────┼───────────┼──────────────┼──────────────┼────────┼───────────────┤ │ 766481653 │ 777768012 │ 772164790.05 │ 772594597.50 │ 0.403% │ 4a23344.dylib │ ├───────────┼───────────┼──────────────┼──────────────┼────────┼───────────────┤ │ 759209188 │ 776747005 │ 769670824.17 │ 770108035.00 │ 0.447% │ 9d0fee7.dylib │ └───────────┴───────────┴──────────────┴──────────────┴────────┴───────────────┘ compilation :: instructions-retired :: intgemm-simd 9d0fee7.dylib is 1.002x to 1.004x faster than 4a23344.dylib! (confidence = 99%, p < 0.0001) ┌────────────┬────────────┬───────────────┬───────────────┬────────┬───────────────┐ │ Min │ Max │ Mean │ Median │ Noise │ Engine │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 1982691763 │ 2007989887 │ 1996724276.07 │ 1996557179.00 │ 0.198% │ 4a23344.dylib │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 1980070014 │ 1998879426 │ 1990695389.68 │ 1990936973.50 │ 0.198% │ 9d0fee7.dylib │ └────────────┴────────────┴───────────────┴───────────────┴────────┴───────────────┘ compilation :: instructions-retired :: hex-simd 9d0fee7.dylib is 1.001x to 1.005x faster than 4a23344.dylib! (confidence = 99%, p < 0.0001) ┌───────────┬───────────┬──────────────┬──────────────┬────────┬───────────────┐ │ Min │ Max │ Mean │ Median │ Noise │ Engine │ ├───────────┼───────────┼──────────────┼──────────────┼────────┼───────────────┤ │ 531962727 │ 552672245 │ 545466041.03 │ 545437207.00 │ 0.614% │ 4a23344.dylib │ ├───────────┼───────────┼──────────────┼──────────────┼────────┼───────────────┤ │ 535691184 │ 551771398 │ 543912053.73 │ 544017258.00 │ 0.662% │ 9d0fee7.dylib │ └───────────┴───────────┴──────────────┴──────────────┴────────┴───────────────┘ compilation :: instructions-retired :: rust-wasmprinter 9d0fee7.dylib is 1.002x to 1.003x faster than 4a23344.dylib! (confidence = 99%, p < 0.0001) ┌────────────┬────────────┬───────────────┬───────────────┬────────┬───────────────┐ │ Min │ Max │ Mean │ Median │ Noise │ Engine │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 2928034965 │ 2945844894 │ 2935849750.79 │ 2935780208.00 │ 0.148% │ 4a23344.dylib │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 2918587193 │ 2957085158 │ 2928239327.50 │ 2928151080.50 │ 0.155% │ 9d0fee7.dylib │ └────────────┴────────────┴───────────────┴───────────────┴────────┴───────────────┘ compilation :: instructions-retired :: shootout-switch 9d0fee7.dylib is 1.002x to 1.003x faster than 4a23344.dylib! (confidence = 99%, p < 0.0001) ┌────────────┬────────────┬───────────────┬───────────────┬────────┬───────────────┐ │ Min │ Max │ Mean │ Median │ Noise │ Engine │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 1126537545 │ 1137022260 │ 1131802975.37 │ 1131870984.00 │ 0.194% │ 4a23344.dylib │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 1116731069 │ 1134119868 │ 1128704378.27 │ 1128958340.50 │ 0.282% │ 9d0fee7.dylib │ └────────────┴────────────┴───────────────┴───────────────┴────────┴───────────────┘ compilation :: instructions-retired :: libsodium-core5 9d0fee7.dylib is 1.000x to 1.004x faster than 4a23344.dylib! (confidence = 99%, p = 0.0041) ┌───────────┬───────────┬──────────────┬──────────────┬────────┬───────────────┐ │ Min │ Max │ Mean │ Median │ Noise │ Engine │ ├───────────┼───────────┼──────────────┼──────────────┼────────┼───────────────┤ │ 327237638 │ 340424928 │ 335944946.02 │ 335934594.50 │ 0.666% │ 4a23344.dylib │ ├───────────┼───────────┼──────────────┼──────────────┼────────┼───────────────┤ │ 326843319 │ 340553848 │ 335162860.87 │ 335213304.50 │ 0.597% │ 9d0fee7.dylib │ └───────────┴───────────┴──────────────┴──────────────┴────────┴───────────────┘ compilation :: instructions-retired :: kotlin-richards 9d0fee7.dylib is 1.000x to 1.004x faster than 4a23344.dylib! (confidence = 99%, p = 0.0013) ┌───────────┬───────────┬──────────────┬──────────────┬────────┬───────────────┐ │ Min │ Max │ Mean │ Median │ Noise │ Engine │ ├───────────┼───────────┼──────────────┼──────────────┼────────┼───────────────┤ │ 645075719 │ 662147732 │ 654550334.75 │ 654586490.50 │ 0.550% │ 4a23344.dylib │ ├───────────┼───────────┼──────────────┼──────────────┼────────┼───────────────┤ │ 630536513 │ 659642627 │ 652892861.36 │ 653537204.00 │ 0.625% │ 9d0fee7.dylib │ └───────────┴───────────┴──────────────┴──────────────┴────────┴───────────────┘ compilation :: instructions-retired :: dart-deltablue 9d0fee7.dylib is 1.000x to 1.004x faster than 4a23344.dylib! (confidence = 99%, p = 0.0045) ┌───────────┬───────────┬──────────────┬──────────────┬────────┬───────────────┐ │ Min │ Max │ Mean │ Median │ Noise │ Engine │ ├───────────┼───────────┼──────────────┼──────────────┼────────┼───────────────┤ │ 596084808 │ 623681992 │ 616472098.01 │ 616700644.00 │ 0.568% │ 4a23344.dylib │ ├───────────┼───────────┼──────────────┼──────────────┼────────┼───────────────┤ │ 600586958 │ 621317173 │ 615210086.13 │ 615635545.50 │ 0.591% │ 9d0fee7.dylib │ └───────────┴───────────┴──────────────┴──────────────┴────────┴───────────────┘ compilation :: instructions-retired :: ocaml-raytrace 9d0fee7.dylib is 1.001x to 1.002x faster than 4a23344.dylib! (confidence = 99%, p < 0.0001) ┌────────────┬────────────┬───────────────┬───────────────┬────────┬───────────────┐ │ Min │ Max │ Mean │ Median │ Noise │ Engine │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 1372173646 │ 1395321230 │ 1387522612.36 │ 1387774163.50 │ 0.319% │ 4a23344.dylib │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 1376303637 │ 1392595615 │ 1385395544.69 │ 1385812148.00 │ 0.253% │ 9d0fee7.dylib │ └────────────┴────────────┴───────────────┴───────────────┴────────┴───────────────┘ compilation :: instructions-retired :: hoot-earley-boyer 9d0fee7.dylib is 1.001x to 1.002x faster than 4a23344.dylib! (confidence = 99%, p < 0.0001) ┌────────────┬────────────┬───────────────┬───────────────┬────────┬───────────────┐ │ Min │ Max │ Mean │ Median │ Noise │ Engine │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 7658560003 │ 7690078983 │ 7672411232.99 │ 7671258383.50 │ 0.103% │ 4a23344.dylib │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 7636094862 │ 7692713447 │ 7661145078.25 │ 7661405196.00 │ 0.065% │ 9d0fee7.dylib │ └────────────┴────────────┴───────────────┴───────────────┴────────┴───────────────┘ compilation :: instructions-retired :: hashset 9d0fee7.dylib is 1.000x to 1.002x faster than 4a23344.dylib! (confidence = 99%, p = 0.0010) ┌────────────┬────────────┬───────────────┬───────────────┬────────┬───────────────┐ │ Min │ Max │ Mean │ Median │ Noise │ Engine │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 1496449645 │ 1509042667 │ 1503476034.31 │ 1503397040.50 │ 0.259% │ 4a23344.dylib │ ├────────────┼────────────┼───────────────┼───────────────┼────────┼───────────────┤ │ 1494184697 │ 1507302843 │ 1502046203.90 │ 1501921235.00 │ 0.241% │ 9d0fee7.dylib │ └────────────┴────────────┴───────────────┴───────────────┴────────┴───────────────┘ ``` --- src/cfg.rs | 18 +----------------- src/ssa.rs | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/cfg.rs b/src/cfg.rs index 5b125f71..499ab835 100644 --- a/src/cfg.rs +++ b/src/cfg.rs @@ -7,13 +7,12 @@ use crate::alloc::vec::Vec; -use crate::{domtree, postorder, Block, Function, Inst, ProgPoint, RegAllocError, VecExt}; +use crate::{postorder, Block, Function, Inst, ProgPoint, RegAllocError, VecExt}; use smallvec::{smallvec, SmallVec}; #[derive(Debug, Default)] pub struct CFGInfoCtx { visited: Vec, - block_to_rpo: Vec>, backedge: Vec, } @@ -21,8 +20,6 @@ pub struct CFGInfoCtx { pub struct CFGInfo { /// Postorder traversal of blocks. pub postorder: Vec, - /// Domtree parents, indexed by block. - pub domtree: Vec, /// For each instruction, the block it belongs to. pub insn_block: Vec, /// For each block, the first instruction. @@ -58,15 +55,6 @@ impl CFGInfo { |block| f.block_succs(block), )?; - domtree::calculate( - nb, - |block| f.block_preds(block), - &self.postorder, - &mut ctx.block_to_rpo, - &mut self.domtree, - f.entry_block(), - ); - let insn_block = self.insn_block.repopulate(f.num_insts(), Block::invalid()); let block_entry = self .block_entry @@ -148,8 +136,4 @@ impl CFGInfo { Ok(()) } - - pub fn dominates(&self, a: Block, b: Block) -> bool { - domtree::dominates(&self.domtree[..], a, b) - } } diff --git a/src/ssa.rs b/src/ssa.rs index 29a82cfe..23a788d6 100644 --- a/src/ssa.rs +++ b/src/ssa.rs @@ -8,9 +8,19 @@ use alloc::vec; use crate::cfg::CFGInfo; -use crate::{Block, Function, FxHashSet, Inst, OperandKind, RegAllocError, VReg}; +use crate::{domtree, Block, Function, FxHashSet, Inst, OperandKind, RegAllocError, VReg}; pub fn validate_ssa(f: &F, cfginfo: &CFGInfo) -> Result<(), RegAllocError> { + let mut idom = vec![]; + domtree::calculate( + f.num_blocks(), + |block| f.block_preds(block), + &cfginfo.postorder, + &mut vec![], + &mut idom, + f.entry_block(), + ); + // For every block param and inst def, check that this is the only def. let mut defined_in = vec![Block::invalid(); f.num_vregs()]; for block in 0..f.num_blocks() { @@ -66,7 +76,7 @@ pub fn validate_ssa(f: &F, cfginfo: &CFGInfo) -> Result<(), RegAllo && if def_block == block { local.contains(&operand.vreg()) } else { - cfginfo.dominates(def_block, block) + domtree::dominates(&idom, def_block, block) }; if !okay { trace!("Invalid use {:?}", operand.vreg());