This is an archive of the discontinued LLVM Phabricator instance.

[Inliner] Update Inliner code not to subtract CallPenalty twice
ClosedPublic

Authored by eastig on Mar 20 2017, 9:54 AM.

Details

Summary

Revision 286814 introduced:

--- llvm/trunk/lib/Analysis/InlineCost.cpp	2016/10/10 21:47:28	283805
+++ llvm/trunk/lib/Analysis/InlineCost.cpp	2016/11/14 11:14:41	286814
@@ -1255,7 +1255,9 @@
       Cost -= InlineConstants::InstrCost;
     }
   }
-
+  // The call instruction also disappears after inlining.
+  Cost -= InlineConstants::InstrCost + InlineConstants::CallPenalty;
+  
   // If there is only one call of the function, and it has internal linkage,
   // the cost of inlining it drops dramatically.
   bool OnlyOneCallAndLocalLinkage =

But the patch did not update Inliner code:

shouldBeDeferred(Function *Caller, CallSite CS, InlineCost IC,
...
  // FIXME: All of this logic should be sunk into getInlineCost. It relies on
  // FIXME: All of this logic should be sunk into getInlineCost. It relies on
  // the internal implementation of the inline cost metrics rather than
  // treating them as truly abstract units etc.
  TotalSecondaryCost = 0;
  // The candidate cost to be imposed upon the current function.
  int CandidateCost = IC.getCost() - (InlineConstants::CallPenalty + 1);

As a result CallPenalty is subtracted twice.

The current patch fixes the issue.

I'd like to thank Easwaran who noticed the issue.

Event Timeline

eastig created this revision.Mar 20 2017, 9:54 AM
This revision was automatically updated to reflect the committed changes.