Skip to content

Commit

Permalink
dse: Eliminate dead assignment statements when debuginfo is not set…
Browse files Browse the repository at this point in the history
… to `full`
  • Loading branch information
DianQK committed Aug 26, 2024
1 parent 22572d0 commit 93b3f30
Show file tree
Hide file tree
Showing 15 changed files with 440 additions and 157 deletions.
14 changes: 10 additions & 4 deletions compiler/rustc_mir_transform/src/dead_store_elimination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use rustc_mir_dataflow::impls::{
borrowed_locals, LivenessTransferFunction, MaybeTransitiveLiveLocals,
};
use rustc_mir_dataflow::Analysis;
use rustc_session::config::DebugInfo;

use crate::util::is_within_packed;

Expand All @@ -31,10 +32,15 @@ use crate::util::is_within_packed;
pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let borrowed_locals = borrowed_locals(body);

// If the user requests complete debuginfo, mark the locals that appear in it as live, so
// we don't remove assignements to them.
let mut always_live = debuginfo_locals(body);
always_live.union(&borrowed_locals);
let always_live = if tcx.sess.opts.debuginfo == DebugInfo::Full {
// If the user requests complete debuginfo, mark the locals that appear in it as live, so
// we don't remove assignements to them.
let mut always_live = debuginfo_locals(body);
always_live.union(&borrowed_locals);
always_live
} else {
borrowed_locals.clone()
};

let mut live = MaybeTransitiveLiveLocals::new(&always_live)
.into_engine(tcx, body)
Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/issue_101973.inner.GVN.panic-abort.diff
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
StorageLive(_4);
StorageLive(_5);
_5 = copy _1;
nop;
- StorageLive(_14);
- _14 = BitAnd(copy _5, const 255_u32);
- _4 = BitOr(const 0_u32, move _14);
Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/issue_101973.inner.GVN.panic-unwind.diff
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
StorageLive(_4);
StorageLive(_5);
_5 = copy _1;
nop;
- StorageLive(_14);
- _14 = BitAnd(copy _5, const 255_u32);
- _4 = BitOr(const 0_u32, move _14);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@

bb2: {
StorageLive(_7);
_7 = &(*_2)[0 of 3];
StorageLive(_8);
_8 = &(*_2)[1 of 3];
StorageLive(_9);
_9 = &(*_2)[2 of 3];
StorageDead(_9);
StorageDead(_8);
StorageDead(_7);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@

bb2: {
StorageLive(_7);
_7 = &(*_2)[0 of 3];
StorageLive(_8);
_8 = &(*_2)[1 of 3];
StorageLive(_9);
_9 = &(*_2)[2 of 3];
StorageDead(_9);
StorageDead(_8);
StorageDead(_7);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,16 @@
}

bb6: {
_5 = move ((_6 as Ok).0: std::ptr::NonNull<[u8]>);
nop;
StorageDead(_16);
StorageDead(_12);
StorageDead(_6);
- StorageLive(_17);
+ nop;
_17 = copy (_5.0: *const [u8]);
- _4 = move _17 as *mut [u8] (PtrToPtr);
- StorageDead(_17);
+ _4 = copy _17 as *mut [u8] (PtrToPtr);
+ nop;
StorageLive(_17);
nop;
nop;
StorageDead(_17);
StorageDead(_5);
- _3 = move _4 as *mut u8 (PtrToPtr);
+ _3 = copy _17 as *mut u8 (PtrToPtr);
nop;
StorageDead(_4);
StorageDead(_3);
- StorageDead(_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,12 @@

bb1: {
StorageDead(_6);
- StorageLive(_12);
+ nop;
_12 = copy (_5.0: *const [u8]);
- _4 = move _12 as *mut [u8] (PtrToPtr);
- StorageDead(_12);
+ _4 = copy _12 as *mut [u8] (PtrToPtr);
+ nop;
StorageLive(_12);
nop;
nop;
StorageDead(_12);
StorageDead(_5);
- _3 = move _4 as *mut u8 (PtrToPtr);
+ _3 = copy _12 as *mut u8 (PtrToPtr);
nop;
StorageDead(_4);
StorageDead(_3);
- StorageDead(_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,16 @@
}

bb6: {
_5 = move ((_6 as Ok).0: std::ptr::NonNull<[u8]>);
nop;
StorageDead(_16);
StorageDead(_12);
StorageDead(_6);
- StorageLive(_17);
+ nop;
_17 = copy (_5.0: *const [u8]);
- _4 = move _17 as *mut [u8] (PtrToPtr);
- StorageDead(_17);
+ _4 = copy _17 as *mut [u8] (PtrToPtr);
+ nop;
StorageLive(_17);
nop;
nop;
StorageDead(_17);
StorageDead(_5);
- _3 = move _4 as *mut u8 (PtrToPtr);
+ _3 = copy _17 as *mut u8 (PtrToPtr);
nop;
StorageDead(_4);
StorageDead(_3);
- StorageDead(_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,12 @@

bb1: {
StorageDead(_6);
- StorageLive(_12);
+ nop;
_12 = copy (_5.0: *const [u8]);
- _4 = move _12 as *mut [u8] (PtrToPtr);
- StorageDead(_12);
+ _4 = copy _12 as *mut [u8] (PtrToPtr);
+ nop;
StorageLive(_12);
nop;
nop;
StorageDead(_12);
StorageDead(_5);
- _3 = move _4 as *mut u8 (PtrToPtr);
+ _3 = copy _12 as *mut u8 (PtrToPtr);
nop;
StorageDead(_4);
StorageDead(_3);
- StorageDead(_1);
Expand Down
Loading

0 comments on commit 93b3f30

Please sign in to comment.