Skip to content

Commit 93b3f30

Browse files
committed
dse: Eliminate dead assignment statements when debuginfo is not set to full
1 parent 22572d0 commit 93b3f30

15 files changed

+440
-157
lines changed

compiler/rustc_mir_transform/src/dead_store_elimination.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_mir_dataflow::impls::{
2121
borrowed_locals, LivenessTransferFunction, MaybeTransitiveLiveLocals,
2222
};
2323
use rustc_mir_dataflow::Analysis;
24+
use rustc_session::config::DebugInfo;
2425

2526
use crate::util::is_within_packed;
2627

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

34-
// If the user requests complete debuginfo, mark the locals that appear in it as live, so
35-
// we don't remove assignements to them.
36-
let mut always_live = debuginfo_locals(body);
37-
always_live.union(&borrowed_locals);
35+
let always_live = if tcx.sess.opts.debuginfo == DebugInfo::Full {
36+
// If the user requests complete debuginfo, mark the locals that appear in it as live, so
37+
// we don't remove assignements to them.
38+
let mut always_live = debuginfo_locals(body);
39+
always_live.union(&borrowed_locals);
40+
always_live
41+
} else {
42+
borrowed_locals.clone()
43+
};
3844

3945
let mut live = MaybeTransitiveLiveLocals::new(&always_live)
4046
.into_engine(tcx, body)

tests/mir-opt/issue_101973.inner.GVN.panic-abort.diff

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
StorageLive(_4);
3131
StorageLive(_5);
3232
_5 = copy _1;
33-
nop;
3433
- StorageLive(_14);
3534
- _14 = BitAnd(copy _5, const 255_u32);
3635
- _4 = BitOr(const 0_u32, move _14);

tests/mir-opt/issue_101973.inner.GVN.panic-unwind.diff

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
StorageLive(_4);
3131
StorageLive(_5);
3232
_5 = copy _1;
33-
nop;
3433
- StorageLive(_14);
3534
- _14 = BitAnd(copy _5, const 255_u32);
3635
- _4 = BitOr(const 0_u32, move _14);

tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff

-3
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@
3838

3939
bb2: {
4040
StorageLive(_7);
41-
_7 = &(*_2)[0 of 3];
4241
StorageLive(_8);
43-
_8 = &(*_2)[1 of 3];
4442
StorageLive(_9);
45-
_9 = &(*_2)[2 of 3];
4643
StorageDead(_9);
4744
StorageDead(_8);
4845
StorageDead(_7);

tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff

-3
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@
3838

3939
bb2: {
4040
StorageLive(_7);
41-
_7 = &(*_2)[0 of 3];
4241
StorageLive(_8);
43-
_8 = &(*_2)[1 of 3];
4442
StorageLive(_9);
45-
_9 = &(*_2)[2 of 3];
4643
StorageDead(_9);
4744
StorageDead(_8);
4845
StorageDead(_7);

tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff

+6-10
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,16 @@
9898
}
9999

100100
bb6: {
101-
_5 = move ((_6 as Ok).0: std::ptr::NonNull<[u8]>);
101+
nop;
102102
StorageDead(_16);
103103
StorageDead(_12);
104104
StorageDead(_6);
105-
- StorageLive(_17);
106-
+ nop;
107-
_17 = copy (_5.0: *const [u8]);
108-
- _4 = move _17 as *mut [u8] (PtrToPtr);
109-
- StorageDead(_17);
110-
+ _4 = copy _17 as *mut [u8] (PtrToPtr);
111-
+ nop;
105+
StorageLive(_17);
106+
nop;
107+
nop;
108+
StorageDead(_17);
112109
StorageDead(_5);
113-
- _3 = move _4 as *mut u8 (PtrToPtr);
114-
+ _3 = copy _17 as *mut u8 (PtrToPtr);
110+
nop;
115111
StorageDead(_4);
116112
StorageDead(_3);
117113
- StorageDead(_1);

tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff

+5-9
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,12 @@
4545

4646
bb1: {
4747
StorageDead(_6);
48-
- StorageLive(_12);
49-
+ nop;
50-
_12 = copy (_5.0: *const [u8]);
51-
- _4 = move _12 as *mut [u8] (PtrToPtr);
52-
- StorageDead(_12);
53-
+ _4 = copy _12 as *mut [u8] (PtrToPtr);
54-
+ nop;
48+
StorageLive(_12);
49+
nop;
50+
nop;
51+
StorageDead(_12);
5552
StorageDead(_5);
56-
- _3 = move _4 as *mut u8 (PtrToPtr);
57-
+ _3 = copy _12 as *mut u8 (PtrToPtr);
53+
nop;
5854
StorageDead(_4);
5955
StorageDead(_3);
6056
- StorageDead(_1);

tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff

+6-10
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,16 @@
9898
}
9999

100100
bb6: {
101-
_5 = move ((_6 as Ok).0: std::ptr::NonNull<[u8]>);
101+
nop;
102102
StorageDead(_16);
103103
StorageDead(_12);
104104
StorageDead(_6);
105-
- StorageLive(_17);
106-
+ nop;
107-
_17 = copy (_5.0: *const [u8]);
108-
- _4 = move _17 as *mut [u8] (PtrToPtr);
109-
- StorageDead(_17);
110-
+ _4 = copy _17 as *mut [u8] (PtrToPtr);
111-
+ nop;
105+
StorageLive(_17);
106+
nop;
107+
nop;
108+
StorageDead(_17);
112109
StorageDead(_5);
113-
- _3 = move _4 as *mut u8 (PtrToPtr);
114-
+ _3 = copy _17 as *mut u8 (PtrToPtr);
110+
nop;
115111
StorageDead(_4);
116112
StorageDead(_3);
117113
- StorageDead(_1);

tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff

+5-9
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,12 @@
4545

4646
bb1: {
4747
StorageDead(_6);
48-
- StorageLive(_12);
49-
+ nop;
50-
_12 = copy (_5.0: *const [u8]);
51-
- _4 = move _12 as *mut [u8] (PtrToPtr);
52-
- StorageDead(_12);
53-
+ _4 = copy _12 as *mut [u8] (PtrToPtr);
54-
+ nop;
48+
StorageLive(_12);
49+
nop;
50+
nop;
51+
StorageDead(_12);
5552
StorageDead(_5);
56-
- _3 = move _4 as *mut u8 (PtrToPtr);
57-
+ _3 = copy _12 as *mut u8 (PtrToPtr);
53+
nop;
5854
StorageDead(_4);
5955
StorageDead(_3);
6056
- StorageDead(_1);

0 commit comments

Comments
 (0)