<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 1, 2016 at 12:35 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:10pt;color:#000000"><br><hr><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><b>From: </b>"Mehdi Amini via llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br><b>To: </b>"Xinliang David Li" <<a href="mailto:davidxl@google.com" target="_blank">davidxl@google.com</a>><br><b>Cc: </b>"llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br><b>Sent: </b>Friday, April 1, 2016 2:26:27 PM<br><b>Subject: </b>Re: [llvm-dev] [RFC] Target-specific parametrization of function inliner<span class=""><br><br>
<br><div><blockquote><div>On Mar 10, 2016, at 10:34 AM, Xinliang David Li via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br><div><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 10, 2016 at 6:49 AM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">IMO, the appropriate thing for TTI to inform the inliner about is how costly the actual act of a "call" is likely to be. I would hope that this would only be used on targets where there is some really dramatic overhead of actually doing a function call such that the code size cost incurred by inlining is completely dwarfed by the improvements. GPUs are one of the few platforms that exhibit this kind of behavior, although I don't think they're truly unique, just a common example.<div><br></div><div>This isn't quite the same thing as the cost of the call instruction, which has much more to do with the size. Instead, it has to do with the expected consequences of actually leaving a call edge in the program.</div></div></blockquote><div> <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>To me, this pretty accurately reflects the TTI hook we have for customizing loop unrolling where the cost of having a cyclic CFG is modeled to help indicate that on some targets (also GPUs) it is worth a very large amount of code size growth to simplify the control flow in a particular way.</div><div><br></div></div></blockquote><div><br></div><div>From 10000 foot, the LLVM inliner implements a size based heuristic :  if the inline instance's size*/cost after simplification via propagating the call context (actually the relative size -- the callsite cost is subtracted from it), is smaller than a threshold (adjusted from a base value), then the callsite is considered an inline candidate. In most cases, the decision is made locally due to the bottom-up order (there are tweaks to bypass it).   The size/cost can be remotely tied and serves a proxy to represent the real runtime cost due to icache/itlb effect, but it seems the size/threshold scheme is mainly used to model the runtime speedup vs compile time/binary size tradeoffs.  <br></div></div></div></div></div></blockquote><div><br></div><div>Other than the call cost itself, I've been surprised that the TTI is not more involved when it comes to this tradeoff: instructions don't have the same tradeoff depending on the platform (oh this operation is not legal on this type and will be expanded in multiple instructions in SDAG, too bad..).</div></div></span></blockquote>I think that doing this was intended, but we've not done it yet (as we did for the throughput model used for vectorization). I think we should (I also think we should combine the cost models so that we have a single model that returns multiple kinds of costs (throughput, size, latency, etc.)).</div></div></blockquote><div><br></div><div><br></div><div>yes -- the time/speed up estimate should be independent of size increase estimate.</div><div><br></div><div>David</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:10pt;color:#000000"><span class="HOEnZb"><font color="#888888"><br><br> -Hal<br><br></font></span><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div><span class="HOEnZb"><font color="#888888"><div></div><div><br></div><div>-- </div><div>Mehdi</div><div><br></div><br></font></span><blockquote><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><div><br></div><div>Set aside what we need longer term for the inliner, the GPU specific problems can be addressed by</div><div>1) if the call overhead is really large, define a target specific getCallCost and subtract it from the initial Cost when analyzing a callsite (this will help boost all targets with high call costs)</div><div>2) if not, but instead GPU users can tolerate large code growth, then it is better to this by adjusting the threshold -- perhaps have a user level option -finline-limit=?</div><div><br></div><div>thanks,</div><div><br></div><div>David</div><div><br></div><div><br></div><div>* some target dependent info may be used: TTI.getUserCost</div><div> </div></span><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class=""><div dir="ltr"><div></div><div>Does that make sense to you Hal? Based on that, it would really just be a scaling factor of the inline heuristics. Unsure of how to more scientifically express this construct.</div><span><font color="#888888"><div><br></div><div>-Chandler</div></font></span></div></span><div><div><br><div class="gmail_quote"><span class=""><div dir="ltr">On Thu, Mar 10, 2016 at 3:42 PM Hal Finkel via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div></span><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><hr><div><div class="h5"><br>
> From: "Artem Belevich via llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
> To: "llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
> Sent: Tuesday, March 1, 2016 6:31:06 PM<br>
> Subject: [llvm-dev] [RFC] Target-specific parametrization of function inliner<br>
><br>
> Hi,<br>
><br>
><br>
> I propose to make function inliner parameters adjustable for specific<br>
> target.<br>
><br>
> Currently function inlining pass appears to be target-agnostic with<br>
> various constants for calculating call cost hardcoded. While it<br>
> works reasonably well for general purpose CPUs, some quirkier<br>
> targets like NVPTX would benefit from target-specific tuning.<br>
><br>
><br>
> Currently it appears that there are two things that need to be done:<br>
><br>
><br>
> * add Inliner preferences to TargetTransformInfo in a way similar to<br>
> how we customize loop unrolling. Use it to provide inliner with<br>
> target-specific thresholds and other parameters.<br>
> * augment Inliner pass to use existing TargetTransformInfo API to<br>
> figure out cost of particular call on a given target.<br>
> TargetTransforInfo already has getCallCost(), though it does not<br>
> look like anything uses it.<br>
><br>
><br>
> Comments? Concerns? Suggestions?<br>
><br>
<br>
Hi Art,<br>
<br>
I've long thought that we should have a more principled way of doing inline profitability. There is obviously some cost to executing a function body, some call site overhead, and some cost reduction associated with any post-inlining simplifications. If inlining reduces the overall call site cost by more than some factor, say 1% (this should probably depend on the optimization level), then we should inline. With profiling information, we might even use global speedup instead of local speedup.<br>
<br>
Whether we need a target customization of this threshold, or just a way for a target to supplement the fine inlining decision, is unclear to me. It is also true that a the result of a bunch of locally-optimal decisions might be far from the global optimum. Maybe the target has something to say about that?<br>
<br>
In short, I'm fine with what you're proposing, but to the extent possible, I want the numbers provided by the target to mean something. Replacing a global set of somewhat-arbitrary magic numbers, with target-specific sets of somewhat-arbitrary magic numbers should be our last choice.<br>
<br>
Thanks again,<br>
Hal<br>
<br>
<br>
><br>
> Thanks,<br>
> --<br>
><br>
><br>
> --Artem Belevich<br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
><br>
<br>
--<br>
Hal Finkel<br>
Assistant Computational Scientist<br>
Leadership Computing Facility<br>
Argonne National Laboratory<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</div></div></blockquote></div>
</div></div></blockquote></div><br></div></div><div><div class="h5">
_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br></div></div></div></blockquote></div><div><div class="h5"><br><br>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br></div></div></blockquote><div><div class="h5"><br><br><br>-- <br><div><span name="x"></span>Hal Finkel<br>Assistant Computational Scientist<br>Leadership Computing Facility<br>Argonne National Laboratory<span name="x"></span><br></div></div></div></div></div></blockquote></div><br></div></div>