-
Notifications
You must be signed in to change notification settings - Fork 12.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #116479 - scottmcm:no-1-simd, r=<try>
Copy 1-/2-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`. And treat `[T; 2]` as a scalar pair (like `(T, T)`) when copying it. Inspired by #101210 (comment), which pointed out that `Option<[u8; 1]>` was codegenning worse than `Option<u8>`. (I'm not sure *why* LLVM doesn't optimize out `<1 x u8>`, but might as well just not emit it in the first place in this codepath.)
- Loading branch information
Showing
5 changed files
with
89 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// assembly-output: emit-asm | ||
// compile-flags: --crate-type=lib -O -C llvm-args=-x86-asm-syntax=intel | ||
// only-x86_64 | ||
// ignore-sgx | ||
|
||
// This is emitted in a way that results in two loads and two stores in LLVM-IR. | ||
// Confirm that that doesn't mean 4 instructions in assembly. | ||
|
||
// CHECK-LABEL: array_copy_2_elements: | ||
#[no_mangle] | ||
pub fn array_copy_2_elements(a: &[u8; 2], p: &mut [u8; 2]) { | ||
// CHECK-NOT: byte | ||
// CHECK-NOT: mov | ||
// CHECK: mov{{.+}}, word ptr | ||
// CHECK-NEXT: mov word ptr | ||
// CHECK-NEXT: ret | ||
*p = *a; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 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: %[[TEMP1:.+]] = load i8, ptr %a, align 1 | ||
// CHECK: %[[TEMP2:.+]] = load i8, ptr | ||
// CHECK: store i8 %[[TEMP1]], ptr %p, align 1 | ||
// CHECK: store i8 %[[TEMP2]], ptr | ||
// 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; | ||
} |