[llvm-branch-commits] [llvm] [AMDGPU] caller/callee scratch awareness in adjustInliningThreshold (PR #227792)

Janek van Oirschot via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Oct 2 05:02:29 PDT 2026


================
@@ -1758,6 +1758,13 @@ unsigned GCNTTIImpl::adjustInliningThreshold(const CallBase *CB) const {
   unsigned AllocaSize = getCallArgsTotalAllocaSize(CB, DL);
   if (AllocaSize > 0)
     Threshold += ArgAllocaCost;
+
+  // Making a call from a non-kernel will require saving return address into
+  // scratch. Add a bonus to threshold to discourage scratch use.
+  static const unsigned ScratchBonus = 200;
----------------
JanekvO wrote:

> What is the reasoning behind the constant value?

I am a bit unsatisfied with the answer: the value covers the specific device side assert case. I initially took the same addend value as the function arg case but 4000 seemed a bit overkill for this so 200 seemed a bit more reasonable while still covering the device side assert case 😅 

For a bit more context: the inlining cost is computed by adding a instrcost for each instruction in a function (and not counting loop iterations), with some surrounding cost minuses/plusses depending on things like static functions. The threshold, however, is set and then multiplied through some bonuses and then multiplied by 11 for AMDGPU so I'm not sure how to fit that in as a mental model.

https://github.com/llvm/llvm-project/pull/227792


More information about the llvm-branch-commits mailing list