<div dir="ltr"><div>Hi friendly LLVM Devs,</div><div><br></div><div>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.</div><div><br></div><div>So I tried the following two really simple functions:</div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><span style="color:rgb(0,0,255)">extern</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,255)">void</span><span style="color:rgb(0,0,0)"> g(</span><span style="color:rgb(0,0,255)">int</span><span style="color:rgb(0,0,0)">*);</span></div><div><span style="color:rgb(0,0,255)">void</span><span style="color:rgb(0,0,0)"> f1() {</span></div><div><span style="color:rgb(0,0,0)">   </span><span style="color:rgb(0,0,255)">int</span><span style="color:rgb(0,0,0)"> x;</span></div><div><span style="color:rgb(0,0,0)">   g(&x);</span></div><div><span style="color:rgb(0,0,0)">}</span></div><div><span style="color:rgb(0,0,255)">void</span><span style="color:rgb(0,0,0)"> f2(</span><span style="color:rgb(0,0,255)">int</span><span style="color:rgb(0,0,0)">* x) {</span></div><div><span style="color:rgb(0,0,0)">   g(x);</span></div><div><span style="color:rgb(0,0,0)">}</span></div></blockquote></div><div>It turns out that 'f1' does not have tail call optimization, but 'f2' does. <br></div><div>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? <br></div><div><br></div><div>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?</div><div><br></div><div>Thanks!</div><div><br></div><div>Best,</div><div>Haoran<br></div><div><br></div><div><div style="color:rgb(0,0,0);background-color:rgb(255,255,254);font-family:"Consolas, ""><div><span style="color:rgb(0,0,0)"><br></span></div><br><br></div></div></div>