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

    <tr>
        <th>Summary</th>
        <td>
            AArch64: extra moves when implementing 128-bit atomic CASP
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:AArch64,
            regalloc
      </td>
    </tr>

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

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

<pre>
    When using `CASP` to implement 128-bit `atomicrmw` operations there are extra moves that could potentially be coalesced.

For example:

```
define fp128 @test_rmw_xchg_f128(fp128* %dst, fp128 %new) {
  %res = atomicrmw xchg fp128* %dst, fp128 %new seq_cst
  ret fp128 %res
}
```

gives (`llc -mtriple=aarch64-apple-ios -mattr=+lse simple.ll -o -`):

```
_test_rmw_xchg_f128:
        sub     sp, sp, #16
        ldp     x4, x5, [x0]
        mov.d   x3, v0[1]
        fmov    x2, d0

LBB0_1:
        mov     x7, x5  // First two are inserting into an xseqpair, issue is liveness across blocks?
        mov     x6, x4
        mov     x5, x7 // Saving input for later compare as `casp` clobbers x4 & x5.
        mov     x4, x6
        caspal  x4, x5, x2, x3, [x0]
        cmp     x5, x7
        ccmp    x4, x6, #0, eq
        b.ne    LBB0_1

        stp     x4, x5, [sp]
        ldr     q0, [sp], #16
        ret
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVMuu4jgQ_RpnUwI5znuRBTRiNRqN1CPNEjlOAZ524lyXA-m_HznhdemraQk5ok75lOvUQxLpU49Ys2zLsl0kR3-2rv77T-v82V7QRY1tf9b_nLGHkXR_Apbzb5vvf7Gcg7egu8Fgh72HWJSrRvuAS287rVx3DU52QCe9tj2BP6NDkA4BJ-8kdPaCwSo9KDuaFgbrsfdaGvMTGgRlpUFS2K4Z3zG-Wc69dYCTDIFZsnlFWM5vv_lvi0fdIxyHWJTAUu6R_MF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