<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [AArch64] Wrong code generated (?) for compare_exchange_strong on __int128_t"
   href="https://bugs.llvm.org/show_bug.cgi?id=51102">51102</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[AArch64] Wrong code generated (?) for compare_exchange_strong on __int128_t
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: AArch64
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>efriedma@quicinc.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>arnaud.degrandmaison@arm.com, llvm-bugs@lists.llvm.org, smithp352@googlemail.com, Ties.Stuij@arm.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider:

#include <stdatomic.h>
__int128_t ff(_Atomic __int128_t *p) {
    __int128_t e = 0;
    atomic_compare_exchange_strong(p, &e, 0);
    return e;
}
ff:
        mov     x8, x0
.LBB0_1:
        ldaxp   x0, x1, [x8]
        orr     x9, x0, x1
        cbnz    x9, .LBB0_4
        stlxp   w9, xzr, xzr, [x8]
        cbnz    w9, .LBB0_1
        ret
.LBB0_4:
        clrex
        ret


This sequence is subtly wrong in the case where the cmpxchg fails. 
Specifically, the ldaxp is not single-copy atomic, so the returned value might
tear.  At least, that's my understanding of the rules here.  So we need to
replace the "clrex" with a sequence like "stlxp w9, x0, x1, [x8]; cbnz w9,
.LBB0_1".

Not sure if this sort of tearing can actually happen in practice on commonly
used AArch64 chips.

I'll throw together a patch.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>