Skip to content

Commit 4b136d6

Browse files
authored
Fix handling of dedicated scratch registers (#149)
`get_reg` can be called multiple times if multiple scratch registers are needed (e.g. for stack-to-stack moves).
1 parent 24c0517 commit 4b136d6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/ion/moves.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,12 +904,15 @@ impl<'a, F: Function> Env<'a, F> {
904904
0,
905905
None,
906906
);
907+
let mut dedicated_scratch = self.env.scratch_by_class[regclass as usize];
907908
let key = LiveRangeKey::from_range(&CodeRange {
908909
from: pos_prio.pos,
909910
to: pos_prio.pos.next(),
910911
});
911912
let get_reg = || {
912-
if let Some(reg) = self.env.scratch_by_class[regclass as usize] {
913+
// Use the dedicated scratch register first if it is
914+
// available.
915+
if let Some(reg) = dedicated_scratch.take() {
913916
return Some(Allocation::reg(reg));
914917
}
915918
while let Some(preg) = scratch_iter.next() {

0 commit comments

Comments
 (0)