From dfb629ace0692d286b9b2ac8fd32fc6d8b5c6123 Mon Sep 17 00:00:00 2001 From: peterino2 Date: Tue, 3 Nov 2026 08:29:20 -0800 Subject: [PATCH] promote: list what has effects once, not every liveness round Liveness runs again each time an empty branch folds (up to 10 rounds on the largest functions), and each round scanned every instruction for the ones with effects. That list does not change between rounds. The hill-climbing set: promotion -16%; output unchanged on the verify corpus. --- src/dxil/promote.zig | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/dxil/promote.zig b/src/dxil/promote.zig index 68ea5c4..1e477ed 100644 --- a/src/dxil/promote.zig +++ b/src/dxil/promote.zig @@ -623,6 +623,9 @@ pub fn run(a: Allocator, m: *module.Module, func: u32, dyn: *const std.AutoHashM // transitively; new phis likewise. (The loads promotion leaves dead, // such as copies of arguments never read, go too.) const live = try a.alloc(bool, n + np); + // (What has effects, worked out once for every round.) + var effects: std.ArrayList(u32) = .empty; + for (insts, 0..) |inst, i| if (!removed[i] and hasEffects(m, inst)) try effects.append(a, @intCast(i)); while (true) { @memset(live, false); { @@ -647,9 +650,9 @@ pub fn run(a: Allocator, m: *module.Module, func: u32, dyn: *const std.AutoHashM } }; var mark: Mark = .{ .repl = repl, .live = live, .removed = removed, .work = &work, .a = a }; - for (insts, 0..) |inst, i| if (!removed[i] and hasEffects(m, inst) and (reach[block_of[i]] or i == block_start[block_of[i] + 1] - 1)) { + for (effects.items) |i| if (reach[block_of[i]] or i == block_start[block_of[i] + 1] - 1) { live[i] = true; - try work.append(a, @intCast(i)); + try work.append(a, i); }; while (work.pop()) |x| { if (x < n) {