Skip to content

Commit 70ee6e4

Browse files
committed
Amortize growing rev_locals.
1 parent 95986dd commit 70ee6e4

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,15 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
293293
let (index, new) = self.values.insert_full(value);
294294
let index = VnIndex::from_usize(index);
295295
if new {
296+
// Grow `evaluated` and `rev_locals` here to amortize the allocations.
296297
let evaluated = self.eval_to_const(index);
297298
let _index = self.evaluated.push(evaluated);
298299
debug_assert_eq!(index, _index);
300+
// No need to push to `rev_locals` if we finished listing assignments.
301+
if self.next_opaque.is_some() {
302+
let _index = self.rev_locals.push(SmallVec::new());
303+
debug_assert_eq!(index, _index);
304+
}
299305
}
300306
index
301307
}
@@ -332,7 +338,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
332338
let is_sized = !self.feature_unsized_locals
333339
|| self.local_decls[local].ty.is_sized(self.tcx, self.param_env);
334340
if is_sized {
335-
self.rev_locals.ensure_contains_elem(value, SmallVec::new).push(local);
341+
self.rev_locals[value].push(local);
336342
}
337343
}
338344

0 commit comments

Comments
 (0)