From a67bf08ed79936fdf9b06d2c8d22fbeb60e55505 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 7 May 2023 12:09:06 +0000 Subject: [PATCH] Only check storage liveness for direct projections. --- compiler/rustc_mir_transform/src/ref_prop.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_mir_transform/src/ref_prop.rs b/compiler/rustc_mir_transform/src/ref_prop.rs index 9afbae9d8d1..dafd2ae23a6 100644 --- a/compiler/rustc_mir_transform/src/ref_prop.rs +++ b/compiler/rustc_mir_transform/src/ref_prop.rs @@ -163,18 +163,15 @@ fn compute_replacement<'tcx>( }; let mut can_perform_opt = |target: Place<'tcx>, loc: Location| { - maybe_dead.seek_after_primary_effect(loc); - let maybe_dead = maybe_dead.contains(target.local); - if target.projection.first() == Some(&PlaceElem::Deref) { // We are creating a reborrow. As `place.local` is a reference, removing the storage // statements should not make it much harder for LLVM to optimize. - if maybe_dead { - storage_to_remove.insert(target.local); - } + storage_to_remove.insert(target.local); true } else { // This is a proper dereference. We can only allow it if `target` is live. + maybe_dead.seek_after_primary_effect(loc); + let maybe_dead = maybe_dead.contains(target.local); !maybe_dead } };