Skip to content
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

Fix OpGroupAsyncCopy used with SPV_KHR_untyped_pointers #2819

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
26 changes: 24 additions & 2 deletions lib/SPIRV/SPIRVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,8 @@ SPIRVType *LLVMToSPIRVBase::transPointerType(SPIRVType *ET, unsigned AddrSpc) {
return transPointerType(ET, SPIRAS_Private);
if (BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_untyped_pointers) &&
!(ET->isTypeArray() || ET->isTypeVector() || ET->isTypeStruct() ||
ET->isTypeImage() || ET->isTypeSampler() || ET->isTypePipe())) {
ET->isTypeImage() || ET->isTypeSampler() || ET->isTypePipe() ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess we should merge #2820 first, right?

ET->isTypeEvent())) {
TranslatedTy = BM->addUntypedPointerKHRType(
SPIRSPIRVAddrSpaceMap::map(static_cast<SPIRAddressSpace>(AddrSpc)));
} else {
Expand Down Expand Up @@ -2486,7 +2487,8 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,

if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(V)) {
auto *PointerOperand = GEP->getPointerOperand();
std::vector<SPIRVWord> Ops = {transValue(PointerOperand, BB)->getId()};
auto *SPVPointerOperand = transValue(PointerOperand, BB);
std::vector<SPIRVWord> Ops = {SPVPointerOperand->getId()};
for (unsigned I = 0, E = GEP->getNumIndices(); I != E; ++I)
Ops.push_back(transValue(GEP->getOperand(I + 1), BB)->getId());

Expand Down Expand Up @@ -2536,7 +2538,15 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
PtrTy = transType(TPT->getElementType());
Ops = getVec(PtrTy->getId(), Ops);
}
} else if (SPVPointerOperand->getType()->isTypeUntypedPointerKHR()) {
// TranslatedTy defines whether ptr access chain instruction would be
// typed or untyped.
// Ensure that we don't create typed ptr access chain instruction with
// untyped pointer as an operand.
Ops[0] = BM->addUnaryInst(OpBitcast, TranslatedTy, SPVPointerOperand, BB)
->getId();
}

return mapValue(
V, BM->addPtrAccessChainInst(TranslatedTy, Ops, BB, GEP->isInBounds()));
}
Expand Down Expand Up @@ -6363,6 +6373,18 @@ LLVMToSPIRVBase::transBuiltinToInstWithoutDecoration(Op OC, CallInst *CI,
} break;
case OpGroupAsyncCopy: {
auto BArgs = transValue(getArguments(CI), BB);
// Check that type of Source and Destination are the same, bitcast if not
// (this mostly needed for untyped pointers)
SPIRVType *SrcTy = BArgs[1]->getType();
SPIRVType *DstTy = BArgs[2]->getType();
if (SrcTy->getPointerElementType() != DstTy->getPointerElementType()) {
llvm::Type *Ty = Scavenger->getScavengedType(CI->getOperand(2));
if (auto *TPT = dyn_cast<TypedPointerType>(Ty)) {
SPIRVType *PtrTy =
transPointerType(TPT->getElementType(), TPT->getAddressSpace());
BArgs[2] = BM->addUnaryInst(OpBitcast, PtrTy, BArgs[2], BB);
}
}
return BM->addAsyncGroupCopy(BArgs[0], BArgs[1], BArgs[2], BArgs[3],
BArgs[4], BArgs[5], BB);
} break;
Expand Down
9 changes: 9 additions & 0 deletions test/transcoding/OpGroupAsyncCopy.ll
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
; RUN: llvm-spirv -r --spirv-target-env=SPV-IR %t.spv -o %t.rev.bc
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-SPV-IR

; RUN: llvm-spirv %t.bc -spirv-text -o %t.txt --spirv-ext=+SPV_KHR_untyped_pointers
; RUN: FileCheck < %t.txt %s --check-prefix=CHECK-SPIRV
; RUN: llvm-spirv %t.bc -o %t.spv --spirv-ext=+SPV_KHR_untyped_pointers
; RUN: spirv-val %t.spv
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
; RUN: llvm-spirv -r --spirv-target-env=SPV-IR %t.spv -o %t.rev.bc
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-SPV-IR

; CHECK-LLVM: call spir_func ptr @_Z29async_work_group_strided_copyPU3AS1Dv2_hPU3AS3KS_jj9ocl_event(
; CHECK-LLVM: call spir_func void @_Z17wait_group_eventsiPU3AS49ocl_event(
; CHECK-LLVM: declare spir_func ptr @_Z29async_work_group_strided_copyPU3AS1Dv2_hPU3AS3KS_jj9ocl_event(ptr addrspace(1), ptr addrspace(3), i32, i32, ptr)
Expand Down
Loading