KhronosGroup / SPIRV-LLVM-Translator

A tool and a library for bi-directional translation between SPIR-V and LLVM IR
Other
486 stars 218 forks source link

Translation of OpenCL atomics #1075

Open maleadt opened 3 years ago

maleadt commented 3 years ago

I'm using the translator to compile LLVM with OpenCL intrinsics into SPIR-V for use with the oneAPI stack. My front-end is also using (mostly) typeless pointers, something that LLVM is probably going to switch to at some point in the future. Calls to e.g. atomic_add using i32 data look as follow:

%4 = call i32 @_Z10atomic_addPU8CLglobalVii(i8 addrspace(1)* %3, i32 %1)

Unmangled, this is atomic_add(int volatile CLglobal*, int).

In the emitted SPIR-V code, it looks like the OpAtomicIAdd has retained the meaningless (typelss pointer) i8:

%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%uint_2 = OpConstant %uint 2
%22 = OpLoad %_ptr_CrossWorkgroup_uchar %21 Aligned 8
%23 = OpAtomicIAdd %uint %22 %uint_2 %uint_0 %15

This in turn makes the Intel compiler choke, because it doesn't have a definition for __builtin_spirv_OpAtomicIAdd_p1i8_i32_i32_i32() (due to the i8 in there).

Shouldn't the translator ignore the input pointer type and bitcast it, since it knows what the actual type should be from the atomic intrinsic? I guess this would need to happen anyway when pointers become typeless in some distant future.

AGindinson commented 3 years ago

Tagging @haonanya.