[PATCH] D152049: [Inline][PGO] Skip block-frequency weighted simplified instructions in the callee when computing cycle savings

Mingming Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 2 19:16:03 PDT 2023


mingmingl created this revision.
Herald added subscribers: wlei, ChuanqiXu, wenlei, haicheng, hiraditya.
Herald added a project: All.
mingmingl requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152049

Files:
  llvm/lib/Analysis/InlineCost.cpp


Index: llvm/lib/Analysis/InlineCost.cpp
===================================================================
--- llvm/lib/Analysis/InlineCost.cpp
+++ llvm/lib/Analysis/InlineCost.cpp
@@ -831,10 +831,8 @@
     BlockFrequencyInfo *CalleeBFI = &(GetBFI(F));
     assert(CalleeBFI);
 
-    // The cycle savings expressed as the sum of InstrCost
-    // multiplied by the estimated dynamic count of each instruction we can
-    // avoid.  Savings come from the call site cost, such as argument setup and
-    // the call instruction, as well as the instructions that are folded.
+    // The cycle savings expressed as savings come from the call site cost, such as argument setup and
+    // the call instruction.
     //
     // We use 128-bit APInt here to avoid potential overflow.  This variable
     // should stay well below 10^^24 (or 2^^80) in practice.  This "worst" case
@@ -843,36 +841,6 @@
     // period on a 4GHz machine.
     APInt CycleSavings(128, 0);
 
-    for (auto &BB : F) {
-      APInt CurrentSavings(128, 0);
-      for (auto &I : BB) {
-        if (BranchInst *BI = dyn_cast<BranchInst>(&I)) {
-          // Count a conditional branch as savings if it becomes unconditional.
-          if (BI->isConditional() &&
-              isa_and_nonnull<ConstantInt>(
-                  SimplifiedValues.lookup(BI->getCondition()))) {
-            CurrentSavings += InstrCost;
-          }
-        } else if (Value *V = dyn_cast<Value>(&I)) {
-          // Count an instruction as savings if we can fold it.
-          if (SimplifiedValues.count(V)) {
-            CurrentSavings += InstrCost;
-          }
-        }
-      }
-
-      auto ProfileCount = CalleeBFI->getBlockProfileCount(&BB);
-      CurrentSavings *= *ProfileCount;
-      CycleSavings += CurrentSavings;
-    }
-
-    // Compute the cycle savings per call.
-    auto EntryProfileCount = F.getEntryCount();
-    assert(EntryProfileCount && EntryProfileCount->getCount());
-    auto EntryCount = EntryProfileCount->getCount();
-    CycleSavings += EntryCount / 2;
-    CycleSavings = CycleSavings.udiv(EntryCount);
-
     // Compute the total savings for the call site.
     auto *CallerBB = CandidateCall.getParent();
     BlockFrequencyInfo *CallerBFI = &(GetBFI(*(CallerBB->getParent())));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152049.528065.patch
Type: text/x-patch
Size: 2270 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230603/1de29df4/attachment.bin>


More information about the llvm-commits mailing list