Skip to content

Commit 900081d

Browse files
wenju-heigcbot
authored andcommitted
Fix SYCL bindless image handle tracing from a call
In O0 mode, integer handle of SYCL bindless image could be retrieved from a function that doesn't handle opaque image type. Therefore, this PR treats return value of a function as a valid source of image handle.
1 parent f3c4356 commit 900081d

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

IGC/Compiler/Optimizer/OCLBIUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static bool isBindlessImageLoad(Value *v)
223223
return false;
224224

225225
auto *ptrOp = load->getPointerOperand()->stripPointerCasts();
226-
if (!isa<Argument>(ptrOp) && !isa<GetElementPtrInst>(ptrOp) && !isa<AllocaInst>(ptrOp))
226+
if (!isa<Argument>(ptrOp) && !isa<GetElementPtrInst>(ptrOp) && !isa<AllocaInst>(ptrOp) && !isa<CallInst>(ptrOp))
227227
return false;
228228

229229
return load->getType()->isIntegerTy(64);
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2023 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; Check image builtin is resolved in the case SYCL bindless image handle is result of a call instruction.
10+
11+
; RUN: igc_opt -igc-conv-ocl-to-common -S %s -o - | FileCheck %s
12+
13+
; CHECK: call <4 x float> @llvm.genx.GenISA.ldptr.v4f32
14+
15+
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32"
16+
target triple = "spir64-unknown-unknown"
17+
18+
%"class.sycl::_V1::range" = type { %"class.sycl::_V1::detail::array" }
19+
%"class.sycl::_V1::detail::array" = type { [1 x i64] }
20+
%class.anon = type { i64, %"class.sycl::_V1::accessor", %"class.sycl::_V1::accessor.3" }
21+
%"class.sycl::_V1::accessor" = type { %"class.sycl::_V1::detail::AccessorImplDevice", %union.anon }
22+
%"class.sycl::_V1::detail::AccessorImplDevice" = type { %"class.sycl::_V1::range", %"class.sycl::_V1::range", %"class.sycl::_V1::range" }
23+
%union.anon = type { i8 addrspace(1)* }
24+
%"class.sycl::_V1::accessor.3" = type { %"class.sycl::_V1::detail::AccessorImplDevice.6", %union.anon }
25+
%"class.sycl::_V1::detail::AccessorImplDevice.6" = type { %"class.sycl::_V1::range.0", %"class.sycl::_V1::range.0", %"class.sycl::_V1::range.0" }
26+
%"class.sycl::_V1::range.0" = type { %"class.sycl::_V1::detail::array.1" }
27+
%"class.sycl::_V1::detail::array.1" = type { [2 x i64] }
28+
%"struct.sycl::_V1::ext::oneapi::experimental::unsampled_image_handle" = type { i64 }
29+
%spirv.Image._void_1_0_0_0_0_0_0 = type opaque
30+
31+
define spir_kernel void @imageHandleFromCall() {
32+
entry:
33+
%agg = alloca %"class.sycl::_V1::range", align 8
34+
%__SYCLKernel = alloca %class.anon, align 8
35+
%imgHandleAcc = getelementptr inbounds %class.anon, %class.anon* %__SYCLKernel, i32 0, i32 1
36+
%0 = call spir_func %"struct.sycl::_V1::ext::oneapi::experimental::unsampled_image_handle" addrspace(1)* @_ZNK4sycl3_V18accessorINS0_3ext6oneapi12experimental22unsampled_image_handleELi1ELNS0_6access4modeE1024ELNS6_6targetE2014ELNS6_11placeholderE0ENS3_22accessor_property_listIJEEEEixILi1EvEERKS5_NS0_2idILi1EEE(%"class.sycl::_V1::accessor"* %imgHandleAcc, %"class.sycl::_V1::range"* %agg)
37+
%raw_handle = getelementptr inbounds %"struct.sycl::_V1::ext::oneapi::experimental::unsampled_image_handle", %"struct.sycl::_V1::ext::oneapi::experimental::unsampled_image_handle" addrspace(1)* %0, i32 0, i32 0
38+
%1 = load i64, i64 addrspace(1)* %raw_handle, align 8
39+
%astype = inttoptr i64 %1 to %spirv.Image._void_1_0_0_0_0_0_0 addrspace(1)*
40+
%2 = ptrtoint %spirv.Image._void_1_0_0_0_0_0_0 addrspace(1)* %astype to i64
41+
%3 = trunc i64 %2 to i32
42+
%call = call spir_func <4 x float> @__builtin_IB_OCL_2d_ld(i32 %3, <2 x i32> zeroinitializer, i32 0)
43+
ret void
44+
}
45+
46+
declare dso_local spir_func %"struct.sycl::_V1::ext::oneapi::experimental::unsampled_image_handle" addrspace(1)* @_ZNK4sycl3_V18accessorINS0_3ext6oneapi12experimental22unsampled_image_handleELi1ELNS0_6access4modeE1024ELNS6_6targetE2014ELNS6_11placeholderE0ENS3_22accessor_property_listIJEEEEixILi1EvEERKS5_NS0_2idILi1EEE(%"class.sycl::_V1::accessor"* align 8, %"class.sycl::_V1::range"* byval(%"class.sycl::_V1::range") align 8)
47+
48+
declare spir_func <4 x float> @__builtin_IB_OCL_2d_ld(i32, <2 x i32>, i32)
49+
50+
!spirv.MemoryModel = !{!0}
51+
!spirv.Source = !{!1}
52+
!spirv.Generator = !{!2}
53+
!igc.functions = !{!3}
54+
!IGCMetadata = !{!5}
55+
!opencl.ocl.version = !{!9}
56+
!opencl.spir.version = !{!9}
57+
58+
!0 = !{i32 2, i32 2}
59+
!1 = !{i32 4, i32 100000}
60+
!2 = !{i16 6, i16 14}
61+
!3 = !{void ()* @imageHandleFromCall, !4}
62+
!4 = !{}
63+
!5 = !{!"ModuleMD", !6}
64+
!6 = !{!"FuncMD", !7, !8}
65+
!7 = !{!"FuncMDMap[130]", void ()* @imageHandleFromCall}
66+
!8 = !{!"FuncMDValue[130]"}
67+
!9 = !{i32 2, i32 0}

0 commit comments

Comments
 (0)