<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64050>64050</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
aarch64 NEON redundant displaced ld3
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
neldredge
</td>
</tr>
</table>
<pre>
Given the following C code, compiled on aarch64 with `-O3`:
``` C
#include <stdint.h>
void CSI2toBE12(uint8_t* pCSI2, uint8_t* pBE, uint8_t* pCSI2LineEnd)
{
while (pCSI2 < pCSI2LineEnd) {
pBE[0] = pCSI2[0];
pBE[1] = ((pCSI2[2] & 0xf) << 4) | (pCSI2[1] >> 4);
pBE[2] = ((pCSI2[1] & 0xf) << 4) | (pCSI2[2] >> 4);
pCSI2 += 3;
pBE += 3;
}
}
```
[Try on godbolt](https://godbolt.org/z/KG8eq4vjq)
In the inner loop (line 53 of the asm on godbolt) we have the following:
```
sub x16, x13, #1
ld3 { v0.16b, v1.16b, v2.16b }, [x16]
ld3 { v3.16b, v4.16b, v5.16b }, [x13], #48
```
The second load is redundant. After these instructions, v3 = v1 and v4 = v2. v5 is different but it is not used by the subsequent code.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVMmO4zYQ_RrqUmiBizYfdGh5GQwSzBwy94ASyxYHNOkWKbk7Xx-Qdm8eZzEMs1T1WK_49EzpvT5YxJaUHSk3mZzD6KbWolETqgNmvVMv7Re9oIUwIuydMe6s7QHWMDiFhMf1eNIGFTgLUk7DWBVw1mEEUtGH74JUlIhHQjeEPsY4fWF9TXCh7WBmhUDE2gelbchHIraX8uK0gvUfX3lw3ZZxwptZ29D8GQh_hFMsxAE-5rrtbSaiftcWt1YRvrrS1t0lAAA4j9ogEN4kaJzjdhN8wsdP5Ck7SsoNELG5jnJJEHEXy16xhDevXKTseErzCujzPjGJdRyguLCu4QP02mFLxDbV_4GI3ydi_5-I_yfRRSjeRRpxb447RVJvXsXf3Ljh-lh2P6aX6KKDU70zIYrJmzGEk48O4jvCd9dS7qYD4bu_CN_99qXBp2L5-fT-dtPv14tjtbU4gXHuFI9otEUoBbh9Kkp__MjHV3BGGOWCn83-q38_H9jPfVqfWRXd98xEXAgX7DPOKJFWUnew0JxVfcQt7C3iMUpKxf1lFxuWm39pIt62Fm9R-UsTkZRMExXN3ZP8GBE8Ds4qME4q0B4mVLNV0oYc4HEfcIqa-CioD9M8BO2sT3wiuW1hIK2Cpbg88RxgKWMfpfd7nNAG6OcAOsScdQFmjwr6l6S0n3uPT3MExVslB8hUK9RKrGSGLatWlBWiLFk2tlLKuuqbhg4MRVVX9V5WTNFVXTPZF0JluuWUC1pzwSlbMZYXtRgapkrEoiwayklB8Si1yY1ZjtFImfZ-xrYqaEkzI3s0Pt2HnFs8QyoSHv8U2dTGPQ_9fPCkoEb74N-7BB0Mtq834Lft92_vGoLS_mTkgCq-v2yeTHvjax3Guc8HdyR8F1tel4fT5H7iEAjfpUE84bs06N8BAAD__4FcjW4">