Skip to content

Commit b35acdb

Browse files
committed
Heuristic improvement: reg-scan offset by inst location.
We currently use a heuristic that our scan for an available PReg starts at an index into the register list that rotates with the bundle index. This is a simple way to distribute contention across the whole register file more evenly and avoid repeating less-likely-to-succeed reg-map probes to lower-numbered registers for every bundle. After some experimentation with different options (queue that dynamically puts registers at end after allocating, various ways of mixing/hashing indices, etc.), adding the *instruction offset* (of the start of the first range in the bundle) as well gave the best results. This is very simple and gives us a likely better-than-random conflict avoidance because ranges tend to be local, so rotating through registers as we scan down the list of instructions seems like a very natural strategy. On the tests used by our `cargo bench` benchmark, this reduces regfile probes for the largest (459 instruction) benchmark from 1538 to 829, i.e., approximately by half, and results in an 11% allocation speedup.
1 parent 8e923b0 commit b35acdb

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/ion/mod.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -2570,6 +2570,17 @@ impl<'a, F: Function> Env<'a, F> {
25702570
} else {
25712571
n_regs
25722572
};
2573+
// Heuristic: start the scan for an available
2574+
// register at an offset influenced both by our
2575+
// location in the code and by the bundle we're
2576+
// considering. This has the effect of spreading
2577+
// demand more evenly across registers.
2578+
let scan_offset = self.ranges[self.bundles[bundle.index()].first_range.index()]
2579+
.range
2580+
.from
2581+
.inst
2582+
.index()
2583+
+ bundle.index();
25732584
for i in 0..loop_count {
25742585
// The order in which we try registers is somewhat complex:
25752586
// - First, if there is a hint, we try that.
@@ -2587,15 +2598,15 @@ impl<'a, F: Function> Env<'a, F> {
25872598
(0, Some(hint_reg)) => hint_reg,
25882599
(i, Some(hint_reg)) => {
25892600
let reg = self.env.regs_by_class[class as u8 as usize]
2590-
[(i - 1 + bundle.index()) % n_regs];
2601+
[(i - 1 + scan_offset) % n_regs];
25912602
if reg == hint_reg {
25922603
continue;
25932604
}
25942605
reg
25952606
}
25962607
(i, None) => {
25972608
self.env.regs_by_class[class as u8 as usize]
2598-
[(i + bundle.index()) % n_regs]
2609+
[(i + scan_offset) % n_regs]
25992610
}
26002611
};
26012612

0 commit comments

Comments
 (0)