<div dir="ltr">Hi,<div><br></div><div>Thanks for all the feedback related to code size.</div><div><br></div><div>From my understanding, the current PGSO (D59514, D67120) has two parts:</div><div>1. Adding a new llvm::shouldOptimizeForSize framework that leverages BFI and PSI to provide block level and function level assessments on whether we should optimize for size.</div><div>2. In Passes (mostly MachinePasses), they'll change certain behaviors (e.g. whether adding pads or not) if llvm::shouldOptimizeForSize returns true OR there is an `optsize` or `minsize` attribute</div><div><br></div><div>I totally agree with Wenlei that (somewhere in the future) we should have a unified FDO framework for both code size and compilation time. And I think Renato and Tobias's suggestions to do the same thing for size-oriented attributes (i.e. `minsize` and `optsize`) is the low-hanging fruit we can support in a short time.</div><div>Engineering-wised I'll prefer to send out a separate review for the size-oriented attributes work, since `minsize` / `optsize` are kind of in conflict with `optnone` so I don't think it's a good idea to put them into one flag / feature set.<br></div><div><br></div><div>Best,</div><div>Min</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 10, 2020 at 9:18 AM Hiroshi Yamauchi via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 9, 2020 at 9:23 PM Wenlei He via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US">
<div>
<p class="MsoNormal">I think calling PGSO size opt is probably a bit misleading though. It’s more of an adaptive opt strategy, and it can improve performance too due to better locality. We have something similar internally for selecting opt level based on profile
 hotness too under AutoFDO. <u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Perhaps similar implementations can all be unified under a profile guided “adaptive optimization” framework to avoid duplication:<u></u><u></u></p>
<ul style="margin-top:0in" type="disc">
<li style="margin-left:0in">A unified way of setting hot/cold cutoff percentile (e.g. through PSI that’s already used by all PGO/FDO).<u></u><u></u></li><li style="margin-left:0in">A unified way of selecting opt strategy for cold functions: default, none, size, minsize.<u></u><u></u></li></ul>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
<p class="MsoNormal">Wenlei<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(181,196,223);padding:3pt 0in 0in">
<p class="MsoNormal"><b><span style="font-size:12pt;color:black">From: </span></b><span style="font-size:12pt;color:black">llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>> on behalf of Modi Mo via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<b>Reply-To: </b>Modi Mo <<a href="mailto:modimo@fb.com" target="_blank">modimo@fb.com</a>><br>
<b>Date: </b>Wednesday, September 9, 2020 at 5:55 PM<br>
<b>To: </b>Tobias Hieta <<a href="mailto:tobias@plexapp.com" target="_blank">tobias@plexapp.com</a>>, Renato Golin <<a href="mailto:rengolin@gmail.com" target="_blank">rengolin@gmail.com</a>><br>
<b>Cc: </b>"<a href="mailto:ddevienne@gmail.com" target="_blank">ddevienne@gmail.com</a>" <<a href="mailto:ddevienne@gmail.com" target="_blank">ddevienne@gmail.com</a>>, llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>, "cfe-dev (<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>)" <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>><br>
<b>Subject: </b>Re: [llvm-dev] [RFC] New Feature Proposal: De-Optimizing Cold Functions using PGO Info<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal">FYI David is referring to PGSO (profile-guided size optimization) as it exists directly under that name, see:
<a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D67120&d=DwMGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=KfYo542rDdZQGClmgz-RBw&m=tscXcy0bnqeZPQHl9SiPfgvfUizD33tNurQecbRunKg&s=RvBQN7FNwjsvLgJgV9jlOUCrkLubfH6CtcALRdXOYao&e=" target="_blank">
https://reviews.llvm.org/D67120</a>. And yeah using PGSO is selecting optsize while this change is selecting optnone.</p></div></div></blockquote><div><br></div><div><span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>P<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>G<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>S<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>O<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span> <span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>l<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>o<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>o<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>k<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>s<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span> <span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>a<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>t<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span> <span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>t<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>h<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>e<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span> <span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>b<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>l<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>o<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>c<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>k<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>-<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>l<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>e<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>v<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>e<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>l<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span> <span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>p<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>r<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>o<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>f<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>i<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>l<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>e<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>,<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span> <span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>t<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>o<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>o<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span>.<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"></span></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div><p class="MsoNormal"><u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">On 9/9/20, 10:58 AM, "llvm-dev on behalf of Tobias Hieta via llvm-dev" <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a> on behalf of
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Would it make sense to have a flag to select optnone or optsize? We would probably also do the tradeoff for a smaller binary. <u></u><u></u></p>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">On Wed, Sep 9, 2020, 19:28 Renato Golin <<a href="mailto:rengolin@gmail.com" target="_blank">rengolin@gmail.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<div>
<div>
<p class="MsoNormal">On Wed, 9 Sep 2020 at 18:15, Min-Yih Hsu via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></p>
</div>
<div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<div>
<div>
<p class="MsoNormal">David mentioned in D87337 that LLVM has used similar techniques on code size (not sure what he was referencing, my guess will be something related to hot-cold code splitting).<u></u><u></u></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">IIUC, it's just using optsize instead of optnone. The idea is that, if the code really doesn't run often/at all, then the performance impact of reducing the size is negligible, but the size impact is considerable.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">I'd wager that optsize could even be faster than optnone, as it would delete a lot of useless code... but not noticeable, as it wouldn't run much.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">This is an idea that we (Verona Language) are interested in, too.<u></u><u></u></p>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>

_______________________________________________<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>
_______________________________________________<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Min-Yih Hsu</div><div>Ph.D Student in ICS Department, University of California, Irvine (UCI).<br></div></div></div>