Skip to content

Commit 9a41a80

Browse files
[AMDGPU] Handle object size and bail if assume-like intrinsic is used in PromoteAllocaToVector (#68744)
Attached test will cause crash without this change. We should not remove isAssumeLikeIntrinsic instruction if it is used by other instruction.
1 parent fb51aae commit 9a41a80

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,15 @@ static Value *promoteAllocaUserToVector(
530530
return Builder.CreateVectorSplat(VectorTy->getElementCount(), Elt);
531531
}
532532

533+
if (auto *Intr = dyn_cast<IntrinsicInst>(Inst)) {
534+
if (Intr->getIntrinsicID() == Intrinsic::objectsize) {
535+
Intr->replaceAllUsesWith(
536+
Builder.getIntN(Intr->getType()->getIntegerBitWidth(),
537+
DL.getTypeAllocSize(VectorTy)));
538+
return nullptr;
539+
}
540+
}
541+
533542
llvm_unreachable("Unsupported call when promoting alloca to vector");
534543
}
535544

@@ -773,8 +782,17 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToVector(AllocaInst &Alloca) {
773782
continue;
774783
}
775784

785+
if (auto *Intr = dyn_cast<IntrinsicInst>(Inst)) {
786+
if (Intr->getIntrinsicID() == Intrinsic::objectsize) {
787+
WorkList.push_back(Inst);
788+
continue;
789+
}
790+
}
791+
776792
// Ignore assume-like intrinsics and comparisons used in assumes.
777793
if (isAssumeLikeIntrinsic(Inst)) {
794+
if (!Inst->use_empty())
795+
return RejectUser(Inst, "assume-like intrinsic cannot have any users");
778796
UsersToRemove.push_back(Inst);
779797
continue;
780798
}

llvm/test/CodeGen/AMDGPU/promote-alloca-mem-intrinsics.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ define amdgpu_kernel void @promote_with_objectsize(ptr addrspace(1) %out) #0 {
5353
ret void
5454
}
5555

56+
; CHECK-LABEL: @promote_with_objectsize_8(
57+
; CHECK: store i32 32, ptr addrspace(1) %out, align 4
58+
define amdgpu_kernel void @promote_with_objectsize_8(ptr addrspace(1) %out) #0 {
59+
%alloca = alloca [8 x i32], align 4, addrspace(5)
60+
%size = call i32 @llvm.objectsize.i32.p5(ptr addrspace(5) %alloca, i1 false, i1 false, i1 false)
61+
store i32 %size, ptr addrspace(1) %out
62+
ret void
63+
}
5664
; CHECK-LABEL: @promote_alloca_used_twice_in_memcpy(
5765
; 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)
5866
define amdgpu_kernel void @promote_alloca_used_twice_in_memcpy(i32 %c) {

0 commit comments

Comments
 (0)