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

    <tr>
        <th>Summary</th>
        <td>
            [AMDGPU] Wrong O0 codegen for workgroup id x + control flow
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:AMDGPU
      </td>
    </tr>

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

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

<pre>
    I tried to narrow down what the OpenMP AMDGPU bugs are all about, the ones that do not make sense. Unrelated changes cause it to pass or fail. Anyhow, I stumbled upon something interesting that I think is broken. I have a runnable reproducer but it's a little tricky (I use the JIT to splice in the IR). Anyhow, here is what I think should suffice, I hope, to see a problem. That is, for someone that actually understands AMDGCN.

In the attached zip file is a good.ll and a broken.ll. I got the respective .s files with `llc -O0`.
In my experiments, good.ll will not run into the trap, broken.ll will.
The trap should not execute, assuming I didn't break stuff doing the manual reduction.
The initial code asserted that `workgroup.id.x < workgroup.size.x`.
However, when I store away the latter in the broken version, I get 0, in the good version I get 256.

I think the underlying problem is some value propagation along the control edges.
If I store `%i15 (workgroup.size.x)` in `%bb` I get 256, if I do it in `%bb194` I get 0, the same value that triggers my trap in the broken case.

@arsenm @nhaehnle Help appreciated.

[amdgpu_backend_bug.zip](https://github.com/llvm/llvm-project/files/10859017/amdgpu_backend_bug.zip)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVUtv2zgX_TX05qICRVlytPAibZCv_oBOi0GLWRZX4pXEmiIFPqy4v35A-pEEg1nMJpGl-zjn3MNL9F6NhmjP6o-sftpgDJN1-1_SkhvIhU1n5Xl_gOAUSQgWDDpnV5B2NbBOGCBMBF8XMl--weOXp_99-wFdHD2gI0CtATsbAxOfcpw15CGkLGnB2AAzHgk8GU8F_DCONAaS0E9oRvLQY_QEKqS-C3oP1sGAShfwaM6TXVPZA_gQ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