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.
This commit is contained in:
@@ -2570,6 +2570,17 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
} else {
|
||||
n_regs
|
||||
};
|
||||
// Heuristic: start the scan for an available
|
||||
// register at an offset influenced both by our
|
||||
// location in the code and by the bundle we're
|
||||
// considering. This has the effect of spreading
|
||||
// demand more evenly across registers.
|
||||
let scan_offset = self.ranges[self.bundles[bundle.index()].first_range.index()]
|
||||
.range
|
||||
.from
|
||||
.inst
|
||||
.index()
|
||||
+ bundle.index();
|
||||
for i in 0..loop_count {
|
||||
// The order in which we try registers is somewhat complex:
|
||||
// - First, if there is a hint, we try that.
|
||||
@@ -2587,7 +2598,7 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
(0, Some(hint_reg)) => hint_reg,
|
||||
(i, Some(hint_reg)) => {
|
||||
let reg = self.env.regs_by_class[class as u8 as usize]
|
||||
[(i - 1 + bundle.index()) % n_regs];
|
||||
[(i - 1 + scan_offset) % n_regs];
|
||||
if reg == hint_reg {
|
||||
continue;
|
||||
}
|
||||
@@ -2595,7 +2606,7 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
}
|
||||
(i, None) => {
|
||||
self.env.regs_by_class[class as u8 as usize]
|
||||
[(i + bundle.index()) % n_regs]
|
||||
[(i + scan_offset) % n_regs]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user