Skip to content

Commit e69bef8

Browse files
committed
Simplify GVN storage checker to use a single bitset
1 parent 67b6ae3 commit e69bef8

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
@@ -149,7 +149,7 @@ impl<'tcx> crate::MirPass<'tcx> for GVN {
149149
.into_results_cursor(body);
150150

151151
let mut storage_checker = StorageChecker {
152-
storage_to_check: state.reused_locals.clone(),
152+
reused_locals: &state.reused_locals,
153153
storage_to_remove: DenseBitSet::new_empty(body.local_decls.len()),
154154
maybe_uninit,
155155
};
@@ -1877,7 +1877,7 @@ impl<'tcx> MutVisitor<'tcx> for StorageRemover<'tcx> {
18771877
}
18781878

18791879
struct StorageChecker<'a, 'tcx> {
1880-
storage_to_check: DenseBitSet<Local>,
1880+
reused_locals: &'a DenseBitSet<Local>,
18811881
storage_to_remove: DenseBitSet<Local>,
18821882
maybe_uninit: ResultsCursor<'a, 'tcx, MaybeUninitializedLocals>,
18831883
}
@@ -1897,18 +1897,16 @@ impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> {
18971897
PlaceContext::MutatingUse(_) | PlaceContext::NonMutatingUse(_) => {}
18981898
}
18991899

1900-
if self.storage_to_check.contains(local) {
1901-
self.maybe_uninit.seek_before_primary_effect(location);
1902-
1903-
if self.maybe_uninit.get().contains(local) {
1904-
debug!(
1905-
?location,
1906-
?local,
1907-
"local is maybe uninit in this location, removing storage"
1908-
);
1909-
self.storage_to_remove.insert(local);
1910-
self.storage_to_check.remove(local);
1911-
}
1900+
// We only need to check reused locals which we haven't already removed storage for.
1901+
if !self.reused_locals.contains(local) || self.storage_to_remove.contains(local) {
1902+
return;
1903+
}
1904+
1905+
self.maybe_uninit.seek_before_primary_effect(location);
1906+
1907+
if self.maybe_uninit.get().contains(local) {
1908+
debug!(?location, ?local, "local is maybe uninit in this location, removing storage");
1909+
self.storage_to_remove.insert(local);
19121910
}
19131911
}
19141912
}

0 commit comments

Comments
 (0)