Skip to content

Commit b114db8

Browse files
committed
panic when a block has multiple predecessors with one of them defining a branch arg on the branch & improve code clarity of decrementing counters when allocating scratch registers
1 parent bdaaead commit b114db8

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/fastalloc/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,12 @@ impl<'a, F: Function> Env<'a, F> {
491491
&& self.edits.scratch_regs[class].is_none()
492492
{
493493
self.alloc_scratch_reg(inst, class, pos)?;
494-
self.num_available_pregs[ExclusiveOperandPos::Both][class] =
495-
0i16.max(self.num_available_pregs[ExclusiveOperandPos::Both][class] - 1);
496-
self.num_available_pregs[ExclusiveOperandPos::LateOnly][class] =
497-
0i16.max(self.num_available_pregs[ExclusiveOperandPos::LateOnly][class] - 1);
498-
self.num_available_pregs[ExclusiveOperandPos::EarlyOnly][class] -=
499-
0i16.max(self.num_available_pregs[ExclusiveOperandPos::EarlyOnly][class] - 1);
494+
let dec_clamp_zero = |x: &mut i16| {
495+
*x = 0i16.max(*x - 1);
496+
};
497+
dec_clamp_zero(&mut self.num_available_pregs[ExclusiveOperandPos::Both][class]);
498+
dec_clamp_zero(&mut self.num_available_pregs[ExclusiveOperandPos::EarlyOnly][class]);
499+
dec_clamp_zero(&mut self.num_available_pregs[ExclusiveOperandPos::LateOnly][class]);
500500
}
501501
self.edits.add_move(inst, from, to, class, pos);
502502
Ok(())
@@ -1453,6 +1453,9 @@ impl<'a, F: Function> Env<'a, F> {
14531453
let move_from = self.func.inst_operands(pred_last_inst)
14541454
.iter()
14551455
.find_map(|op| if op.kind() == OperandKind::Def && op.vreg() == branch_arg_for_param {
1456+
if self.func.block_preds(block).len() > 1 {
1457+
panic!("Multiple predecessors when a branch arg is defined on the branch");
1458+
}
14561459
match op.constraint() {
14571460
OperandConstraint::FixedReg(reg) => {
14581461
trace!("Found one for branch arg {branch_arg_for_param} and param {block_param} in reg {reg}");

0 commit comments

Comments
 (0)