Assert that we only use virtual registers with moves (#5440)

Assert that we never see real registers as arguments to move instructions in VCodeBuilder::collect_operands.

Also fix a bug in the riscv64 backend that was discovered by these assertions: the lowerings of get_stack_pointer and get_frame_pointer were using physical registers 8 and 2 directly. The solution was similar to other backends: add a move instruction specifically for moving out of physical registers, whose source operand is opaque to regalloc2.
This commit is contained in:
Trevor Elliott
2022-12-20 18:22:47 -08:00
committed by GitHub
parent a308828ba2
commit fac4a915a3
6 changed files with 71 additions and 7 deletions

View File

@@ -568,11 +568,25 @@ impl<I: VCodeInst> VCodeBuilder<I> {
}
if let Some((dst, src)) = insn.is_move() {
// We should never see non-virtual registers present in move
// instructions.
assert!(
src.is_virtual(),
"the real register {:?} was used as the source of a move instruction",
src
);
assert!(
dst.to_reg().is_virtual(),
"the real register {:?} was used as the destination of a move instruction",
dst.to_reg()
);
let src = Operand::reg_use(Self::resolve_vreg_alias_impl(vreg_aliases, src.into()));
let dst = Operand::reg_def(Self::resolve_vreg_alias_impl(
vreg_aliases,
dst.to_reg().into(),
));
// Note that regalloc2 requires these in (src, dst) order.
self.vcode.is_move.insert(InsnIndex::new(i), (src, dst));
}