Issue |
139441
|
Summary |
Missed optimization for unaligned store via shifts
|
Labels |
new issue
|
Assignees |
|
Reporter |
0f-0b
|
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).
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs