Skip to content

[AMDGPU] Quit PromoteAllocaToVector if intrinsic is used #68744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,15 @@ static Value *promoteAllocaUserToVector(
return Builder.CreateVectorSplat(VectorTy->getElementCount(), Elt);
}

if (auto *Intr = dyn_cast<IntrinsicInst>(Inst)) {
if (Intr->getIntrinsicID() == Intrinsic::objectsize) {
Intr->replaceAllUsesWith(
Builder.getIntN(Intr->getType()->getIntegerBitWidth(),
DL.getTypeAllocSize(VectorTy)));
return nullptr;
}
}

llvm_unreachable("Unsupported call when promoting alloca to vector");
}

Expand Down Expand Up @@ -773,8 +782,17 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToVector(AllocaInst &Alloca) {
continue;
}

if (auto *Intr = dyn_cast<IntrinsicInst>(Inst)) {
if (Intr->getIntrinsicID() == Intrinsic::objectsize) {
WorkList.push_back(Inst);
continue;
}
}

// Ignore assume-like intrinsics and comparisons used in assumes.
if (isAssumeLikeIntrinsic(Inst)) {
if (!Inst->use_empty())
return RejectUser(Inst, "assume-like intrinsic cannot have any users");
UsersToRemove.push_back(Inst);
continue;
}
Expand Down
8 changes: 8 additions & 0 deletions llvm/test/CodeGen/AMDGPU/promote-alloca-mem-intrinsics.ll
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ define amdgpu_kernel void @promote_with_objectsize(ptr addrspace(1) %out) #0 {
ret void
}

; CHECK-LABEL: @promote_with_objectsize_8(
; CHECK: store i32 32, ptr addrspace(1) %out, align 4
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) {
Expand Down