[llvm-dev] How to understand "tail" call?

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Tue Feb 19 21:39:53 PST 2019


On Tue, 19 Feb 2019 at 17:30, Peng Yu <pengyu.ut at gmail.com> wrote:
> Since the tail call optimization can not be trigger any way, why the
> generated IR still has the keyword "tail"? Isn't that unnecessary?

If you look at https://llvm.org/docs/LangRef.html#id1509, the "tail"
keyword is a suggestion together with a promise about what the callee
does (not do) with the caller's stack.

In that light it makes sense for a pass that has discovered a call
satisfies those constraints to mark it with "tail" so that if later
simplifications mean it ends up in tail position CodeGen knows it's
safe to do the optimization. Otherwise you'd have to do some
potentially fairly sophisticated inter-procedural analysis right when
you were deciding whether to make a tail call; that's definitely
something we'd discourage in LLVM.

Cheers.

Tim.


More information about the llvm-dev mailing list