[llvm] [AMDGPU] Skip pointer users with no uses when preloading kernel args (PR #216281)
Arseniy Obolenskiy via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 14 02:02:40 PDT 2026
https://github.com/aobolensk created https://github.com/llvm/llvm-project/pull/216281
A dead GEP has no users, so dereferencing user_begin() looking for a load hits the end iterator and asserts
>From 74b4a91a960162a7934b7484674c1c04849651ed Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Fri, 14 Aug 2026 11:02:01 +0200
Subject: [PATCH] [AMDGPU] Skip pointer users with no uses when preloading
kernel args
A dead GEP has no users, so dereferencing user_begin() looking for a load hits the end iterator and asserts
---
.../AMDGPU/AMDGPUPreloadKernelArguments.cpp | 3 ++-
.../preload-implicit-kernargs-IR-lowering.ll | 18 ++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPreloadKernelArguments.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPreloadKernelArguments.cpp
index 7d6e3edc75e1f..caad246b4ff7f 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPreloadKernelArguments.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPreloadKernelArguments.cpp
@@ -203,7 +203,8 @@ class PreloadKernelArgInfo {
int64_t Offset = 0;
auto *Load = dyn_cast<LoadInst>(U); // Load from ImplicitArgPtr?
if (!Load) {
- if (GetPointerBaseWithConstantOffset(U, Offset, DL) != CI)
+ if (U->user_empty() ||
+ GetPointerBaseWithConstantOffset(U, Offset, DL) != CI)
continue;
Load = dyn_cast<LoadInst>(*U->user_begin()); // Load from GEP?
diff --git a/llvm/test/CodeGen/AMDGPU/preload-implicit-kernargs-IR-lowering.ll b/llvm/test/CodeGen/AMDGPU/preload-implicit-kernargs-IR-lowering.ll
index 86b17eac16344..defb5296c33b2 100644
--- a/llvm/test/CodeGen/AMDGPU/preload-implicit-kernargs-IR-lowering.ll
+++ b/llvm/test/CodeGen/AMDGPU/preload-implicit-kernargs-IR-lowering.ll
@@ -217,6 +217,24 @@ define amdgpu_kernel void @incompatible_attribute_block_count_x(ptr addrspace(1)
ret void
}
+define amdgpu_kernel void @preload_hidden_arg_dead_gep() {
+; NO-PRELOAD-LABEL: define amdgpu_kernel void @preload_hidden_arg_dead_gep(
+; NO-PRELOAD-SAME: ) #[[ATTR0]] {
+; NO-PRELOAD-NEXT: [[IMP_ARG_PTR:%.*]] = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
+; NO-PRELOAD-NEXT: [[GEP:%.*]] = getelementptr i8, ptr addrspace(4) [[IMP_ARG_PTR]], i64 12
+; NO-PRELOAD-NEXT: ret void
+;
+; PRELOAD-LABEL: define amdgpu_kernel void @preload_hidden_arg_dead_gep(
+; PRELOAD-SAME: ) #[[ATTR0]] {
+; PRELOAD-NEXT: [[IMP_ARG_PTR:%.*]] = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
+; PRELOAD-NEXT: [[GEP:%.*]] = getelementptr i8, ptr addrspace(4) [[IMP_ARG_PTR]], i64 12
+; PRELOAD-NEXT: ret void
+;
+ %imp_arg_ptr = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
+ %gep = getelementptr i8, ptr addrspace(4) %imp_arg_ptr, i64 12
+ ret void
+}
+
;.
; NO-PRELOAD: [[META0]] = !{}
;.
More information about the llvm-commits
mailing list