unroll: a loop's blocks in order from its bits, not a sort

Each loop's block list was sorted after the walk that found its blocks,
for every loop on each of unrollOne's calls (230 calls of about 200
loops on 00828). The body's bitset already holds them in order: they
are read out of its words.

The hill-climbing set: -8.1% (A/B); output unchanged on the verify
corpus.
This commit is contained in:
peterino2 2026-11-03 11:05:35 -08:00
parent 9bb4feb32b
commit 35dedc171e
1 changed files with 13 additions and 5 deletions

View File

@ -373,20 +373,28 @@ fn unrollOne(a: Allocator, m: *module.Module, func: u32, budget: *usize, tried:
if (latches.items.len == 0) continue; if (latches.items.len == 0) continue;
const bits = try a.alloc(u64, (nb + 63) / 64); const bits = try a.alloc(u64, (nb + 63) / 64);
@memset(bits, 0); @memset(bits, 0);
var blocks: std.ArrayList(u32) = .empty;
var body: Body = .{ .bits = bits, .blocks = &.{} }; var body: Body = .{ .bits = bits, .blocks = &.{} };
body.add(h); body.add(h);
try blocks.append(a, h); var count: usize = 1;
var stack: std.ArrayList(u32) = .empty; var stack: std.ArrayList(u32) = .empty;
try stack.appendSlice(a, latches.items); try stack.appendSlice(a, latches.items);
while (stack.pop()) |x| { while (stack.pop()) |x| {
if (body.has(x)) continue; if (body.has(x)) continue;
body.add(x); body.add(x);
try blocks.append(a, x); count += 1;
for (cfg.preds[x]) |p| if (cfg.idom[p] != none) try stack.append(a, p); for (cfg.preds[x]) |p| if (cfg.idom[p] != none) try stack.append(a, p);
} }
std.sort.pdq(u32, blocks.items, {}, std.sort.asc(u32)); // The blocks in order, from the bits.
body.blocks = blocks.items; const blocks = try a.alloc(u32, count);
var k: usize = 0;
for (bits, 0..) |word, wi| {
var w = word;
while (w != 0) : (w &= w - 1) {
blocks[k] = @intCast(wi * 64 + @ctz(w));
k += 1;
}
}
body.blocks = blocks;
try loops.append(a, .{ .h = h, .body = body, .latches = latches.items }); try loops.append(a, .{ .h = h, .body = body, .latches = latches.items });
} }