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

    <tr>
        <th>Summary</th>
        <td>
            IR outliner behaves strangely on outlined functions without returns
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:crash,
            llvm:optimizations
      </td>
    </tr>

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

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

<pre>
    The following code crashes the IR outliner in asserts builds:

https://godbolt.org/z/TP1v9WYsr (1)

This was bugpointed from a larger program.

Further reduction gives us this:

https://godbolt.org/z/6Pav4hnfh (2a)
https://godbolt.org/z/j9fWsMGze (2b)

I'm not sure if (2a,b) are over-reduced, but the behaviour is strange. Hopefully they reflect what is going wrong in (1) as well.

In (2a,b), we have identical functions like this:

```
define void @fN() {
bb:
  br label %bb1
bb1:
  br label %bb1
}
```

_Without asserts_, these are outlined and we end up with

```
define void @fN() {
  call void @outlined_ir_func_0()
  ret void
}
```

This seems incorrect, because the original `@fN` _doesn't have a return_.

Also, it seems like the IR outliner misses the first candidate in this case. I would expect

```
define void @f1() {
 call void @outlined_ir_func_0()
}

define void @f2() {
  call void @outlined_ir_func_0()
}

define void @f3() {
  call void @outlined_ir_func_0()
}

define internal void @outlined_ir_func_0() {
  br label %bb_to_outline
bb_to_outline: 
  br label %bb1
bb1:
  br label %bb1
}
```

But instead we don't outline from `@f1` at all (on top of the existing issue with the added `ret` instructions)



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