[PATCH] D145516: [Inliner] Avoid excessive inlining through devirtualised calls

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 18 11:59:01 PDT 2023


aeubanks added inline comments.


================
Comment at: llvm/lib/Analysis/InlineCost.cpp:683
         // threshold to get the bonus we want to apply, but don't go below zero.
-        Cost -= std::max(0, CA.getThreshold() - CA.getCost());
+        Cost -= std::min(Cost, std::max(0, CA.getThreshold() - CA.getCost()));
       }
----------------
jmorse wrote:
> aeubanks wrote:
> > is this change intended?
> It is, it puts a ceiling on the outer subtraction so that the cost is never reduced to be below zero. While the comment says that negative-costs have been considered, I think that only applies to the inner subtraction, as I've seen negative numbers produced here during testing.
> 
> I can split this out into a different patch if needs be, but I'm not sure how to write a test for it. As far as I understand it, the cost can only be observed by passing `-debug` to LLVM, and I'm under the impression that that's generally discouraged in tests.
`-passes=print<inline-cost>` should be what you want for testing

but negative costs are very common for inlining because it's cheaper to not setup a call, so I don't think this change makes sense


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145516/new/

https://reviews.llvm.org/D145516



More information about the llvm-commits mailing list