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

    <tr>
        <th>Summary</th>
        <td>
            Suboptimal code generation for 256-bit integer addition containing constant bits in arm64
        </td>
    </tr>

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

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

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

<pre>
    Hello all,

It seems llc is producing suboptimal code for 256-bit int add when target is arm64.

https://godbolt.org/z/MfEMGKE8n
The command I used is `llc --mtriple=arm64-unknown-unknown -mcpu=neoverse-n1 -O3` (which is also used in the godbolt instance).

The above code evaluates [x3;x2;x1;x0] + [y3;y2;y1;0x1] and stores the results into the memory.

The generated code is
```
        adds    x8, x1, x4
 adcs    x9, x2, x5
        adc     x10, x3, x6
        adds x11, x0, #1
        adcs    x8, x8, xzr
        stp     x11, x8, [x7]
        adcs    x8, x9, xzr
        cinc    x9, x10, hs
 stp     x8, x9, [x7, #16]
        ret
```

.. which doesn't quite seem optimal.
I think it can be further reduced to:
```
adds x15, x0, #1
adcs x16, x1, x2
adcs x17, x3, x4
adc x18, x5, x6
stp x15, x16, [x30]
stp x17, x18, [x30, #16]
``` 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VM1u4zgMfhrlQiSQpdiODz6kk8nuYDHYw-4L6IeNNZWljCS3yTz9QrKnTdtgg4CC_dEfyY8iRYzm5BB7Uj-Q-rASUxp86MXPH5PDlfT62v-J1noQ1hL2hdADofvZfksQEccI1iowEc7B60kZd4I4SX9OZhQWlNcIjz4Aq5u1NAmMSyC0hpcBHSQRTpjyxyKMzXZzSz-kdI6E7wk7EnY8eS29TRsfToQdfxF2_P749fsff33dudn93wFB-XEUTsM3mCLqTEsamrNbr8cUzNki4YcSaT25J-df3O8T1qM6T4QfHPpnDBHXroL135w0FAjbvQxGDSVNG_1C7iANCEteYFxMwikkrHtXRU5LSP-MsxL4LOwkEkYg9cOFE_5wYdlU2VBSH4Cwh4xdM3bN2DVj9FJlMBcXkw8YS_CAcbIpZk19eTHi6MP1UwIndBhEQj0nYeLi0NDlXx5h-QmtYz4vO8K-wKUqdrv4CK1msCuvWbH1RwJVzktFC8yLbe5EuVQze_EjjFefiG4zme2v8N4ppvMSrXrzyuq2pD78L193l08Zp24qnGsYFsneot1QzMGWCppPUQOmu3rPdrOB-XZpj9ER1ib4OZmEZbZgGaOlo98gDcY9gUmghAOJ8DiFNGCAgHpSqCH5PDH3oi161_f0Lrpcquam3-wd0t70cfuKwKXaLf2_aXBW6HecmbJcdfqqy-wwU1a7G4dPCr6WACvdc93xTqywr5q2bhnraroaesSdFCgZ5d2uqdpHirUSSgqBVLacdivTM8o4ZbRhjNc13XBeKd51FZUtk62syZbiKIzdWPs85v2yMjFO2De0bquVFRJtLNuRMSnUEzpN-H6_D2potoSxvDRDn79dy-kUyZZaE1N8Y0smWez_-bASl5E03n3cjnjCkKfDFFB5l4RxeasqX3ZMAmnKzM87czUF23_YlSYNk9woPxJ2zHksx_oc_A9UibBjKTESdixV_hcAAP__F1-57Q">