[llvm-dev] Optimizing assembly generated for tail call
Haoran Xu via llvm-dev
llvm-dev at lists.llvm.org
Tue Oct 6 02:51:46 PDT 2020
Hello,
I recently found that LLVM generates sub-optimal assembly for a tail call
optimization case. Below is an example (https://godbolt.org/z/ao15xE):
> void g1();
> void g2();
> void f(bool v) {
> if (v) {
> g1();
> } else {
> g2();
> }
> }
>
The assembly generated is as follow:
> f(bool): # @f(bool)
> testb %dil, %dil
> je .LBB0_2
> jmp g1() # TAILCALL
> .LBB0_2:
> jmp g2() # TAILCALL
>
However, in this specific case (where no function epilogue is needed), one
can actually change 'je .LBB0_2' to 'je g2()' directly, thus saving a jump.
Is there any way I could instruct LLVM to do this? For my use case, it is
acceptable to do this at any level (C++ level /IR level /MachineInst level
is all fine).
Thanks!
Best,
Haoran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201006/400bcc5a/attachment.html>
More information about the llvm-dev
mailing list