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

    <tr>
        <th>Summary</th>
        <td>
            gvn-hoist hoists uses of inline assembly results before inline assembly
        </td>
    </tr>

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

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

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

<pre>
    llvm commit: f4a78830b80
Reproduce with
```opt -passes=gvn-hoist bbi-79336_2.ll -o /dev/null```
Result:
```
Instruction does not dominate all uses!
 %0 = callbr { i32, i32 } asm sideeffect "somestuff", "=r,=r,!i"()
 to label %asm.fallthrough [label %err.split]
  %asmresult = extractvalue { i32, i32 } %0, 0
LLVM ERROR: Broken module found, compilation aborted!
```
So gvn-hoist has hoisted the use of %0 before the definition of %0:
```
  %asmresult = extractvalue { i32, i32 } %0, 0
  %0 = callbr { i32, i32 } asm sideeffect "somestuff", "=r,=r,!i"()
          to label %asm.fallthrough [label %err.split]
```
The input in bbi-79336_2.ll is what we get from clang nowadays after 329ef60f3e2
```
[Clang] support for outputs along indirect edges of asm goto

Initial support for asm goto w/ outputs (D69876) only supported outputs
along the "default" (aka "fallthrough") edge.

We can support outputs along all edges by repeating the same pattern of
stores along the indirect edges that we allready do for the default
edge.  One complication is that these indirect edges may be critical
edges which would need to be split. Another issue is that mid-codgen of
LLVM IR, the control flow graph might not reflect the control flow of
the final function.

To avoid this "chicken and the egg" problem assume that any given
indirect edge may become a critical edge, and pro-actively split it.
This is unnecessary if the edge does not become critical, but LLVM will
optimize such cases via tail duplication.

Fixes: https://github.com/llvm/llvm-project/issues/53562

Reviewed By: void

Differential Revision: https://reviews.llvm.org/D136497
```
[bbi-79336_2.ll.gz](https://github.com/llvm/llvm-project/files/10838440/bbi-79336_2.ll.gz)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.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