Skip to content

Commit 00dc332

Browse files
authored
Move the split point to the first fixed use (#165)
Address bytecodealliance/wasmtime#7147 by moving the bundle split point to the first fixed use found after the suggested split point. This implementation only considers the first liverange that contains the split point, so there's room for improvement. The intent with this change is to not artificially constrain the bundle produced after the split point by leaving unconstrained uses that could be kept above the split point. Splitting at the first fixed use after the suggested split point should produce a less constrained upper bundle, which will be easier to allocate. One interesting effect from the example in the issue linked above is that the change of split point alone does not fix the problem, as we also trim the space around the split point into the spill bundle. Doing this creates the same splits that we would have arrived at before, as the second load doesn't use `v1` all and thus that region is trimmed to the spill bundle. I addressed that by disabling trimming when the split point is advanced, under the assumption that the point moving means that you probably want to give the allocator another chance with both bundles. I'm not sure that this implementation is the right path forward currently, as it might be better to perform the heuristic outside of the call to `split_and_requeue_bundle`, allowing us the flexibility to make the decision about trimming at that point.
1 parent 4777ec9 commit 00dc332

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/ion/process.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl<'a, F: Function> Env<'a, F> {
397397
reg_hint: PReg,
398398
// Do we trim the parts around the split and put them in the
399399
// spill bundle?
400-
trim_ends_into_spill_bundle: bool,
400+
mut trim_ends_into_spill_bundle: bool,
401401
) {
402402
self.stats.splits += 1;
403403
trace!(
@@ -496,6 +496,31 @@ impl<'a, F: Function> Env<'a, F> {
496496
}
497497
if split_at < entry.range.to {
498498
first_lr_in_new_bundle_idx = i;
499+
500+
// When the bundle contains a fixed constraint, we advance the split point to right
501+
// before the first instruction with a fixed use present.
502+
if self.bundles[bundle].cached_fixed() {
503+
for u in &self.ranges[entry.index].uses {
504+
if u.pos < split_at {
505+
continue;
506+
}
507+
508+
if matches!(u.operand.constraint(), OperandConstraint::FixedReg { .. }) {
509+
split_at = ProgPoint::before(u.pos.inst());
510+
511+
if split_at > entry.range.from {
512+
last_lr_in_old_bundle_idx = i;
513+
}
514+
515+
trace!(" -> advancing split point to {split_at:?}");
516+
517+
trim_ends_into_spill_bundle = false;
518+
519+
break;
520+
}
521+
}
522+
}
523+
499524
break;
500525
}
501526
}

0 commit comments

Comments
 (0)