<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/152863>152863</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SPIR-V] Invalid OpPhi lowering
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
simeonschaub
</td>
</tr>
</table>
<pre>
`phi_node_issue.ll`:
```llvm
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"
target triple = "spirv64-unknown-unknown-unknown"
declare i64 @_Z14atomic_cmpxchgPU8CLglobalVlll(ptr addrspace(1), i64, i64)
define spir_kernel void @_Z3foo13CLDeviceArrayI5Int64Li0ELi1EE(ptr addrspace(1) %0) {
conversion:
br label %L6
L6: ; preds = %L6, %conversion
%value_phi = phi i64 [ 0, %conversion ], [ %1, %L6 ]
%1 = call i64 @_Z14atomic_cmpxchgPU8CLglobalVlll(ptr addrspace(1) %0, i64 %value_phi, i64 0)
br label %L6
}
```
Compiling with `llc -filetype=obj phi_node_issue.ll -o phi_node_issue.spv, I get the following SPIR-V:
```llvm
; SPIR-V
; Version: 1.4
; Generator: LLVM LLVM SPIR-V Backend; 20
; Bound: 34
; Schema: 0
OpCapability Kernel
OpCapability Addresses
OpCapability Int64
%1 = OpExtInstImport "OpenCL.std"
OpMemoryModel Physical64 OpenCL
OpEntryPoint Kernel %_Z3foo13CLDeviceArrayI5Int64Li0ELi1EE "_Z3foo13CLDeviceArrayI5Int64Li0ELi1EE"
OpExecutionMode %_Z3foo13CLDeviceArrayI5Int64Li0ELi1EE ContractionOff
OpSource OpenCL_CPP 100000
OpName %_Z3foo13CLDeviceArrayI5Int64Li0ELi1EE "_Z3foo13CLDeviceArrayI5Int64Li0ELi1EE"
OpName %conversion "conversion"
OpName %value_phi "value_phi"
OpName %L6 "L6"
%ulong = OpTypeInt 64 0
%_ptr_CrossWorkgroup_ulong = OpTypePointer CrossWorkgroup %ulong
%void = OpTypeVoid
%uint = OpTypeInt 32 0
%8 = OpConstantNull %ulong
%9 = OpTypeFunction %void %_ptr_CrossWorkgroup_ulong
%uint_0 = OpConstant %uint 0
%uint_2 = OpConstant %uint 2
%_Z3foo13CLDeviceArrayI5Int64Li0ELi1EE = OpFunction %void None %9
%13 = OpFunctionParameter %_ptr_CrossWorkgroup_ulong
%conversion = OpLabel
OpBranch %L6
%L6 = OpLabel
%value_phi = OpPhi %ulong %8 %conversion %15 %L6
%15 = OpAtomicCompareExchange %uint %13 %uint_2 %uint_0 %uint_0 %8 %value_phi
OpBranch %L6
OpFunctionEnd
```
Running `spirv-val phi_node_issue.spv` then errors with:
```
error: line 26: OpPhi's result type <id> '4[%ulong]' does not match incoming value <id> '15[%15]' type <id> '7[%uint]'.
%value_phi = OpPhi %ulong %8 %conversion %15 %L6
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVttu2zgQ_Rr6hZBBURfLD37wJSmMdRuj3c0C-2LQEm2xoUiBpJT47xdDyZfYbjdFNzBKlTxzeDgz5AyzVuwV5xOUzFCyGLDGldpMrKi4VjYvWbMdbHVxmKCU1KXYKF3wjbC24UMpUUpQNEXE_1LS_aRsK0Smjpk9d7hgjkl20I3DKFpgRCkPRBqjaJrGQRumKJqGadBSmIlo0Ea0_4izHjP2GJoFbTiGRZoAPkmPn0kIs0lIgzYkngeG4FOIKD3rcEbUkh812FqYNo2DRr0o_aqux84SkWnBc8kMxyKNMYrJ5p8wZk5XIt_kVf2Wl_v1X9l8tZd6y-SzlBLRrHYGs6IwtmY5RzQLER0jOgeK0zA-su-E4hjEbF64UVziVoui2ynaaR1G89WCtyLnU2PYYZkslUvjlSAPKxE-PPxgN4xoQvw4miEyzbVqubFCqy5WGG8NlmzLJQBXaadlBf7EKJrh2vDC9o6CZTqHjwsWoEA0aZls-KYuhcfC6L2UzDC5scEoWfjJZAYLY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