<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/139441>139441</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed optimization for unaligned store via shifts
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
0f-0b
</td>
</tr>
</table>
<pre>
This Rust code, when compiled for `aarch64-unknown-linux-gnu`, generates only one instruction.
```rust
#[inline(never)]
pub fn write(out: &mut [u32; 2], a: u64) {
out[0] = a as u32;
out[1] = (a >> 32) as u32;
}
```
```asm
example::write::h4c19b1f2c54c5627:
str x1, [x0]
ret
```
However, inefficient code is emitted when there are 2 or more `u64`s to store.
```rust
#[inline(never)]
pub fn write2(out: &mut [u32; 4], a: u64, b: u64) {
out[0] = a as u32;
out[1] = (a >> 32) as u32;
out[2] = b as u32;
out[3] = (b >> 32) as u32;
}
```
```asm
example::write2::h650f933056ff8897:
lsr x8, x1, #32
lsr x9, x2, #32
stp w1, w8, [x0]
stp w2, w9, [x0, #8]
ret
```
[Compiler Explorer](https://godbolt.org/z/Y4j5cnovd).
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0VM2u4zYPfRp6QySQKduJFl7k5wbf5tsU3XQp23SsqS0Fkpxk5ukL2fd2LjKDokBbQYBsn0OK5KGpQzBXy1xDeYTynOk5Ds7Xot-IJmtc97X-dTABf5lDxNZ1DHTCx8AWWzfdzMgd9s4jVEJr3w5VsZnt79Y97GY0dn5urnaGSiSjK1v2OnJAZ8ev6CyjsSH6uY3G2S2IQ9qVWLefQ0zvJKE8Gjsay0B7y3f2QArKM4jDbW6wt_jwJibQzRHkAYGqaY4I5XGWBPKIlNh0Qp3QuSqAFMLuCOKAmGzKo4DyjCDPqFEHXM0-wfkHDLTXCPIN5BtKSn4-02F3_pzBS0I6TCAO_NTTbWSQB5CHNfDlcSjaXDV5T21ZtGVFu_Q5RbCuED0-85QElMenWNP_AD3HH-_9n3ustTqhsdz3pjVsVwXRBOTJxMjdqmQc2DNqz0joPE7OcxI0laoSAaPDEJ3nfyoR_YVGxQ8anbD5j_X6oNMHvfkpLD95a_5t9eld_qoUvZJSlFXf7_fqRf4xeHzuU03em4CkpBc8radaOPQzToi35XwsHh7712b6E1-sH-o7vjrb_42mg_J4WqeCx7fnbXSe_SLsfojxFlJSdAG6XF3XuDFunb8CXb4BXX4rvpStdfcOSKU-y7padkoqnXGd74pKFUqRzIa62e8aUbTU9lVDeduqSvGOKlkVinVV6MzUJKgUZZ6LXUlCblVXVbpUPVctsypKKARP2ozbcbxPKYTMhDBznUtVFHk26obHsExDIssPXFCg1CWZr5PRppmvAQoxmhDDdzfRxJHr_5sQuEN3i2Yy33SabcuEnK0e06Dt1p8J70ZjGEwfQzb7sX4pkInD3GxbNwFd0gXvx-bm3RduI9BlCSsAXd7jvtf0RwAAAP__jn6ZtQ">