Skip to content

Commit e9ebfa5

Browse files
vmaksimojsji
authored andcommitted
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. Original commit: KhronosGroup/SPIRV-LLVM-Translator@cd7985fb6d2589d
1 parent 7be620b commit e9ebfa5

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,13 +2226,19 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
22262226
MemoryAccessNoAliasINTELMaskMask);
22272227
if (MemoryAccess.front() == 0)
22282228
MemoryAccess.clear();
2229-
return mapValue(
2230-
V,
2231-
BM->addLoadInst(
2232-
transValue(LD->getPointerOperand(), BB), MemoryAccess, BB,
2233-
BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_untyped_pointers)
2234-
? transType(LD->getType())
2235-
: nullptr));
2229+
if (BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_untyped_pointers)) {
2230+
SPIRVValue *Source = transValue(LD->getPointerOperand(), BB);
2231+
SPIRVType *LoadTy = transType(LD->getType());
2232+
// For images do not use explicit load type, but rather use the source
2233+
// type (calculated in SPIRVLoad constructor)
2234+
if (LoadTy->isTypeUntypedPointerKHR() &&
2235+
(Source->getType()->getPointerElementType()->isTypeImage())) {
2236+
LoadTy = nullptr;
2237+
}
2238+
return mapValue(V, BM->addLoadInst(Source, MemoryAccess, BB, LoadTy));
2239+
}
2240+
return mapValue(V, BM->addLoadInst(transValue(LD->getPointerOperand(), BB),
2241+
MemoryAccess, BB));
22362242
}
22372243

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

llvm-spirv/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,

llvm-spirv/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)