about summary refs log tree commit diff
path: root/tests/codegen/array-optimized.rs
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2023-10-06 01:17:09 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2023-10-07 00:10:32 -0700
commitae9cec58394d7a38aac17e2873d213d5fcd85f7a (patch)
tree694b6a4b46ac6aefff6c1c6e85478270ea0ffa0b /tests/codegen/array-optimized.rs
parent579be69de9f98f56d92b93820eaf7e6b06b517a5 (diff)
downloadrust-ae9cec58394d7a38aac17e2873d213d5fcd85f7a.tar.gz
rust-ae9cec58394d7a38aac17e2873d213d5fcd85f7a.zip
Copy 1-element arrays as scalars, not vectors
For `[T; 1]` it's silly to copy as `<1 x T>` when we can just copy as `T`.
Diffstat (limited to 'tests/codegen/array-optimized.rs')
-rw-r--r--tests/codegen/array-optimized.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/codegen/array-optimized.rs b/tests/codegen/array-optimized.rs
new file mode 100644
index 00000000000..27448fdcfad
--- /dev/null
+++ b/tests/codegen/array-optimized.rs
@@ -0,0 +1,33 @@
+// compile-flags: -O
+
+#![crate_type = "lib"]
+
+// CHECK-LABEL: @array_copy_1_element
+#[no_mangle]
+pub fn array_copy_1_element(a: &[u8; 1], p: &mut [u8; 1]) {
+    // CHECK-NOT: alloca
+    // CHECK: %[[TEMP:.+]] = load i8, ptr %a, align 1
+    // CHECK: store i8 %[[TEMP]], ptr %p, align 1
+    // CHECK: ret
+    *p = *a;
+}
+
+// CHECK-LABEL: @array_copy_2_elements
+#[no_mangle]
+pub fn array_copy_2_elements(a: &[u8; 2], p: &mut [u8; 2]) {
+    // CHECK-NOT: alloca
+    // CHECK: %[[TEMP:.+]] = load <2 x i8>, ptr %a, align 1
+    // CHECK: store <2 x i8> %[[TEMP]], ptr %p, align 1
+    // CHECK: ret
+    *p = *a;
+}
+
+// CHECK-LABEL: @array_copy_4_elements
+#[no_mangle]
+pub fn array_copy_4_elements(a: &[u8; 4], p: &mut [u8; 4]) {
+    // CHECK-NOT: alloca
+    // CHECK: %[[TEMP:.+]] = load <4 x i8>, ptr %a, align 1
+    // CHECK: store <4 x i8> %[[TEMP]], ptr %p, align 1
+    // CHECK: ret
+    *p = *a;
+}