[PATCH] D50704: [Inline-cost] Teach cost function to account for accumulative code-size growth

Diogo N. Sampaio via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 14 09:43:08 PDT 2018


dnsampaio added inline comments.


================
Comment at: lib/Analysis/InlineCost.cpp:1908
+  // code growth of X.
+  // Then, the actual code-size growth is S - (N * X). We assume that the
+  // code growth is constant when inlining the same function.
----------------
greened wrote:
> S - (N*X) doesn't match what the comment message says and doesn't make sense to me in this context.  If N is large enough, this says the growth could become negative.
Indeed the comment wrong. It should be (N*X). Will fix it.

The stipulated growth is N * (NumberOfInstrucions - NumberOfSimplifiedInstructions), where the last is expected, due the previous analysis. Yes, it is a pessimistic assumption, but with such a small threshold, is quite effective.

If the function has local linkage, then the expected growth might be negative, as the function will be eliminated, and the cost would actually be (N*X)-S.


================
Comment at: lib/Analysis/InlineCost.cpp:1913
+
+  int Growth = (NumInstructions - NumInstructionsSimplified) * F.getNumUses();
+
----------------
greened wrote:
> This assumes all uses are inlined.  That seems overly pessimistic.  I'm not sure it's wise to predict what the inliner will do in the cost model.  It seems like an incremental cost would be better.  The inliner would then do the cost analysis for each inlining opportunity and decide on a case-by-case basis whether to inline or not.  As written, this seems to have the cost model driving inline decisions (inline everything or nothing) rather than the inliner using cost information to make decisions.
The cost-function analysis using -Oz are not that complex. It only considers each of the instructions (if they can be simplified if inlined), arguments passed and a constant cost for the call site. And see that it is incremental already. The additional cost decreases each time the function is inlined, that is, N reduces. The first one has the higher penalty, the last ones the higher benefit. Not counting the last one that gains huge bonus already.



https://reviews.llvm.org/D50704





More information about the llvm-commits mailing list