diff options
| author | bors <bors@rust-lang.org> | 2023-10-12 18:45:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-10-12 18:45:01 +0000 |
| commit | df4379b4eb5357263f0cf75475953f9b5c48c31f (patch) | |
| tree | 5dcabe4de59bc9ca25a492dd04b2d3ae377e61fe /compiler/rustc_codegen_llvm/src | |
| parent | 672fad9b860c6f2e2b5ca088d7b426099c7198a5 (diff) | |
| parent | f5cdd3e130dce081a72735eeeb0eca283912f48b (diff) | |
Auto merge of #116510 - scottmcm:no-1-simd-v2, r=compiler-errors
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`. Inspired by https://github.com/rust-lang/rust/issues/101210#issuecomment-1732470941, 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.) --- I think I bit off too much in #116479; let me try just the scalar case first. r? `@ghost`
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 |
