Skip to content

Commit 15326d5

Browse files
krzysz00shiltian
authored andcommitted
[AMDGPU][LowerBufferFatPointers] Erase dead ptr(7) intrinsics (llvm#160798)
Fix a crash that would arise when intrinsics like llvm.masked.load.T.p7 were left in the module when AMDGPULowerBufferFatPointers was applied and so a captures(none) annotation would be applied to a non-pointer value, triggering a verifier failure. --------- Co-authored-by: Shilei Tian <[email protected]>
1 parent c81df96 commit 15326d5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2562,7 +2562,9 @@ bool AMDGPULowerBufferFatPointers::run(Module &M, const TargetMachine &TM) {
25622562
for (Function *F : NeedsPostProcess)
25632563
Splitter.processFunction(*F);
25642564
for (Function *F : Intrinsics) {
2565-
if (isRemovablePointerIntrinsic(F->getIntrinsicID())) {
2565+
// use_empty() can also occur with cases like masked load, which will
2566+
// have been rewritten out of the module by now but not erased.
2567+
if (F->use_empty() || isRemovablePointerIntrinsic(F->getIntrinsicID())) {
25662568
F->eraseFromParent();
25672569
} else {
25682570
std::optional<Function *> NewF = Intrinsic::remangleIntrinsicFunction(F);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -amdgpu-lower-buffer-fat-pointers < %s | FileCheck %s
2+
; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -passes=amdgpu-lower-buffer-fat-pointers < %s | FileCheck %s
3+
4+
; CHECK: @arbitrary
5+
declare amdgpu_kernel void @arbitrary(ptr addrspace(1))
6+
7+
; COM: This used to cause verifier errors when "lowered"
8+
declare <4 x i8> @llvm.masked.load.v4i8.p7(ptr addrspace(7) captures(none), i32 immarg, <4 x i1>, <4 x i8>)
9+
; CHECK-NOT: llvm.masked.load

0 commit comments

Comments
 (0)