Skip to content

Commit

Permalink
Auto merge of #98675 - eddyb:cg-array-literal, r=nikic
Browse files Browse the repository at this point in the history
rustc_codegen_ssa: use `project_index`, not `project_field`, for array literals.

See #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`
  • Loading branch information
bors committed Jul 7, 2022
2 parents c461f7a + 900309e commit 20dd693
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/rustc_codegen_ssa/src/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 20dd693

Please sign in to comment.