about summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2023-05-26 01:23:55 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2023-06-04 00:50:55 -0700
commitcce0b52e7bc7ca2b95fe9f95c8528cd87e787e33 (patch)
treefee9157b8c5dd713999b52d17458a9e32e60e0c5 /tests/codegen
parent9eee230cd0a56bfba3ce65121798d9f9f4341cdd (diff)
downloadrust-cce0b52e7bc7ca2b95fe9f95c8528cd87e787e33.tar.gz
rust-cce0b52e7bc7ca2b95fe9f95c8528cd87e787e33.zip
Add a codegen test for manually swapping a small `Copy` type
To confirm we're not just helping `mem::swap`
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/swap-small-types.rs20
1 files changed, 20 insertions, 0 deletions
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