<div dir="ltr"><div>I checked Intel instruction guide and it seems like conditional jumps can take rip-relative 32-bit operands, same as unconditional jumps. Did I miss something?</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Joerg Sonnenberger via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> 于2020年10月6日周二 下午4:14写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, Oct 06, 2020 at 02:51:46AM -0700, Haoran Xu via llvm-dev wrote:<br>
> Hello,<br>
> <br>
> I recently found that LLVM generates sub-optimal assembly for a tail call<br>
> optimization case. Below is an example (<a href="https://godbolt.org/z/ao15xE" rel="noreferrer" target="_blank">https://godbolt.org/z/ao15xE</a>):<br>
> <br>
> > void g1();<br>
> > void g2();<br>
> > void f(bool v) {<br>
> > if (v) {<br>
> > g1();<br>
> > } else {<br>
> > g2();<br>
> > }<br>
> > }<br>
> ><br>
> The assembly generated is as follow:<br>
> <br>
> > f(bool): # @f(bool)<br>
> > testb %dil, %dil<br>
> > je .LBB0_2<br>
> > jmp g1() # TAILCALL<br>
> > .LBB0_2:<br>
> > jmp g2() # TAILCALL<br>
> ><br>
> However, in this specific case (where no function epilogue is needed), one<br>
> can actually change 'je .LBB0_2' to 'je g2()' directly, thus saving a jump.<br>
> Is there any way I could instruct LLVM to do this? For my use case, it is<br>
> acceptable to do this at any level (C++ level /IR level /MachineInst level<br>
> is all fine).<br>
<br>
That translation doesn't normally work as conditional jumps have a much<br>
more restricted range.<br>
<br>
Joerg<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>