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

    <tr>
        <th>Summary</th>
        <td>
            [SPIR-V] Tablegen instruction selection in SPIR-V Backend doesn't account for a pointer size of the target
        </td>
    </tr>

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

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

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

<pre>
    SPIR-V Backend uses notion of a pointer size of the target, most notably, in legalizer code, but Tablegen instruction selection in SPIR-V Backend doesn't account for a pointer size of the target. This leads to crashes in spirv64 environment (-mtriple=spirv64-unknown-unknown), for example, when we are trying to translate G_LOAD. Even worse is that the issue is intertwined with match patterns used for ASSIGN_TYPE pseudo instructions, with register, register classes and register banks. The following example shows a minimal set of instructions that is incompatible with existing approach to Tablegen instruction selection in SPIR-V Backend:

```
%struct = type { [3 x float] }

define spir_kernel void @bar(i1 %sw) {
entry:
  %var1 = alloca %struct
  %var2 = alloca %struct
  %elem1 = getelementptr inbounds [3 x float], ptr %var1, i64 0, i64 0
  %elem2 = getelementptr inbounds [3 x float], ptr %var2, i64 0, i64 1
  %elem = select i1 %sw, ptr %elem1, ptr %elem2
  %res = load float, ptr %elem
  ret void
}
```

Translation of this code would fail either during legalization, or on the instruction selection stage, depending on how we tweaked pre-legalization and on 32/64 choice of the target.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vc2O4zYTfBr60rBhU_LfwYeZ9XqxwOL7FpnBAjkNWmJLYkyRAtmyxvv0ASnNnxMkSA4BDEmkm9VVbHYRQ9C1JTqI9b1YH2fYc-P84ccVy4aCwcs3ulw5nK_XWeHU9fDw_esv8x9wj-WZrII-UADrWDsLrgKEzmnL5CHonxRnuCFg9DWxkJ-gdYFjOBbmGsfagqEajf5JHkqnKE4WPcMjFoZqs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