From d0b35fa5aa98296cbf8ba476b2fcb8c9e07ff19f Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Wed, 25 Nov 2026 23:10:34 -0600 Subject: [PATCH] Do not restart the blockparam_ins walk for every block of a range apply_allocations_and_insert_moves walks blockparam_ins, sorted by (to_vreg, to_block), once for every block whose entry a live range covers, and each of those walks started again from the cursor buffered for the range. Ranges of one vreg can overlap, so the cursor must be re-read per range, but within one range blocks are visited in increasing order: everything a walk steps over is below the key of every later block and cannot match it. Restarting per block therefore only repeated work: a block parameter with T predecessors that stays live across B later blocks cost T * B steps, and L such parameters L * T * B. With two merge points of T edges in one function, B is T for the parameters of the first. Carry the walk's position from block to block within a range. The entries collected and the cursor value handed to PrevBuffer are the same in every case, including the case in which the buffered cursor has already passed a block's entries, so the output is unchanged. #281 removed the other half of the problem, the cursor that a vreg with a single range left behind for all later vregs. With both, the walk is linear in the number of entries plus the number of (range, block) pairs. Co-Authored-By: Claude Fable 5.2 --- src/ion/moves.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ion/moves.rs b/src/ion/moves.rs index ccac1f0c..a1a0ff28 100644 --- a/src/ion/moves.rs +++ b/src/ion/moves.rs @@ -479,6 +479,17 @@ impl<'a, F: Function> Env<'a, F> { if self.cfginfo.block_entry[block.index()] < range.from { block = block.next(); } + // The walk of `blockparam_ins` starts from the buffered + // cursor once per range: ranges of one vreg can overlap, so + // a later range may need entries that an earlier one already + // passed. It must not start again for every block of the + // range, though. Blocks are visited in increasing order and + // the entries are sorted by (vreg, block), so everything the + // walk for one block steps over is below the key of every + // later block and cannot match it; starting again only + // rescans this vreg's entries once per block the range + // covers. + let mut idx = prev.blockparam_ins_idx(); while block.is_valid() && block.index() < self.func.num_blocks() { if self.cfginfo.block_entry[block.index()] >= range.to { break; @@ -489,9 +500,8 @@ impl<'a, F: Function> Env<'a, F> { "scanning blockparam_ins at vreg {} block {}: blockparam_in_idx = {}", vreg.index(), block.index(), - prev.prev_ins_idx, + idx, ); - let mut idx = prev.blockparam_ins_idx(); while idx < self.blockparam_ins.len() { let BlockparamIn { from_block,