Skip to content

Commit 5f04e06

Browse files
committed
Tweak regalloc double-split handling
The double-split logic assumed that the range obtained by splitting at the first split point would always be splittable at the second, but this is incorrect for ranges with holes around the second split point. Make sure double split handling always checks whether the range is splittable at the second split point before going through with it, and simplify some code in the double-split computation now that that is the case.
1 parent 5bd22b7 commit 5f04e06

File tree

2 files changed

+9637
-5
lines changed

2 files changed

+9637
-5
lines changed

crates/codegen/src/regalloc/split.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,7 @@ impl<M: MachineRegalloc> RegAllocContext<'_, M> {
179179
self.get_real_split_point(fragment, high_split_point, boundary_instr);
180180

181181
let split_kind = match (low_split_point, high_split_point) {
182-
(Some(low_split_point), Some(high_split_point))
183-
if high_split_point != low_split_point =>
184-
{
182+
(Some(low_split_point), Some(high_split_point)) => {
185183
SplitKind::Double(low_split_point, high_split_point)
186184
}
187185
(Some(low_split_point), _) => SplitKind::Single(low_split_point),
@@ -211,11 +209,18 @@ impl<M: MachineRegalloc> RegAllocContext<'_, M> {
211209
}
212210
SplitKind::Double(instr1, instr2) => {
213211
let mid = self.split_fragment(fragment, instr1);
214-
let high = self.split_fragment(mid, instr2);
212+
213+
// Attempt to split again at `instr2`. This won't be possible, when, for example:
214+
// * `instr1 == instr2`
215+
// * `mid` starts at or above `instr2` because there was a hole in the original
216+
// fragment
217+
if self.can_split_fragment_before(mid, instr2) {
218+
let high = self.split_fragment(mid, instr2);
219+
self.enqueue_fragment(high);
220+
}
215221

216222
self.enqueue_fragment(fragment);
217223
self.enqueue_fragment(mid);
218-
self.enqueue_fragment(high);
219224
}
220225
}
221226
}

0 commit comments

Comments
 (0)