Dear GCC developers: TL;DR Can I talk to a maintainer of gcc's tail-call optimizer to learn more about the very impressive technology behind it? Or is there a paper, or documentation, that explains it?
I am sure you know that gcc does a much better job of tail-call optimizations than its competitors. Recently I noticed this little gem: void f( void *p); int h( int n, void *p) { { void *a[ 10 ]; a[ 0 ]= p; f(( void *)a); } return h(n, p); } With the inner curly braces, gcc turns the call to h into a jump. Without the inner curly braces, gcc does not do tail-call optimization. This is exactly correct, because we cannot know whether f() stores its argument in a place where later calls to h() might access it. The inner braces ensure that a[] is officially deallocated before the call to h. Clang/llvm does not tail-call-optimize this program. So, congratulations. I would enjoy speaking to one of you who is knowledgeable about how gcc does this. A few years ago I wrote some compiler textbooks, Modern Compiler Implementation in C, in ML, in Java (Cambridge University Press) and I am still interested in these things. More to the point, I use C as the target for a functional-language compiler, for which tail-call optimization is very important. So please let me know, * is there a paper somewhere that describes the approach that gcc takes for TCO? * I'm particularly interested in how gcc's intermediate language represents the fact that a[] is deallocated at the first close-curly-brace * Would someone like to Zoom sometime to tell me about this? Sincerely, Andrew Appel Professor of Computer Science Princeton University