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

    <tr>
        <th>Summary</th>
        <td>
            [SPIR-V] Non-logical pointer generated following an ptrcast
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            SPIR-V
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            Keenuts
      </td>
    </tr>

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

<pre>
    Logical SPIR-V is not allowing pointer cast after an `OpAccessChain`.

Given this LLVM IR:
```llvm
define internal spir_func void @baz(ptr addrspace(10) %a, i64 %b) {
  %index = getelementptr <4 x i32>, ptr addrspace(10) %a, i64 %b
 %load = load <3 x i32>, ptr addrspace(10) %index, align 4
  ret void
}
```

In OpenCL SPIR-V, the following instructions would be generated:

```
    %index_1 = OpAccessChain %_ptr_Private_v4uint %a_1
 %28 = OpBitcast %_ptr_Private_v3uint %index_1
    %loadv_1 = OpLoad %v3uint %28 Aligned 4
```

This is not allowed in logical SPIR-V.

For this specific case, what we'd need is to load the initial `<4 x i32>`, then `OpCompositeExtract` and then `OpCompositeConstruct`.

If the types were of the same bit-size, we could to the `OpBitcast`, but on the value after the load.
For other types of cast, we might have to handle this differently (loading the initial member of a struct for ex).
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVE2P4zYM_TXKhUhgS87XwYdMZlMMmnYX22KvgWzRtgpFMiQ6mdlfX0hRNjPtHhYwYJkWH8nHR8oQdG8Ra7Z8Ypz_jmgnCoxztnyeyYkG5-tsnDVOvdVH1-tWGvjry8vX-TfQAawjkMa4q7Y9jE5bQg-tDASyi0dpga2Kz-OubTGE_SC1ZatiwYodK3a_6QtaoEEHOB6__QEvX5mIdrYqbo8xlzMrdgo7bRESuJUGwqj9qZtsCxenFbCqaOR3xjcjeZBK-TDKFhnflAXjW2B8KRnfg15V8dwk2_qJFTuI39oq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