[llvm] [AMDGPU] Mark the async marker intrinsics nocallback (PR #219099)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 3 03:02:56 PDT 2026
https://github.com/Dewei-Wang-sh updated https://github.com/llvm/llvm-project/pull/219099
>From 1fdffb9859a6bf97c7558244134ee222ceb6c09f Mon Sep 17 00:00:00 2001
From: Dewei Wang <Dewei.Wang at amd.com>
Date: Thu, 27 Aug 2026 03:08:45 +0000
Subject: [PATCH 1/3] [AMDGPU] Mark the async marker intrinsics nocallback
llvm.amdgcn.asyncmark and llvm.amdgcn.wait.asyncmark only set and await a
marker in the stream of async requests. They cannot transfer control out of
the module, so they qualify for nocallback.
Without it, AAAMDGPUMinAGPRAlloc takes its conservative arm for calls that are
not nocallback and reaches a pessimistic fixpoint, so no amdgpu-agpr-alloc
attribute is manifested. getMaxNumVectorRegs then falls back to reserving half
of the vector register file for AGPRs, which halves the arch VGPRs available
to any kernel that uses async LDS copies.
---
llvm/include/llvm/IR/IntrinsicsAMDGPU.td | 5 +++--
.../amdgpu-attributor-asyncmark-leaf.ll | 20 +++++++++++++++++++
2 files changed, 23 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/CodeGen/AMDGPU/amdgpu-attributor-asyncmark-leaf.ll
diff --git a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
index c7bb08bafac4f..36a5cf6c805c4 100644
--- a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
+++ b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
@@ -2933,12 +2933,13 @@ def int_amdgcn_pops_exiting_wave_id :
// Sets a marker in the stream of async requests. Modelled as InaccessibleMem.
def int_amdgcn_asyncmark : ClangBuiltin<"__builtin_amdgcn_asyncmark">,
- Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects]>;
+ Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrNoCallback]>;
// Waits until the Nth previous marker is completed, if it exists.
def int_amdgcn_wait_asyncmark :
ClangBuiltin<"__builtin_amdgcn_wait_asyncmark">,
- Intrinsic<[], [llvm_i16_ty], [ImmArg<ArgIndex<0>>, IntrNoMem, IntrHasSideEffects]>;
+ Intrinsic<[], [llvm_i16_ty],
+ [ImmArg<ArgIndex<0>>, IntrNoMem, IntrHasSideEffects, IntrNoCallback]>;
//===----------------------------------------------------------------------===//
// GFX10 Intrinsics
diff --git a/llvm/test/CodeGen/AMDGPU/amdgpu-attributor-asyncmark-leaf.ll b/llvm/test/CodeGen/AMDGPU/amdgpu-attributor-asyncmark-leaf.ll
new file mode 100644
index 0000000000000..da2781f808e9b
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/amdgpu-attributor-asyncmark-leaf.ll
@@ -0,0 +1,20 @@
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -mcpu=gfx950 -passes=amdgpu-attributor %s | FileCheck %s
+
+; The async marker intrinsics only set/await a marker in the stream of async
+; requests; they cannot transfer control out of the module. Make sure they do
+; not defeat the AGPR allocation inference, which conservatively gives up on
+; any call that is not nocallback.
+
+declare void @llvm.amdgcn.asyncmark()
+
+declare void @llvm.amdgcn.wait.asyncmark(i16 immarg)
+
+; CHECK: define amdgpu_kernel void @asyncmark_kernel({{.*}}) #[[ATTR:[0-9]+]]
+define amdgpu_kernel void @asyncmark_kernel(ptr addrspace(1) %out) {
+ call void @llvm.amdgcn.asyncmark()
+ call void @llvm.amdgcn.wait.asyncmark(i16 0)
+ store i32 0, ptr addrspace(1) %out
+ ret void
+}
+
+; CHECK: attributes #[[ATTR]] = {{{.*}}"amdgpu-agpr-alloc"="0"
>From f50e1113caf3a2e9cfa97014479df44b80fff3f9 Mon Sep 17 00:00:00 2001
From: "Wang, Dewei" <Dewei.Wang at amd.com>
Date: Thu, 27 Aug 2026 13:42:46 +0800
Subject: [PATCH 2/3] Update
llvm/test/CodeGen/AMDGPU/amdgpu-attributor-asyncmark-leaf.ll
Co-authored-by: Harrison Hao <57025411+harrisonGPU at users.noreply.github.com>
---
llvm/test/CodeGen/AMDGPU/amdgpu-attributor-asyncmark-leaf.ll | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/CodeGen/AMDGPU/amdgpu-attributor-asyncmark-leaf.ll b/llvm/test/CodeGen/AMDGPU/amdgpu-attributor-asyncmark-leaf.ll
index da2781f808e9b..879ebd7de00b4 100644
--- a/llvm/test/CodeGen/AMDGPU/amdgpu-attributor-asyncmark-leaf.ll
+++ b/llvm/test/CodeGen/AMDGPU/amdgpu-attributor-asyncmark-leaf.ll
@@ -1,4 +1,4 @@
-; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -mcpu=gfx950 -passes=amdgpu-attributor %s | FileCheck %s
+; RUN: opt -S -mtriple=amdgpu9.50 -passes=amdgpu-attributor %s | FileCheck %s
; The async marker intrinsics only set/await a marker in the stream of async
; requests; they cannot transfer control out of the module. Make sure they do
>From 24a9ab1cf3a7ebf5d044c79164fbd52d157071e2 Mon Sep 17 00:00:00 2001
From: Dewei Wang <Dewei.Wang at amd.com>
Date: Mon, 31 Aug 2026 21:46:29 -0500
Subject: [PATCH 3/3] address review comments
---
llvm/include/llvm/IR/IntrinsicsAMDGPU.td | 6 ++++--
.../test/CodeGen/AMDGPU/amdgpu-attributor-asyncmark-leaf.ll | 4 ----
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
index 36a5cf6c805c4..1781e399a64dd 100644
--- a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
+++ b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
@@ -2933,13 +2933,15 @@ def int_amdgcn_pops_exiting_wave_id :
// Sets a marker in the stream of async requests. Modelled as InaccessibleMem.
def int_amdgcn_asyncmark : ClangBuiltin<"__builtin_amdgcn_asyncmark">,
- Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrNoCallback]>;
+ Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrWillReturn,
+ IntrNoCallback, IntrNoFree]>;
// Waits until the Nth previous marker is completed, if it exists.
def int_amdgcn_wait_asyncmark :
ClangBuiltin<"__builtin_amdgcn_wait_asyncmark">,
Intrinsic<[], [llvm_i16_ty],
- [ImmArg<ArgIndex<0>>, IntrNoMem, IntrHasSideEffects, IntrNoCallback]>;
+ [ImmArg<ArgIndex<0>>, IntrNoMem, IntrHasSideEffects,
+ IntrWillReturn, IntrNoCallback, IntrNoFree]>;
//===----------------------------------------------------------------------===//
// GFX10 Intrinsics
diff --git a/llvm/test/CodeGen/AMDGPU/amdgpu-attributor-asyncmark-leaf.ll b/llvm/test/CodeGen/AMDGPU/amdgpu-attributor-asyncmark-leaf.ll
index 879ebd7de00b4..2dc823f54139c 100644
--- a/llvm/test/CodeGen/AMDGPU/amdgpu-attributor-asyncmark-leaf.ll
+++ b/llvm/test/CodeGen/AMDGPU/amdgpu-attributor-asyncmark-leaf.ll
@@ -5,10 +5,6 @@
; not defeat the AGPR allocation inference, which conservatively gives up on
; any call that is not nocallback.
-declare void @llvm.amdgcn.asyncmark()
-
-declare void @llvm.amdgcn.wait.asyncmark(i16 immarg)
-
; CHECK: define amdgpu_kernel void @asyncmark_kernel({{.*}}) #[[ATTR:[0-9]+]]
define amdgpu_kernel void @asyncmark_kernel(ptr addrspace(1) %out) {
call void @llvm.amdgcn.asyncmark()
More information about the llvm-commits
mailing list