diff --git a/lib/SPIRV/SPIRVWriter.cpp b/lib/SPIRV/SPIRVWriter.cpp index a8320c4d0..197569bd0 100644 --- a/lib/SPIRV/SPIRVWriter.cpp +++ b/lib/SPIRV/SPIRVWriter.cpp @@ -755,7 +755,7 @@ 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->isSPIRVOpaqueType())) { TranslatedTy = BM->addUntypedPointerKHRType( SPIRSPIRVAddrSpaceMap::map(static_cast(AddrSpc))); } else { @@ -2220,11 +2220,11 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB, MemoryAccess.clear(); if (BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_untyped_pointers)) { SPIRVValue *Source = transValue(LD->getPointerOperand(), BB); + SPIRVType *PtrElTy = Source->getType()->getPointerElementType(); SPIRVType *LoadTy = transType(LD->getType()); - // For images do not use explicit load type, but rather use the source - // type (calculated in SPIRVLoad constructor) - if (LoadTy->isTypeUntypedPointerKHR() && - (Source->getType()->getPointerElementType()->isTypeImage())) { + // For special types (images, pipes, etc.) do not use explicit load type, + // but rather use the source type (calculated in SPIRVLoad constructor) + if (LoadTy->isTypeUntypedPointerKHR() && PtrElTy->isSPIRVOpaqueType()) { LoadTy = nullptr; } return mapValue(V, BM->addLoadInst(Source, MemoryAccess, BB, LoadTy)); diff --git a/lib/SPIRV/libSPIRV/SPIRVType.cpp b/lib/SPIRV/libSPIRV/SPIRVType.cpp index 84b6cd6a9..e2d9199d8 100644 --- a/lib/SPIRV/libSPIRV/SPIRVType.cpp +++ b/lib/SPIRV/libSPIRV/SPIRVType.cpp @@ -265,6 +265,14 @@ bool SPIRVType::isTypeVectorOrScalarFloat() const { return isTypeFloat() || isTypeVectorFloat(); } +bool SPIRVType::isSPIRVOpaqueType() const { + return isTypeDeviceEvent() || isTypeEvent() || isTypeImage() || + isTypePipe() || isTypeReserveId() || isTypeSampler() || + isTypeSampledImage() || isTypePipeStorage() || + isTypeCooperativeMatrixKHR() || isTypeJointMatrixINTEL() || + isTypeTaskSequenceINTEL(); +} + bool SPIRVTypeStruct::isPacked() const { return hasDecorate(DecorationCPacked); } diff --git a/lib/SPIRV/libSPIRV/SPIRVType.h b/lib/SPIRV/libSPIRV/SPIRVType.h index a586a997a..66ada436d 100644 --- a/lib/SPIRV/libSPIRV/SPIRVType.h +++ b/lib/SPIRV/libSPIRV/SPIRVType.h @@ -109,6 +109,7 @@ class SPIRVType : public SPIRVEntry { bool isTypeSubgroupAvcINTEL() const; bool isTypeSubgroupAvcMceINTEL() const; bool isTypeTaskSequenceINTEL() const; + bool isSPIRVOpaqueType() const; }; class SPIRVTypeVoid : public SPIRVType { diff --git a/test/extensions/INTEL/SPV_INTEL_task_sequence/task_sequence.ll b/test/extensions/INTEL/SPV_INTEL_task_sequence/task_sequence.ll index d82c316aa..c63cb88cd 100644 --- a/test/extensions/INTEL/SPV_INTEL_task_sequence/task_sequence.ll +++ b/test/extensions/INTEL/SPV_INTEL_task_sequence/task_sequence.ll @@ -7,6 +7,14 @@ ; RUN: llvm-dis %t.rev.bc ; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM +; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_task_sequence,+SPV_KHR_untyped_pointers -o %t.spv +; RUN: llvm-spirv %t.spv -to-text -o %t.spt +; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV + +; RUN: llvm-spirv -r %t.spv -o %t.rev.bc +; RUN: llvm-dis %t.rev.bc +; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM + ; Source SYCL code example ; int mult(int a, int b) { ; return a * b; diff --git a/test/extensions/INTEL/SPV_INTEL_task_sequence/task_sequence_zero_capacity_literals.ll b/test/extensions/INTEL/SPV_INTEL_task_sequence/task_sequence_zero_capacity_literals.ll index 46bf2d25a..f40f5db86 100644 --- a/test/extensions/INTEL/SPV_INTEL_task_sequence/task_sequence_zero_capacity_literals.ll +++ b/test/extensions/INTEL/SPV_INTEL_task_sequence/task_sequence_zero_capacity_literals.ll @@ -7,6 +7,14 @@ ; RUN: llvm-dis %t.rev.bc ; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM +; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_task_sequence,+SPV_KHR_untyped_pointers -o %t.spv +; RUN: llvm-spirv %t.spv -to-text -o %t.spt +; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV + +; RUN: llvm-spirv -r %t.spv -o %t.rev.bc +; RUN: llvm-dis %t.rev.bc +; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM + ; CHECK-SPIRV: TypeInt [[#IntTy:]] 32 0 ; CHECK-SPIRV: TypeTaskSequenceINTEL [[#TypeTS:]] ; CHECK-SPIRV: TypeFunction [[#FuncTy:]] [[#IntTy]] [[#IntTy]] [[#IntTy]] diff --git a/test/transcoding/enqueue_marker.cl b/test/transcoding/enqueue_marker.cl index 0c05205e9..7b652fb26 100644 --- a/test/transcoding/enqueue_marker.cl +++ b/test/transcoding/enqueue_marker.cl @@ -12,6 +12,19 @@ // RUN: llvm-spirv %t.rev.bc -spirv-text -o %t.spv.txt // RUN: FileCheck < %t.spv.txt %s --check-prefix=CHECK-SPIRV +// RUN: llvm-spirv --spirv-ext=+SPV_KHR_untyped_pointers %t.bc -spirv-text -o %t.spv.txt +// RUN: FileCheck < %t.spv.txt %s --check-prefix=CHECK-SPIRV +// RUN: llvm-spirv --spirv-ext=+SPV_KHR_untyped_pointers %t.bc -o %t.spv +// RUN: spirv-val %t.spv +// RUN: llvm-spirv -r %t.spv -o %t.rev.bc +// RUN: llvm-dis %t.rev.bc -o - | 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 -o - | FileCheck %s --check-prefix=CHECK-SPV-IR + +// Check that SPIR-V friendly IR is correctly recognized +// RUN: llvm-spirv --spirv-ext=+SPV_KHR_untyped_pointers %t.rev.bc -spirv-text -o %t.spv.txt +// RUN: FileCheck < %t.spv.txt %s --check-prefix=CHECK-SPIRV + kernel void test_enqueue_marker(global int *out) { queue_t queue = get_default_queue();