<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/96170>96170</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [SPIR-V] Address space casting via a Generic pointer as an intermediary creates a wrong Generic pointer type
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            VyacheslavLevytskyy
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          VyacheslavLevytskyy
      </td>
    </tr>
</table>

<pre>
    When creating a Generic pointer type as an intermediary for address space casting (https://github.com/llvm/llvm-project/blob/b18bf8faaef952323c96e4c6b82f25623073fb1c/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp#L1061) a wrong type is generated. Namely, the source ptr is treated as if it's a pointee type. We must fetch a pointee type instead first, and use it as a base for creation of a new Generic pointer type.

The next is a reproducer:

```
define spir_kernel void @foo(ptr addrspace(1) %arg) {
entry:
  %p = addrspacecast ptr addrspace(1) %arg to ptr addrspace(3)
  ret void
}
```

spirv-val complain looks like 

```
error: line 28: Expected input and Result Type to point to the same type: PtrCastToGeneric
  %13 = OpPtrCastToGeneric %_ptr_Generic__ptr_CrossWorkgroup_uchar %12
```

As we see a new Generic pointer type points to a pointer and that's wrong.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVF1vozgU_TXOy1UjMB-BBx46zWY10mh3NFO1j9HFXMAbx0a2SYd_v7JJO1U3qrRSBHbu9cHnHPugc3LQRA0rvjDOnxYUIzmFl290Wbw7LQvjnBX7Dc5-NLa50bBpTbc0zyNpEJbQSz0Awp-kyUoBk5HakwW_TAToADXEP87USbQL9MYCdp0l58BNKAgEuojBeDV6PzmW3TN-YPwwSD_O7VaYM-MHpS6vr7vJmn9IeMYPrTJteKVV21c9IvV1wTOeibqkXJRtxXtelDxLdlnfpuIdjgzrHtEOFHB-fv_64-n1_VU7b2fhpdE_SZHwxm7FNDGefUuTMmW8BoQXa_SwspQOhsAePXVb-AvPpBbGH8CPBM7MVhBM3oY2H_SiLugie5Ce8Z0DvGpGEW0LzwTn2XnoyYvxQxWkdp6wg15a58NHUHcwOwLpo9rQoqMo8uqN0WB6QND0ctOiLUv2LLlfn48jgaZfPmwVwdJkTTcLssGRd22sTK6_OO2ol5rATdIeT2Q1KbgY2QHLk94YxqtAPlge7Wa8igoyXqAd4mj3ZQUi7e3y9i0ILROwbP97cTgq8AkcePOfcsZ4_Ypoyce9XXns9jcJrc_A53J3QQXCnCeFUoMy5uRAyRPBJ3qQtSZIBirIwqsw_OPXRCI4L_U0-2jaD3Kz8vAYXA3bDqaEQTw1eF79Dmu_e_uAzj-aq3_v5EmzqM_f08eeUDxO3h6v82OcPFjj3LOxp8GaeTrOYkQbYfgnOtw7eCFwRJ-conXiwvbxrRBI-hHXQx6vy3bTNVlXZzVuqEl3aVVVnJf5ZmzaXVHV2Bdt0Sd1VZRpnfZtses6ygQVgm9kwxOeJyVP0jTd5fm2LDlP-ipr8yRPakxZntAZpdqGC741dthI52Zq6jLdJRuFLSl3Db3AIhavUWebmCrtPDiWJ0o6736jeOlVTMsQDXdPrNjD_c34uki8EYM3EjBeTHJvGXJL0M1sVfO_0zCScowfVtKXhv8bAAD__-7D63Y">