Skip to content

Commit c56f2f1

Browse files
committed
Simplify GVN storage checker to use a single bitset
1 parent 02ddf2f commit c56f2f1

File tree

1 file changed

+12
-14
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+12
-14
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl<'tcx> crate::MirPass<'tcx> for GVN {
160160
.into_results_cursor(body);
161161

162162
let mut storage_checker = StorageChecker {
163-
storage_to_check: state.reused_locals.clone(),
163+
reused_locals: &state.reused_locals,
164164
storage_to_remove: DenseBitSet::new_empty(body.local_decls.len()),
165165
maybe_uninit,
166166
};
@@ -1984,7 +1984,7 @@ impl<'tcx> MutVisitor<'tcx> for StorageRemover<'tcx> {
19841984
}
19851985

19861986
struct StorageChecker<'a, 'tcx> {
1987-
storage_to_check: DenseBitSet<Local>,
1987+
reused_locals: &'a DenseBitSet<Local>,
19881988
storage_to_remove: DenseBitSet<Local>,
19891989
maybe_uninit: ResultsCursor<'a, 'tcx, MaybeUninitializedLocals>,
19901990
}
@@ -2004,18 +2004,16 @@ impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> {
20042004
PlaceContext::MutatingUse(_) | PlaceContext::NonMutatingUse(_) => {}
20052005
}
20062006

2007-
if self.storage_to_check.contains(local) {
2008-
self.maybe_uninit.seek_before_primary_effect(location);
2009-
2010-
if self.maybe_uninit.get().contains(local) {
2011-
debug!(
2012-
?location,
2013-
?local,
2014-
"local is maybe uninit in this location, removing storage"
2015-
);
2016-
self.storage_to_remove.insert(local);
2017-
self.storage_to_check.remove(local);
2018-
}
2007+
// We only need to check reused locals which we haven't already removed storage for.
2008+
if !self.reused_locals.contains(local) || self.storage_to_remove.contains(local) {
2009+
return;
2010+
}
2011+
2012+
self.maybe_uninit.seek_before_primary_effect(location);
2013+
2014+
if self.maybe_uninit.get().contains(local) {
2015+
debug!(?location, ?local, "local is maybe uninit in this location, removing storage");
2016+
self.storage_to_remove.insert(local);
20192017
}
20202018
}
20212019
}

0 commit comments

Comments
 (0)