Skip to content

Commit

Permalink
Add a codegen test for manually swapping a small Copy type
Browse files Browse the repository at this point in the history
To confirm we're not just helping `mem::swap`
  • Loading branch information
scottmcm committed Jun 4, 2023
1 parent 9eee230 commit cce0b52
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/codegen/swap-small-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,30 @@ use std::mem::swap;

type RGB48 = [u16; 3];

// CHECK-LABEL: @swap_rgb48_manually(
#[no_mangle]
pub fn swap_rgb48_manually(x: &mut RGB48, y: &mut RGB48) {
// CHECK-NOT: alloca
// CHECK: %temp = alloca [3 x i16]
// CHECK-NOT: alloca
// CHECK-NOT: call void @llvm.memcpy
// CHECK: call void @llvm.memcpy.{{.+}}({{.+}} %temp, {{.+}} %x, {{.+}} 6, {{.+}})
// CHECK: call void @llvm.memcpy.{{.+}}({{.+}} %x, {{.+}} %y, {{.+}} 6, {{.+}})
// CHECK: call void @llvm.memcpy.{{.+}}({{.+}} %y, {{.+}} %temp, {{.+}} 6, {{.+}})
// CHECK-NOT: call void @llvm.memcpy

let temp = *x;
*x = *y;
*y = temp;
}

// CHECK-LABEL: @swap_rgb48
#[no_mangle]
pub fn swap_rgb48(x: &mut RGB48, y: &mut RGB48) {
// FIXME MIR inlining messes up LLVM optimizations.
// If these checks start failing, please update this test.
// CHECK: alloca [3 x i16]
// CHECK: call void @llvm.memcpy
// WOULD-CHECK-NOT: alloca
// WOULD-CHECK: load i48
// WOULD-CHECK: store i48
Expand Down

0 comments on commit cce0b52

Please sign in to comment.