[llvm-branch-commits] [llvm] [NFC][AMDGPU] Don't create call site AACallEdges for direct calls (PR #237633)

Shilei Tian via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Nov 1 10:16:05 PST 2026


https://github.com/shiltian updated https://github.com/llvm/llvm-project/pull/237633

>From 800aeded33c65c0cd627fd10aa7e6bea16405d16 Mon Sep 17 00:00:00 2001
From: Shilei Tian <i at tianshilei.me>
Date: Sat, 31 Oct 2026 16:18:08 -0400
Subject: [PATCH] [NFC][AMDGPU] Don't create call site AACallEdges for direct
 calls

AAAMDGPUMinAGPRAlloc and AAAMDGPUNoLDSDMA asked for a call site AACallEdges for
every call that is not an intrinsic, only to get its callees. For a direct call
whose callee has no callback metadata, that callee is the only one, so use it
directly, like AACallEdgesFunction does since #232616. Calls to callback brokers
still use AACallEdges, because thebroker also calls the callback target.

On a generated module with 2,001 functions and 15,986 calls,
-passes=amdgpu-attributor creates 2,001 instead of 11,987 abstract attributes,
and the median wall time goes from 95 ms to 84 ms.

This PR was assisted by AI but I reviewed all the changes.
---
 llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp | 63 ++++++++++++---------
 1 file changed, 36 insertions(+), 27 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
index c9068c7a3766cd..f149ce8d377b60 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
@@ -1307,6 +1307,26 @@ static unsigned inlineAsmGetNumRequiredAGPRs(const InlineAsm *IA,
   return std::min(MaxVirtReg + MaxPhysReg, 256u);
 }
 
+/// Call \p Pred on each function that \p CB may call. Return false if a callee
+/// is unknown, or if \p Pred returns false for a callee.
+static bool
+checkForAllPossibleCallees(Attributor &A, const AbstractAttribute &QueryingAA,
+                           const CallBase &CB,
+                           function_ref<bool(const Function &)> Pred) {
+  // A direct call without callbacks only calls its callee, so it does not need
+  // a call site AACallEdges.
+  auto *Callee = dyn_cast<Function>(CB.getCalledOperand());
+  if (Callee && !Callee->hasMetadata(LLVMContext::MD_callback))
+    return Pred(*Callee);
+
+  const AACallEdges *CBEdges = A.getAAFor<AACallEdges>(
+      QueryingAA, IRPosition::callsite_function(CB), DepClassTy::REQUIRED);
+  if (!CBEdges || CBEdges->hasUnknownCallee())
+    return false;
+  return all_of(CBEdges->getOptimisticEdges(),
+                [&](const Function *Fn) { return Pred(*Fn); });
+}
+
 struct AAAMDGPUMinAGPRAlloc
     : public StateWrapper<DecIntegerState<>, AbstractAttribute> {
   using Base = StateWrapper<DecIntegerState<>, AbstractAttribute>;
@@ -1398,22 +1418,18 @@ struct AAAMDGPUMinAGPRAlloc
       }
 
       // TODO: Handle callsite attributes
-      auto *CBEdges = A.getAAFor<AACallEdges>(
-          *this, IRPosition::callsite_function(CB), DepClassTy::REQUIRED);
-      if (!CBEdges || CBEdges->hasUnknownCallee()) {
-        Maximum.indicatePessimisticFixpoint();
-        return false;
-      }
-
-      for (const Function *PossibleCallee : CBEdges->getOptimisticEdges()) {
-        const auto *CalleeInfo = A.getAAFor<AAAMDGPUMinAGPRAlloc>(
-            *this, IRPosition::function(*PossibleCallee), DepClassTy::REQUIRED);
-        if (!CalleeInfo || !CalleeInfo->isValidState()) {
-          Maximum.indicatePessimisticFixpoint();
+      auto CheckCallee = [&](const Function &Callee) {
+        const AAAMDGPUMinAGPRAlloc *CalleeInfo =
+            A.getAAFor<AAAMDGPUMinAGPRAlloc>(
+                *this, IRPosition::function(Callee), DepClassTy::REQUIRED);
+        if (!CalleeInfo || !CalleeInfo->isValidState())
           return false;
-        }
-
         Maximum.takeAssumedMaximum(CalleeInfo->getAssumed());
+        return true;
+      };
+      if (!checkForAllPossibleCallees(A, *this, CB, CheckCallee)) {
+        Maximum.indicatePessimisticFixpoint();
+        return false;
       }
 
       return true;
@@ -1492,19 +1508,12 @@ struct AAAMDGPUNoLDSDMA : public StateWrapper<BooleanState, AbstractAttribute> {
                CB.hasFnAttr(Attribute::NoCallback);
       }
 
-      const auto *CBEdges = A.getAAFor<AACallEdges>(
-          *this, IRPosition::callsite_function(CB), DepClassTy::REQUIRED);
-      if (!CBEdges || CBEdges->hasUnknownCallee())
-        return false;
-
-      for (const Function *PossibleCallee : CBEdges->getOptimisticEdges()) {
-        const auto *CalleeInfo = A.getAAFor<AAAMDGPUNoLDSDMA>(
-            *this, IRPosition::function(*PossibleCallee), DepClassTy::REQUIRED);
-        if (!CalleeInfo || !CalleeInfo->getAssumed())
-          return false;
-      }
-
-      return true;
+      return checkForAllPossibleCallees(
+          A, *this, CB, [&](const Function &Callee) {
+            const AAAMDGPUNoLDSDMA *CalleeInfo = A.getAAFor<AAAMDGPUNoLDSDMA>(
+                *this, IRPosition::function(Callee), DepClassTy::REQUIRED);
+            return CalleeInfo && CalleeInfo->getAssumed();
+          });
     };
 
     bool UsedAssumedInformation = false;



More information about the llvm-branch-commits mailing list