Skip to content

Commit fe3fffa

Browse files
committed
Amortize growing rev_locals.
1 parent 3dc9956 commit fe3fffa

File tree

1 file changed

+7
-1
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+7
-1
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,15 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
291291
let (index, new) = self.values.insert_full(value);
292292
let index = VnIndex::from_usize(index);
293293
if new {
294+
// Grow `evaluated` and `rev_locals` here to amortize the allocations.
294295
let evaluated = self.eval_to_const(index);
295296
let _index = self.evaluated.push(evaluated);
296297
debug_assert_eq!(index, _index);
298+
// No need to push to `rev_locals` if we finished listing assignments.
299+
if self.next_opaque.is_some() {
300+
let _index = self.rev_locals.push(SmallVec::new());
301+
debug_assert_eq!(index, _index);
302+
}
297303
}
298304
index
299305
}
@@ -330,7 +336,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
330336
let is_sized = !self.feature_unsized_locals
331337
|| self.local_decls[local].ty.is_sized(self.tcx, self.param_env);
332338
if is_sized {
333-
self.rev_locals.ensure_contains_elem(value, SmallVec::new).push(local);
339+
self.rev_locals[value].push(local);
334340
}
335341
}
336342

0 commit comments

Comments
 (0)