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

    <tr>
        <th>Summary</th>
        <td>
            Miscompile of atomic rmw or on x86 (not on aarch, though)
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          lovely-error
      </td>
    </tr>
</table>

<pre>
    Recently I wrote one little piece of code that gave me too much headache. After investigation, I discovered that on x86 the sequence of instructions that llvm (strangely, GCC as well) produces is invalid because after applying optimisations, atomicity of load gets elided. You can witness that llvm makes up bunch of nonsense [here](https://godbolt.org/z/Thfeq1KGW). There you can find c code and if you compile it with recent llvm to aarch, `atomic_fetch_or_explicit` gets translated to a loop of a pair of special load-store instructions which is correct lowering, but if you do it for x86, you can in fact witness that generated code does not contain `lock or ...` instruction, which would be correct code, but instead `lock cmpxchg ...` which is invalid.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxck0-PnDgQxT-NuZQG0abphgOHZKKOotVeVpFWexoZu8DeGBexi-7p_fQrw0znzwkku6p-79WzSslNAbEXzUfRfCrUypZi7-mK_v6EMVIsBjL3_i_UGNjf4QvcIjECBQTvmD3C4lAj0AiaDAJbxTCpK8KMwEQwr9qCRWWUtljCh5ExggtXTOwmxY6CkM_wBYxLmq4Y0ew9KMBrewK2CAm_rxj2IS4kjqvOdWm_6P11BiHbxFGFCf099_v8_AwqwQ29F7KDJZJZNSZwKc9W3hkYUKs1IaiNSC2Lv7swAS3sZpc2spRbKabZacf3PN6TMjAhJ0DvDJoS_qEVtApwcxww_cw0q2-YYF1gWIO2uTpQSBgSgmg-Wowomk9CtpZ5SaL-IORFyMtEZiDPJcVJyMt_Ql6-2hG_H_74_LeQXQlfcyHc36aOLhjQu_UqGHDjfkTz4jyC48xlIW7727GYQKmobdYmTtUu72VE1vaF4gu-Lj7LFadqF5ptTV5xXgyBAk-0ZDEKFuVi_ksLaqf8Zs5TYor465pu1mmbrdcUI2oGTzeMLkwZYVj5ndpQBh4p5s3ns3eVLsCoNP_q8YQB44a1qTeECQIxaAqsXMjaPOlvQBHKssxyfoLK3XesG60-h-EBl7s9wEJiVObRS8_Lq7bTe8OHsLdMlYXpa9PVnSqwP5y686npzmdZ2H6QnVENtsPRaFVV7dBVdSeboT6f2vFQycL1spL1oTq0sqq6uipb7KoDDsf6cBxV15zFscJZOV_mJeZ0FC6lFftT11Rt4dWAPr2_49jnS0_DOiVxrLxLnH6UsWOP_Z_5ue0hybvcQgBxvmW73p6ekG32k8KPvLCldbJCdsUaff9bcB3bdSg1zUJe8rS3z9MS6V_ULORlI05CXjbo_wMAAP__aZGKmA">