From cce0b52e7bc7ca2b95fe9f95c8528cd87e787e33 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Fri, 26 May 2023 01:23:55 -0700 Subject: [PATCH] Add a codegen test for manually swapping a small `Copy` type To confirm we're not just helping `mem::swap` --- tests/codegen/swap-small-types.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/codegen/swap-small-types.rs b/tests/codegen/swap-small-types.rs index 03e2a2327fc..6289d7af3a0 100644 --- a/tests/codegen/swap-small-types.rs +++ b/tests/codegen/swap-small-types.rs @@ -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