Skip to content

Commit cce0b52

Browse files
committed
Add a codegen test for manually swapping a small Copy type
To confirm we're not just helping `mem::swap`
1 parent 9eee230 commit cce0b52

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Diff for: tests/codegen/swap-small-types.rs

+20
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,30 @@ use std::mem::swap;
88

99
type RGB48 = [u16; 3];
1010

11+
// CHECK-LABEL: @swap_rgb48_manually(
12+
#[no_mangle]
13+
pub fn swap_rgb48_manually(x: &mut RGB48, y: &mut RGB48) {
14+
// CHECK-NOT: alloca
15+
// CHECK: %temp = alloca [3 x i16]
16+
// CHECK-NOT: alloca
17+
// CHECK-NOT: call void @llvm.memcpy
18+
// CHECK: call void @llvm.memcpy.{{.+}}({{.+}} %temp, {{.+}} %x, {{.+}} 6, {{.+}})
19+
// CHECK: call void @llvm.memcpy.{{.+}}({{.+}} %x, {{.+}} %y, {{.+}} 6, {{.+}})
20+
// CHECK: call void @llvm.memcpy.{{.+}}({{.+}} %y, {{.+}} %temp, {{.+}} 6, {{.+}})
21+
// CHECK-NOT: call void @llvm.memcpy
22+
23+
let temp = *x;
24+
*x = *y;
25+
*y = temp;
26+
}
27+
1128
// CHECK-LABEL: @swap_rgb48
1229
#[no_mangle]
1330
pub fn swap_rgb48(x: &mut RGB48, y: &mut RGB48) {
1431
// FIXME MIR inlining messes up LLVM optimizations.
32+
// If these checks start failing, please update this test.
33+
// CHECK: alloca [3 x i16]
34+
// CHECK: call void @llvm.memcpy
1535
// WOULD-CHECK-NOT: alloca
1636
// WOULD-CHECK: load i48
1737
// WOULD-CHECK: store i48

0 commit comments

Comments
 (0)