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

    <tr>
        <th>Summary</th>
        <td>
            [AMDGPU] Invalid removal of convergence on atomic store
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:AMDGPU,
            llvm:optimizations
      </td>
    </tr>

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

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

<pre>
    The GPU backend relies on convergent attributes to prevent optimizations that change dependencies on control flow. In this example, we wish to acquire a lock on a per-wavefront basis https://godbolt.org/z/W1vE15G8v. The control flow is important here, when run with two threads on the GPU, the expected masking behavior would be the following:
```
mask 01: open(); close();
mask 10: open(); close();
```
Which should be legal as the operations within a wave are executed in lock-step according to their mask. However, the optimizer will sink the call to `close()` to a common branch, changing the control flow:
```
mask 01: open();
mask 10: open();
mask 11: close();
```
This will then deadlock because we have two `open()` calls that mutually depend on each other.

This occurs when we remove the `convergent` attribute on the `close()` call, as shown in https://godbolt.org/z/W7Ks3qda5 in the IR. To solve this problem we will most likely require the convergence tokens as discussed in https://discourse.llvm.org/t/rfc-introduce-convergence-control-intrinsics/69613/3.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVU2P2zYQ_TX0ZWBDoizFOvjgxHW6KAoUxRY5U-TIZExxFJKysvn1BWntrncLtClgwJbm682bN2MRgjk7xD2rP7L6uBJT1OT3X_XUoW9WHamn_aNG-PzHX9AJeUGnwKM1GIAcSHJX9Gd0EUSM3nRTxACRYPR4TW9pjGYwP0Q05AJELSJILdwZQeGITqGTr6miJwu9pXkDDw6iNgHwuxhGi4x_ghlhNkGn7EJ-m4xHEGBJXlK0gBH9ehZX7D25CJ0IJoCOcQysOjB-Yvx0JtWRjRvyZ8ZPPxg_fSmvv5T15911A6nHewhgAphhJB-Fi6DR3zBodOAnB7OJGuJMEL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