about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-07-07 12:23:26 +0000
committerbors <bors@rust-lang.org>2022-07-07 12:23:26 +0000
commit20dd6930134d07a5ef90393a040a1594ac8d714c (patch)
treec95234336a79d5d456e8ea20fa2a947ee572c1e0
parentc461f7a16e8372216dbf7a54ab86ee958bec83b5 (diff)
parent900309ec8ae6b717d6dc04778b0e999430fcb4a1 (diff)
downloadrust-20dd6930134d07a5ef90393a040a1594ac8d714c.tar.gz
rust-20dd6930134d07a5ef90393a040a1594ac8d714c.zip
Auto merge of #98675 - eddyb:cg-array-literal, r=nikic
rustc_codegen_ssa: use `project_index`, not `project_field`, for array literals.

See https://github.com/rust-lang/rust/pull/98615#issuecomment-1170082774 for some context.

In short, we were using `project_field` even for array `mir::Rvalue::Aggregate`s, which results in benchmarks like `deep-vector.rs` (and presumably also some real-world usecases?) being impacted by how we handle non-array aggregate fields.

(This is a separate PR so that we can measure the perf effects in isolation)

r? `@nikic`
-rw-r--r--compiler/rustc_codegen_ssa/src/mir/rvalue.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs
index 7ff12823bf7..55ab8b08d4a 100644
--- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs
@@ -123,7 +123,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
                     // Do not generate stores and GEPis for zero-sized fields.
                     if !op.layout.is_zst() {
                         let field_index = active_field_index.unwrap_or(i);
-                        let field = dest.project_field(&mut bx, field_index);
+                        let field = if let mir::AggregateKind::Array(_) = **kind {
+                            let llindex = bx.cx().const_usize(field_index as u64);
+                            dest.project_index(&mut bx, llindex)
+                        } else {
+                            dest.project_field(&mut bx, field_index)
+                        };
                         op.val.store(&mut bx, field);
                     }
                 }