On Thu, Jul 4, 2024 at 3:24 AM Eduard Zingerman <eddyz87@xxxxxxxxx> wrote: > > + for (j = 1; j <= spills_num; ++j) { > + if ((insn - j)->off >= subprogs[cur_subprog].nocsr_stack_off || > + (insn + j)->off >= subprogs[cur_subprog].nocsr_stack_off) { > + /* do a second visit of this instruction, > + * so that verifier can inline it > + */ > + i -= 1; > + insn -= 1; > + goto next_insn; > + } > + } > + > + /* apply the rewrite: > + * *(u64 *)(r10 - X) = rY ; num-times > + * call() -> call() > + * rY = *(u64 *)(r10 - X) ; num-times > + */ > + err = verifier_remove_insns(env, i + delta - spills_num, spills_num); > + if (err) > + return err; > + err = verifier_remove_insns(env, i + delta - spills_num + 1, spills_num); > + if (err) > + return err; > + > + i += spills_num - 1; > + /* ^ ^ do a second visit of this instruction, > + * | '-- so that verifier can inline it > + * '--------------- jump over deleted fills > + */ > + delta -= 2 * spills_num; > + insn = env->prog->insnsi + i + delta; > + goto next_insn; > + } somewhere after spill/fill removal subprog->stack_depth needs to be adjust to nocsr_stack_off, otherwise extra stack space is wasted. I couldn't find this logic in the patch. Once the adjustment logic is done, pls add a selftest with nocsr and may_goto, since may_goto processing is in the same do_misc_fixups() loop and it needs to grow the stack while spill/fill removal will shrink the stack.