diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-10-06 01:17:09 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-10-07 00:10:32 -0700 |
| commit | ae9cec58394d7a38aac17e2873d213d5fcd85f7a (patch) | |
| tree | 694b6a4b46ac6aefff6c1c6e85478270ea0ffa0b /compiler/rustc_codegen_llvm/src | |
| parent | 579be69de9f98f56d92b93820eaf7e6b06b517a5 (diff) | |
| download | rust-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 'compiler/rustc_codegen_llvm/src')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/type_of.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs index dcc62d314ff..fd4c9572af2 100644 --- a/compiler/rustc_codegen_llvm/src/type_of.rs +++ b/compiler/rustc_codegen_llvm/src/type_of.rs @@ -397,7 +397,12 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { // extracts all the individual values. let ety = element.llvm_type(cx); - return Some(cx.type_vector(ety, *count)); + if *count == 1 { + // Emitting `<1 x T>` would be silly; just use the scalar. + return Some(ety); + } else { + return Some(cx.type_vector(ety, *count)); + } } // FIXME: The above only handled integer arrays; surely more things |
