[llvm] [AMDGPU] Quit PromoteAllocaToVector if intrinsic is used (PR #68744)

Mariusz Sikora via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 14:04:22 PDT 2023


https://github.com/mariusz-sikora-at-amd created https://github.com/llvm/llvm-project/pull/68744

Attached test will cause crash without this change.

We should not remove isAssumeLikeIntrinsic instruction if it is used by other instruction.

>From 17d62799b3f28eef5fdbe189c89c3dc4b653303b Mon Sep 17 00:00:00 2001
From: Mariusz Sikora <mariusz.sikora at amd.com>
Date: Tue, 10 Oct 2023 21:50:48 +0200
Subject: [PATCH] [AMDGPU] Quit PromoteAllocaToVector if intrinsic is used

Attached test will cause crash without this change.

We should not remove isAssumeLikeIntrinsic instruction if it is
used by other instruction.
---
 llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp           | 3 ++-
 .../test/CodeGen/AMDGPU/promote-alloca-mem-intrinsics.ll | 9 +++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
index 3707a960211eb49..8a25710e46991ba 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
@@ -771,7 +771,8 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToVector(AllocaInst &Alloca) {
     }
 
     // Ignore assume-like intrinsics and comparisons used in assumes.
-    if (isAssumeLikeIntrinsic(Inst)) {
+    // Make sure that intrinsics do not have any use like e.g. llvm.objectsize
+    if (isAssumeLikeIntrinsic(Inst) && Inst->use_empty()) {
       UsersToRemove.push_back(Inst);
       continue;
     }
diff --git a/llvm/test/CodeGen/AMDGPU/promote-alloca-mem-intrinsics.ll b/llvm/test/CodeGen/AMDGPU/promote-alloca-mem-intrinsics.ll
index 0bba1bdce95655b..5616bc0f5ef3c12 100644
--- a/llvm/test/CodeGen/AMDGPU/promote-alloca-mem-intrinsics.ll
+++ b/llvm/test/CodeGen/AMDGPU/promote-alloca-mem-intrinsics.ll
@@ -53,6 +53,15 @@ define amdgpu_kernel void @promote_with_objectsize(ptr addrspace(1) %out) #0 {
   ret void
 }
 
+; CHECK-LABEL: @promote_with_objectsize_8(
+; CHECK: [[PTR:%[0-9]+]] = getelementptr inbounds [64 x [8 x i32]], ptr addrspace(3) @promote_with_objectsize_8.alloca, i32 0, i32 %{{[0-9]+}}
+; CHECK: call i32 @llvm.objectsize.i32.p3(ptr addrspace(3) [[PTR]], i1 false, i1 false, i1 false)
+define amdgpu_kernel void @promote_with_objectsize_8(ptr addrspace(1) %out) #0 {
+  %alloca = alloca [8 x i32], align 4, addrspace(5)
+  %size = call i32 @llvm.objectsize.i32.p5(ptr addrspace(5) %alloca, i1 false, i1 false, i1 false)
+  store i32 %size, ptr addrspace(1) %out
+  ret void
+}
 ; CHECK-LABEL: @promote_alloca_used_twice_in_memcpy(
 ; CHECK: call void @llvm.memcpy.p3.p3.i64(ptr addrspace(3) align 8 dereferenceable(16) %arrayidx1, ptr addrspace(3) align 8 dereferenceable(16) %arrayidx2, i64 16, i1 false)
 define amdgpu_kernel void @promote_alloca_used_twice_in_memcpy(i32 %c) {



More information about the llvm-commits mailing list