Skip to content

Commit cd7985f

Browse files
authored
SPV_KHR_untyped_pointers - fix images translation (#2817)
This patch ensures that we are loading image type, not untyped pointer type when the extension is used. This way we also preserve correct mangling during the reverse translation.
1 parent e3b9ba3 commit cd7985f

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,13 +2218,19 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
22182218
MemoryAccessNoAliasINTELMaskMask);
22192219
if (MemoryAccess.front() == 0)
22202220
MemoryAccess.clear();
2221-
return mapValue(
2222-
V,
2223-
BM->addLoadInst(
2224-
transValue(LD->getPointerOperand(), BB), MemoryAccess, BB,
2225-
BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_untyped_pointers)
2226-
? transType(LD->getType())
2227-
: nullptr));
2221+
if (BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_untyped_pointers)) {
2222+
SPIRVValue *Source = transValue(LD->getPointerOperand(), BB);
2223+
SPIRVType *LoadTy = transType(LD->getType());
2224+
// For images do not use explicit load type, but rather use the source
2225+
// type (calculated in SPIRVLoad constructor)
2226+
if (LoadTy->isTypeUntypedPointerKHR() &&
2227+
(Source->getType()->getPointerElementType()->isTypeImage())) {
2228+
LoadTy = nullptr;
2229+
}
2230+
return mapValue(V, BM->addLoadInst(Source, MemoryAccess, BB, LoadTy));
2231+
}
2232+
return mapValue(V, BM->addLoadInst(transValue(LD->getPointerOperand(), BB),
2233+
MemoryAccess, BB));
22282234
}
22292235

22302236
if (BinaryOperator *B = dyn_cast<BinaryOperator>(V)) {

test/transcoding/get_image_num_mip_levels.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-SPV-IR
99
; RUN: llvm-spirv -spirv-text %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-SPIRV
1010

11+
; RUN: llvm-spirv --spirv-ext=+SPV_KHR_untyped_pointers -spirv-text %t.bc -o - | FileCheck %s --check-prefix=CHECK-SPIRV
12+
; RUN: llvm-spirv --spirv-ext=+SPV_KHR_untyped_pointers %t.bc -o %t.spv
13+
; RUN: spirv-val %t.spv
14+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
15+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
16+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc --spirv-target-env=SPV-IR
17+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-SPV-IR
18+
; RUN: llvm-spirv -spirv-text %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-SPIRV
19+
1120
; Generated from the following OpenCL C code:
1221
; #pragma OPENCL EXTENSION cl_khr_mipmap_image : enable
1322
; void test(image1d_t img1,

test/transcoding/image_with_access_qualifiers.ll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
66
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
77

8+
; RUN: llvm-spirv --spirv-ext=+SPV_KHR_untyped_pointers %t.bc -spirv-text -o %t.txt
9+
; RUN: FileCheck < %t.txt %s --check-prefix=CHECK-SPIRV
10+
; RUN: llvm-spirv --spirv-ext=+SPV_KHR_untyped_pointers %t.bc -o %t.spv
11+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
12+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
13+
814
; NOTE: access qualifier infomation is not preserved after round-trip conversion to LLVM
915
; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef14ocl_image1d_rw11ocl_sampleri(ptr
1016

0 commit comments

Comments
 (0)