Skip to content
Open
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
12 changes: 12 additions & 0 deletions lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,18 @@ Value *SPIRVToLLVM::transConvertInst(SPIRVValue *BV, Function *F,
CO = Instruction::IntToPtr;
}
break;
// Workaround: OpConvertPtrToU on a target extension type (e.g. spirv.Image)
// is invalid SPIR-V, but is generated by the DPC++ frontend for ESIMD
// get_surface_index() on image accessors.
// Translate as a builtin call (valid LLVM IR) instead of PtrToInt (invalid
// IR). Removing this requires fixing the root cause: either a new SPIR-V
// extension for image-handle-to-index conversion, or redesigning ESIMD
// accessor storage.
case OpConvertPtrToU: {
if (Src->getType()->isTargetExtTy())
return transSPIRVBuiltinFromInst(BC, BB);
[[fallthrough]];
}
default:
CO = static_cast<CastInst::CastOps>(OpCodeMap::rmap(BC->getOpCode()));
}
Expand Down
36 changes: 36 additions & 0 deletions test/workarounds/ptrtoint-target-extension-types.spt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
; RUN: llvm-spirv -spirv-text -r -spirv-target-env=SPV-IR %s -o - | llvm-dis | FileCheck %s --check-prefix=CHECK-LLVM

; The purpose of this test is to validate whether this workaround works fine:

; Workaround: OpConvertPtrToU on a target extension type (e.g. spirv.Image)
; is invalid SPIR-V, but is generated by the DPC++ frontend for ESIMD
; get_surface_index() on image accessors.
; Translate as a builtin call (valid LLVM IR) instead of PtrToInt (invalid
; IR). Removing this requires fixing the root cause: either a new SPIR-V
; extension for image-handle-to-index conversion, or redesigning ESIMD
; accessor storage.

; CHECK-LLVM: = call spir_func i32 @_Z26__spirv_ConvertPtrToU_RintPU3AS133__spirv_Image__void_1_0_0_0_0_0_0(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %0)

119734787 65792 393230 118 0
2 Capability Addresses
2 Capability Linkage
2 Capability Kernel

5 ExtInstImport 1 "OpenCL.std"
3 MemoryModel 2 2
27 EntryPoint 6 35 "_ZTSN4sycl3_V16detail19__pf_kernel_wrapperIZZ4mainENKUlRNS0_7handlerEE_clES4_E4TestEE" 5 6

3 Source 0 100000

4 TypeInt 7 32 0
2 TypeVoid 17
10 TypeImage 32 17 1 0 0 0 0 0 0
4 TypeFunction 34 17 32

5 Function 17 35 0 34
3 FunctionParameter 32 38
2 Label 41
4 ConvertPtrToU 7 66 38
1 Return
1 FunctionEnd
Loading