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

    <tr>
        <th>Summary</th>
        <td>
            [SPIR-V] SPIRVGlobalRegistry::createOpType() doesn't ensure that iterator and machine basic block of the insertion point are consistent
        </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>
    One of SYCL CTS cases (group_barrier) fails to build due to inconsistency between iterator and machine basic block of the insertion point inside of SPIRVGlobalRegistry::createOpType(). The result is

```
llc: /localdisk2/vlevytsk/llvm-project/llvm/include/llvm/CodeGen/MachineBasicBlock.h:1020: llvm::MachineBasicBlock::iterator llvm::MachineBasicBlock::insert(iterator, llvm::MachineInstr*): Assertion `(I == end() || I->getParent() == this) && "iterator points outside of basic block"' failed.
```

Triaging shows that while SPIRVGlobalRegistry::createOpType() itself expects that users of this function are to insert definitions at the insertion point set by this utility function (that is always the first MBB), it might happen that the instruction gets relocated along its way through passes. This means that there is no guarantee for SPIRVGlobalRegistry::createOpType() to create a valid insertion point without additional checks before using one of previously stored positions.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVE9v27gT_TT0ZVBDpizZPujgOD8XAVq0aIMAv9OCEsfSbGhS4Izs1bdfUHKSRVNgkQV4meFw_rx5fIaZWo9YqeJOaf00mqZDdubyBS-j8PM4Kq1Vcb8wg3QhVr8JWNTBjtU3jxBO8PP_hy9wePwJjWFkUHrbxjD0f9QmRsKo9A5OhhyDBKgHchbsgMkg3wTPxIK-GaFGuSJ6IMFoJEQw3sLZNB15hNowNVC70DynktIhkGeMQsFDH8hLssnODX1_-PH02YXauB_YEkscVb5X-b6JaAS_9Y9jj0pvld4t4bFDiMiDEyBW2T6dMrudbO9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