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

    <tr>
        <th>Summary</th>
        <td>
            [AArch64][CodeGen]: LD{AX}P/S{LX}TP endian swap 
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Consider the following code (https://godbolt.org):
```
volatile __int128 a;
a = 1;
```
which emits a store pair on AArch64 when compiled to target a big-endian system:
```
stp     x9, xzr, [x8]
```
such that the contents of x9 (containing 1) are stored in the lower 64-bits, and zero is stored in the higher 64-bits. This means the order that data is stored is flipped on a big endian system.

Removing `volatile` in the above example flips the order bits are stored for big-endian:
```
stp xzr, x9, [x8]
```
likewise marking `a` as `_Atomic` acts like `volatile` as it is marked as volatile internally by LLVM (https://godbolt.org/z/osT1Wfez5):
```
stp     x9, xzr, [x8]
```
According to the Arm pseudocode (https://developer.arm.com/documentation/ddi0596/2021-06/Base-Instructions/STP--Store-Pair-of-Registers-) the order in which the 128-bits is stored is flipped only if the access type is not `BigEndian(AccType_NORMAL)`. 

Further this seems to effect load-acquire-exclusive and store-release exclusive pairs in compare and swap loops too (https://godbolt.org/z/7fjMxvoE7):
```
.LBB0_1: // =>This Inner Loop Header: Depth=1
        ldaxp   xzr, x10, [x9]
        stlxp   w10, x8, xzr, [x9]
        cbnz    w10, .LBB0_1
```

My understanding of this is that the endianness for big-endian systems is flipped.


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVU1z4zYP_jX0BSOPPmzZOvggr9fvuzNOm9nNtL1lKBKyuEuRKkn5I7--A8mOkzSbth6PJJAACDx4AHLv1d4grth8zeabCe9DY91K9z9wn8TJpLLyvPpkjVcSHYQGobZa26MyexBWIrB02YTQeZaVLN2ydLu3srI6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