<div dir="ltr"><div>Regarding the heap-to-stack:</div><div><br></div>On Thu, Sep 12, 2013 at 9:21 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank" class="cremed">hfinkel@anl.gov</a>></span> wrote:<br>
<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><span style="color:rgb(34,34,34)">why is it not simple:</span><br>
</div>
<br>
 - For all calls to malloc, for which we see calls to free along all control-flow paths<br>
 - Replace the malloc with alloca, remove the free (and add lifetime intrinsics immediately after the alloca and where the free used to be)<br>
<br>
What am I missing?<br></blockquote><div><br></div><div>Do you do it every time? If not, when?</div><div><br></div><div>- What about when this dramatically increases stack usage (potentially causing us to run out of stack)?</div>
<div>- What about cases where this occurs inside of a loop? Or is inlined into a loop?</div><div><br></div><div>These are certainly solvable with reasonable thresholds, but setting those thresholds requires benchmarking across a wide variety of benchmarks, etc. Something that we should do, but something that is not trivial to do, and which I see zero chance of doing in 1 week. ;]</div>
<div><br></div><div>Note that I didn't say "intractable", just "not trivial". I think that's the case.</div><div><br></div><div><br></div><div>And the dynamic case:</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im">> It blocks inlining,<br>
<br>
</div>Only because you made it do so; we could enabling inlining just as easily. When you originally did this, we did not have stack coloring, right?<br></blockquote><div><br></div><div>This predates my work on the inliner. It has been there a *long* time. I don't know what the implications would be of removing it, that too would require benchmarking and analysis to ensure this doesn't regress code, or if it does to fix those regressions with more appropriate measures.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">>increases register pressure,<br>
<br>
This is true, but it is not clear that it would be a significant problem. Function calls have overhead too, obviously, so I think that for small functions it would probably be okay, and for larger functions you'd probably want to maintain the prohibition.<br>
</blockquote><div><br></div><div>This is another threshold that I expect to be challenging to set and have be correct across a wide variety of architectures and benchmarks.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im"><span style="color:rgb(34,34,34)">This is somewhat of a chicken and egg problem.</span></div></blockquote><div><br></div><div>Not really. We have alloca and VLAs. We could use them, and can even build containers around them that aren't as elegant. And yet, I very rarely see code doing this in practice.</div>
</div></div></div>