[llvm-dev] Understanding tail call

Haoran Xu via llvm-dev llvm-dev at lists.llvm.org
Fri Sep 25 03:33:32 PDT 2020


Hi friendly LLVM Devs,

I'm trying to understand the technical details of tail call optimization,
but unfortunately I hit some issues that I couldn't figure out myself.

So I tried the following two really simple functions:

> extern void g(int*);
> void f1() {
>    int x;
>    g(&x);
> }
> void f2(int* x) {
>    g(x);
> }
>
It turns out that 'f1' does not have tail call optimization, but 'f2' does.
My current really naive understanding is that a call happening as the last
statement of the function can be optimized as a tail call. However, why
cannot 'f1' do this?

Is there any recommended articles that I should read if I were to
understand the internals of tail call optimization in LLVM, or more
generally, performance optimization on reducing function calling overhead?
I know there are a bunch of different calling conventions, optimized for
different use cases, but I don't know any of the details. Can someone
suggest a good introductory material that I should read to understand what
are the pros and cons of each calling convention, and what should be the
best calling convention for a given use case?

Thanks!

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


More information about the llvm-dev mailing list