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

    <tr>
        <th>Summary</th>
        <td>
            CoroSplit incorrectly assumed poison after splitting retcon coroutines with zero suspensions
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    As of `cefd20c496`, `CoroSplit` would incorrectly assert that the detached frame buffer to be poisoned for `retcon` coroutines with no suspensions.

Currently I am using this IR.
```llvm
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
declare token @llvm.coro.id.retcon(i32, i32, ptr, ptr, ptr, ptr)
declare ptr @llvm.coro.begin(token, ptr)
declare void @llvm.coro.end(ptr, i1, token)
declare noalias ptr @malloc(i64)
declare void @free(ptr)
define ptr @prototype(ptr dereferenceable(8) %buf, i1 %unwind) {
  ret ptr null
}
define ptr @f(ptr dereferenceable(8) %buf) {
entry:
  ; We can set size to 0 and align to 1 because this coroutine has 0 suspends,
  ; meaning it will always be elided and requires no frame storage.
  %id = call token @llvm.coro.id.retcon(i32 0, i32 1, ptr %buf, ptr @prototype, ptr @malloc, ptr @free)
  %hdl = call ptr @llvm.coro.begin(token %id, ptr %buf)
  
  ; Access the frame (buffer) via handle.
  ; %hdl is equivalent to %buf (dereferenceable(8)).
  ; GEP offset is 1 (4 bytes for i32), so we access bytes 4-7, which is within the 8-byte buffer.
  %val_ptr = getelementptr inbounds i32, ptr %hdl, i64 1
  store i32 42, ptr %val_ptr, align 4
  
 call void @llvm.coro.end(ptr %hdl, i1 false, token none)
  ret ptr null
}
```

I ran `CoroEarly` and `CoroSplit` on it and I spotted a problem.

```sh
opt -passes='coro-early,coro-split' -S repro.ll -o repro_split.ll
```

The problem is with the `poison`

```llvm
define ptr @f(ptr dereferenceable(8) %buf) {
entry:
  ; We can set size to 0 and align to 1 because this coroutine has 0 suspends,
  ; meaning it will always be elided and requires no frame storage.
  %id = call token @llvm.coro.id.retcon(i32 0, i32 1, ptr %buf, ptr @prototype, ptr @malloc, ptr @free)
  br label %AllocaSpillBB

AllocaSpillBB: ; preds = %entry
  br label %PostSpill

PostSpill: ; preds = %AllocaSpillBB
  ; BUG: %hdl replaced by poison instead of %buf,
  ; but %buf should have been used because it has enough frame storage and
  ; it is dereferenceable for 8 bytes.
  %val_ptr = getelementptr inbounds i32, ptr poison, i64 1
  store i32 42, ptr %val_ptr, align 4
  br label %CoroEnd

CoroEnd: ; preds = %PostSpill
  ret ptr null
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsVkGP4ygT_TXkUnJEsOPYhxzS3dOjvo2-_lZ7HGFTjtkh4AXcmcyvXwG2O53pnR3tSntaKXIMpl4V9aoecOfkUSPuyfaObB9WfPS9sXsh9fGr5PrYoWSU1qvGiMv-4MB0QEraYicYbYu6JCUl7D7M3RtrngclPSkpnM2oBEjdGmux9eoC3Dm0HnzPwwNBoOdtjwI6y08Izdh1aMEbaBAGI53R4ZuxAdqib40OuK2xZvRSo4Oz9D1oA250A2onjXZrQg-EHu5Ha1EHp0_ATzA6qY_ge-ng6X9xSUnTT6mXE6EHz-0RPQjuueIXM3og-QMQxjA7kfyA2cB2lOSHnMVHGG7eDsNbWcRHJpeXDatIftiwKusqOr3pOFXO5mWRPYdljL3G4a0cFM4xfK3Kz2WRjfqLNmedKanHr9lRj8lEYKu4RfDmC2ogRdzSOmRpLcV6yhurZM4CS9Pf4O2f_NVXkIO3bwEbPMoAFn29a_JipHhrg1oQVk0u5CY8J_NrO224ktzNLk9cKdOGsMvifQedRZxx0_dO6iXkwRpv_GWYloBAix1a1C3yRoXZirAaCNs2Y5cCC4NRn2UItwayuyP0AGDRR0w9KhXqZvfwna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