Skip to content

Conversation

@arrowd
Copy link
Contributor

@arrowd arrowd commented May 29, 2025

for consistency sake.

@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label May 29, 2025
@llvmbot
Copy link
Member

llvmbot commented May 29, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Gleb Popov (arrowd)

Changes

for consistency sake.


Full diff: https://github.com/llvm/llvm-project/pull/141901.diff

1 Files Affected:

  • (modified) llvm/lib/Analysis/InlineCost.cpp (+7-7)
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index 8ddfa1e4eb6f7..55525be9b6f22 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;
   }
 }
@@ -3040,16 +3040,16 @@ int llvm::getCallsiteCost(const TargetTransformInfo &TTI, const CallBase &Call,
       // DataLayout.
       NumStores = std::min(NumStores, 8U);
 
-      Cost += 2 * NumStores * InstrCost;
+      addCost(2 * NumStores * InstrCost);
     } else {
       // For non-byval arguments subtract off one instruction per call
       // argument.
-      Cost += InstrCost;
+      addCost(InstrCost);
     }
   }
   // The call instruction also disappears after inlining.
-  Cost += InstrCost;
-  Cost += TTI.getInlineCallPenalty(Call.getCaller(), Call, CallPenalty);
+  addCost(InstrCost);
+  addCost(TTI.getInlineCallPenalty(Call.getCaller(), Call, CallPenalty));
 
   return std::min<int64_t>(Cost, INT_MAX);
 }

@arrowd
Copy link
Contributor Author

arrowd commented Jun 16, 2025

May I get attention to this?

@arrowd
Copy link
Contributor Author

arrowd commented Jul 14, 2025

Ping.

@arrowd
Copy link
Contributor Author

arrowd commented Jul 28, 2025

Ping. Let me know if this PR isn't worth merging.

The reason I created it was digging llvm-dev archives and finding a mail describing this issue. It was agreed to be a good fix back then.

@arrowd
Copy link
Contributor Author

arrowd commented Sep 14, 2025

Ping.

@arrowd
Copy link
Contributor Author

arrowd commented Oct 14, 2025

Monthly ping.

@arrowd
Copy link
Contributor Author

arrowd commented Oct 23, 2025

@nikic Sorry for pinging you, but I can't get a feedback on this PR for months. It is trivial and can either be merged quickly, or discarded as not worth merging.

@nikic nikic merged commit 13a40e3 into llvm:main Oct 23, 2025
9 of 10 checks passed
mikolaj-pirog pushed a commit to mikolaj-pirog/llvm-project that referenced this pull request Oct 23, 2025
dvbuka pushed a commit to dvbuka/llvm-project that referenced this pull request Oct 27, 2025
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants