diff --git a/src/lj_asm.c b/src/lj_asm.c index b0e6d313..1ecbe45e 100644 --- a/src/lj_asm.c +++ b/src/lj_asm.c @@ -2550,7 +2550,9 @@ void lj_asm_trace(jit_State *J, GCtrace *T) /* Set trace entry point before fixing up tail to allow link to self. */ T->mcode = as->mcp; T->mcloop = as->mcloop ? (MSize)((char *)as->mcloop - (char *)as->mcp) : 0; - if (!as->loopref) + if (as->loopref) + asm_loop_tail_fixup(as); + else asm_tail_fixup(as, T->link); /* Note: this may change as->mctop! */ T->szmcode = (MSize)((char *)as->mctop - (char *)as->mcp); asm_snap_fixup_mcofs(as); diff --git a/src/lj_asm_arm.h b/src/lj_asm_arm.h index 96703d7d..6cfe5c70 100644 --- a/src/lj_asm_arm.h +++ b/src/lj_asm_arm.h @@ -2129,6 +2129,12 @@ static void asm_loop_fixup(ASMState *as) } } +/* Fixup the tail of the loop. */ +static void asm_loop_tail_fixup(ASMState *as) +{ + UNUSED(as); /* Nothing to do. */ +} + /* -- Head of trace ------------------------------------------------------- */ /* Reload L register from g->cur_L. */ diff --git a/src/lj_asm_arm64.h b/src/lj_asm_arm64.h index dde52347..bb972ad1 100644 --- a/src/lj_asm_arm64.h +++ b/src/lj_asm_arm64.h @@ -1858,6 +1858,12 @@ static void asm_loop_fixup(ASMState *as) } } +/* Fixup the tail of the loop. */ +static void asm_loop_tail_fixup(ASMState *as) +{ + UNUSED(as); /* Nothing to do. */ +} + /* -- Head of trace ------------------------------------------------------- */ /* Reload L register from g->cur_L. */ diff --git a/src/lj_asm_mips.h b/src/lj_asm_mips.h index 22aa88bf..1fe934e1 100644 --- a/src/lj_asm_mips.h +++ b/src/lj_asm_mips.h @@ -2640,6 +2640,12 @@ static void asm_loop_fixup(ASMState *as) } } +/* Fixup the tail of the loop. */ +static void asm_loop_tail_fixup(ASMState *as) +{ + if (as->loopinv) as->mctop--; +} + /* -- Head of trace ------------------------------------------------------- */ /* Coalesce BASE register for a root trace. */ @@ -2647,7 +2653,6 @@ static void asm_head_root_base(ASMState *as) { IRIns *ir = IR(REF_BASE); Reg r = ir->r; - if (as->loopinv) as->mctop--; if (ra_hasreg(r)) { ra_free(as, r); if (rset_test(as->modset, r) || irt_ismarked(ir->t)) @@ -2662,7 +2667,6 @@ static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow) { IRIns *ir = IR(REF_BASE); Reg r = ir->r; - if (as->loopinv) as->mctop--; if (ra_hasreg(r)) { ra_free(as, r); if (rset_test(as->modset, r) || irt_ismarked(ir->t)) diff --git a/src/lj_asm_ppc.h b/src/lj_asm_ppc.h index c27ee71c..f5cedd6a 100644 --- a/src/lj_asm_ppc.h +++ b/src/lj_asm_ppc.h @@ -2157,6 +2157,12 @@ static void asm_loop_fixup(ASMState *as) } } +/* Fixup the tail of the loop. */ +static void asm_loop_tail_fixup(ASMState *as) +{ + UNUSED(as); /* Nothing to do. */ +} + /* -- Head of trace ------------------------------------------------------- */ /* Coalesce BASE register for a root trace. */ diff --git a/src/lj_asm_x86.h b/src/lj_asm_x86.h index c8ed46d2..3c934c31 100644 --- a/src/lj_asm_x86.h +++ b/src/lj_asm_x86.h @@ -2863,6 +2863,12 @@ static void asm_loop_fixup(ASMState *as) } } +/* Fixup the tail of the loop. */ +static void asm_loop_tail_fixup(ASMState *as) +{ + UNUSED(as); /* Nothing to do. */ +} + /* -- Head of trace ------------------------------------------------------- */ /* Coalesce BASE register for a root trace. */