mozilla/rust — pull request #6724 by thestinger (2013-05-24 21:53:03+00:00)
Title: make the memcpy/memmove intrinsics higher-level

This allows them to make use of the type's alignment, instead of being
pessimistic and assuming it is only 1.

LLVM expects the *minimum* alignment, so passing higher values gives the optimization passes more freedom. This change results in rustc outputting the same post-optimization IR as clang for swaps. Note that this isn't a huge improvement since the swap is *often* inlined deep enough to figure out the alignment without help.

Code snippet:

```rust
#[inline(never)]
fn swap(x: &mut T, y: &mut T) {
util::swap(x, y);
}
```

Original IR:

```llvm
define internal fastcc void @_ZN9swap_283417_a71830ca3ed2d65d3_00E(i64*, i64*) #1 {
static_allocas:
%2 = icmp eq i64* %0, %1
br i1 %2, label %_ZN4util9swap_283717_a71830ca3ed2d65d3_00E.exit, label %3

; :3 ; preds = %static_allocas
%4 = load i64* %0, align 1
%5 = load i64* %1, align 1
store i64 %5, i64* %0, align 1
store i64 %4, i64* %1, align 1
br label %_ZN4util9swap_283717_a71830ca3ed2d65d3_00E.exit

_ZN4util9swap_283717_a71830ca3ed2d65d3_00E.exit: ; preds = %3, %static_allocas
ret void
}
```

After #6710:

```llvm
define internal fastcc void @_ZN9swap_283017_a71830ca3ed2d65d3_00E(i64* nocapture, i64* nocapture) #1 {
static_allocas:
%2 = load i64* %0, align 1
%3 = load i64* %1, align 1
store i64 %3, i64* %0, align 1
store i64 %2, i64* %1, align 1
ret void
}
```

After this change:

```llvm
define internal fastcc void @_ZN9swap_283017_a71830ca3ed2d65d3_00E(i64* nocapture, i64* nocapture) #1 {
static_allocas:
%2 = load i64* %0, align 8
%3 = load i64* %1, align 8
store i64 %3, i64* %0, align 8
store i64 %2, i64* %1, align 8
ret void
}
```