[llvm] [Analysis] Use the addCost() helper across InlineCost.cpp (PR #141901)

Gleb Popov via llvm-commits llvm-commits at lists.llvm.org
Wed May 28 23:31:05 PDT 2025


https://github.com/arrowd updated https://github.com/llvm/llvm-project/pull/141901

>From 94833a5a950640d89d2c1b3bd8538c72422a14cf Mon Sep 17 00:00:00 2001
From: Gleb Popov <6yearold at gmail.com>
Date: Thu, 29 May 2025 09:21:08 +0300
Subject: [PATCH] [Analysis] Use the addCost() helper across InlineCost.cpp for
 consistency sake

---
 llvm/lib/Analysis/InlineCost.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index 8ddfa1e4eb6f7..4f2786efe5600 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -717,7 +717,7 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
       if (CA.analyze().isSuccess()) {
         // We were able to inline the indirect call! Subtract the cost from the
         // threshold to get the bonus we want to apply, but don't go below zero.
-        Cost -= std::max(0, CA.getThreshold() - CA.getCost());
+        addCost(-std::max(0, CA.getThreshold() - CA.getCost()));
       }
     } else
       // Otherwise simply add the cost for merely making the call.
@@ -1116,7 +1116,7 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
     // If this function uses the coldcc calling convention, prefer not to inline
     // it.
     if (F.getCallingConv() == CallingConv::Cold)
-      Cost += InlineConstants::ColdccPenalty;
+      addCost(InlineConstants::ColdccPenalty);
 
     LLVM_DEBUG(dbgs() << "      Initial cost: " << Cost << "\n");
 
@@ -2126,7 +2126,7 @@ void InlineCostCallAnalyzer::updateThreshold(CallBase &Call, Function &Callee) {
   // the cost of inlining it drops dramatically. It may seem odd to update
   // Cost in updateThreshold, but the bonus depends on the logic in this method.
   if (isSoleCallToLocalFunction(Call, F)) {
-    Cost -= LastCallToStaticBonus;
+    addCost(-LastCallToStaticBonus);
     StaticBonusApplied = LastCallToStaticBonus;
   }
 }



More information about the llvm-commits mailing list