Skip to content

Commit fdbdb9a

Browse files
authored
[mono][jit] Fix an assert in the local register allocator. (#66054)
The assertion is hit when an instruction has a fixed sreg (like shifts on x86) which was spilled to the stack.
1 parent 1cfa6d6 commit fdbdb9a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/mono/mono/mini/mini-codegen.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,7 @@ mono_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
14361436
continue;
14371437
}
14381438

1439+
gboolean need_assign = FALSE;
14391440
if (rs->ifree_mask & (regmask (dest_sreg))) {
14401441
if (is_global_ireg (sreg)) {
14411442
int k;
@@ -1454,8 +1455,8 @@ mono_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
14541455
DEBUG (printf ("\tshortcut assignment of R%d to %s\n", sreg, mono_arch_regname (dest_sreg)));
14551456
assign_reg (cfg, rs, sreg, dest_sreg, 0);
14561457
} else if (val < -1) {
1457-
/* FIXME: */
1458-
g_assert_not_reached ();
1458+
/* sreg is spilled, it can be assigned to dest_sreg */
1459+
need_assign = TRUE;
14591460
} else {
14601461
/* Argument already in hard reg, need to copy */
14611462
MonoInst *copy = create_copy_ins (cfg, bb, tmp, dest_sreg, val, NULL, ip, 0);
@@ -1476,9 +1477,9 @@ mono_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
14761477
}
14771478
} else {
14781479
gboolean need_spill = TRUE;
1479-
gboolean need_assign = TRUE;
14801480
int k;
14811481

1482+
need_assign = TRUE;
14821483
dreg_mask &= ~ (regmask (dest_sreg));
14831484
for (k = 0; k < num_sregs; ++k) {
14841485
if (k != j)
@@ -1538,18 +1539,17 @@ mono_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
15381539
if (need_spill) {
15391540
free_up_hreg (cfg, bb, tmp, ins, dest_sreg, 0);
15401541
}
1542+
}
1543+
if (need_assign) {
1544+
if (rs->vassign [sreg] < -1) {
1545+
int spill;
15411546

1542-
if (need_assign) {
1543-
if (rs->vassign [sreg] < -1) {
1544-
int spill;
1545-
1546-
/* Need to emit a spill store */
1547-
spill = - rs->vassign [sreg] - 1;
1548-
create_spilled_store (cfg, bb, spill, dest_sreg, sreg, tmp, NULL, ins, bank);
1549-
}
1550-
/* force-set sreg2 */
1551-
assign_reg (cfg, rs, sregs [j], dest_sreg, 0);
1547+
/* Need to emit a spill store */
1548+
spill = - rs->vassign [sreg] - 1;
1549+
create_spilled_store (cfg, bb, spill, dest_sreg, sreg, tmp, NULL, ins, bank);
15521550
}
1551+
/* force-set sreg */
1552+
assign_reg (cfg, rs, sregs [j], dest_sreg, 0);
15531553
}
15541554
sregs [j] = dest_sreg;
15551555
}

0 commit comments

Comments
 (0)