[llvm-dev] Another tail call optimization question

Haoran Xu via llvm-dev llvm-dev at lists.llvm.org
Sat Oct 3 02:02:53 PDT 2020


Hello,

Could anyone kindly explain to me why the 'g()' in the following function
cannot have tail call optimization?

> void f(int* x);
> void g();
> void h(int v) {
>    f(&v);
>    g();
> }
>
A while ago I was taught that tail call optimization cannot apply if local
variables needs to be kept alive, but 'g()' doesn't seem to require
anything to be alive on the stack.
I tried to manually add 'tail' to the emitted LLVM IR and it appears to
work.

Any idea how I could fix this and let clang automatically generate tail
call?

Thanks!

Best,
Haoran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201003/35e23c06/attachment.html>


More information about the llvm-dev mailing list