lightning
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: jit_jmpi() to absolute address


From: Paulo César Pereira de Andrade
Subject: Re: jit_jmpi() to absolute address
Date: Tue, 6 Sep 2022 09:35:41 -0300

Em seg., 5 de set. de 2022 às 17:17, Paul Cercueil
<paul@crapouillou.net> escreveu:
>
> Hi Paulo,
>
> Le lun., sept. 5 2022 at 14:13:58 -0300, Paulo César Pereira de
> Andrade <paulo.cesar.pereira.de.andrade@gmail.com> a écrit :
> > Em sáb., 3 de set. de 2022 às 10:58, Paul Cercueil
> > <paul@crapouillou.net> escreveu:
> >>
> >>  Hi Paulo,
> >>
> >>  Somewhere in my code I do:
> >>
> >>  jit_patch_abs(jit_jmpi(), code);
> >>
> >>  On PowerPC at least, this unconditionally resolves to a movi_p() +
> >>  jmpr(), which isn't ideal - it could totally be a PC-relative branch
> >>  instead.
> >>
> >>  Is there a valid reason why this isn't converted to a PC-relative
> >>  branch, or is it a bug?
> >
> >   A pc relative jump is used only if it is a backward jump to a
> > node. If it is a raw address it will still do a jmpr.
> >   But indeed, most if no all other ports do a relative jump if
> > possible, to a raw address if it is in range.
> >
> >   Please share a jit_print() of the generated code so I can
> > check if it is triggering some bug or if for some reason it is
> > some expected condition.
> >
> >   Likely it will work if you replace:
> >
> > (void)jmpi_p(node->u.w);
> > with:
> > (void)jmpi(node->u.w);
>
> It does work. Thanks for the tip.
>
> > in jit_ppc.c:_emit_code()
> >
> > it will work, but might be hiding a bug. If the displacement
> > returns false in:
> >
> > #  define can_sign_extend_jump_p(im)    ((im) >= -33554432 && (im) <=
> > 33554431)
> >
> > it will still use a temporary register.
>
> But that's not a bug, is it? If a direct jump cannot be used I expect a
> temporary register to be used.

  It is not a bug, just a missed optimization. It works either way, and should
use a register only if an immediate does not fit.

  Still, please check the patch in the last commit. As it creates the condition
for the issue that should have been fixed.

  That pattern should be avoided, but for sure there are cases where some
kind of jump table is required, and cannot jump to a jit node, but only to
some raw address, usually resolved at runtime, and this prevents the code
to check the live range of registers. The problem was that it was not properly
updating the initial state of the block; in this case it should
consider dead all
non callee save registers, not used in the block, as dead at entry.

> Cheers,
> -Paul

Thanks,
Paulo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]