Skip to content

Commit 20dd693

Browse files
committed
Auto merge of rust-lang#98675 - eddyb:cg-array-literal, r=nikic
rustc_codegen_ssa: use `project_index`, not `project_field`, for array literals. See rust-lang#98615 (comment) 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`
2 parents c461f7a + 900309e commit 20dd693

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: compiler/rustc_codegen_ssa/src/mir/rvalue.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
123123
// Do not generate stores and GEPis for zero-sized fields.
124124
if !op.layout.is_zst() {
125125
let field_index = active_field_index.unwrap_or(i);
126-
let field = dest.project_field(&mut bx, field_index);
126+
let field = if let mir::AggregateKind::Array(_) = **kind {
127+
let llindex = bx.cx().const_usize(field_index as u64);
128+
dest.project_index(&mut bx, llindex)
129+
} else {
130+
dest.project_field(&mut bx, field_index)
131+
};
127132
op.val.store(&mut bx, field);
128133
}
129134
}

0 commit comments

Comments
 (0)