Skip to content

Commit bee69ed

Browse files
committed
Sandwich MIR optimizations between DSE.
1 parent b8c2074 commit bee69ed

File tree

70 files changed

+539
-282
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+539
-282
lines changed

compiler/rustc_mir_transform/src/dead_store_elimination.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,19 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
127127
crate::simplify::simplify_locals(body, tcx)
128128
}
129129

130-
pub struct DeadStoreElimination;
130+
pub enum DeadStoreElimination {
131+
Initial,
132+
Final,
133+
}
131134

132135
impl<'tcx> MirPass<'tcx> for DeadStoreElimination {
136+
fn name(&self) -> &'static str {
137+
match self {
138+
DeadStoreElimination::Initial => "DeadStoreElimination-initial",
139+
DeadStoreElimination::Final => "DeadStoreElimination-final",
140+
}
141+
}
142+
133143
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
134144
sess.mir_opt_level() >= 2
135145
}

compiler/rustc_mir_transform/src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -583,24 +583,25 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
583583
&multiple_return_terminators::MultipleReturnTerminators,
584584
&instsimplify::InstSimplify,
585585
&simplify::SimplifyLocals::BeforeConstProp,
586-
&copy_prop::CopyProp,
586+
&dead_store_elimination::DeadStoreElimination::Initial,
587+
&gvn::GVN,
588+
&simplify::SimplifyLocals::AfterGVN,
587589
// Perform `SeparateConstSwitch` after SSA-based analyses, as cloning blocks may
588590
// destroy the SSA property. It should still happen before const-propagation, so the
589591
// latter pass will leverage the created opportunities.
590592
&separate_const_switch::SeparateConstSwitch,
591-
&gvn::GVN,
592-
&simplify::SimplifyLocals::AfterGVN,
593593
&dataflow_const_prop::DataflowConstProp,
594594
&const_debuginfo::ConstDebugInfo,
595595
&o1(simplify_branches::SimplifyConstCondition::AfterConstProp),
596596
&jump_threading::JumpThreading,
597597
&early_otherwise_branch::EarlyOtherwiseBranch,
598598
&simplify_comparison_integral::SimplifyComparisonIntegral,
599-
&dead_store_elimination::DeadStoreElimination,
600599
&dest_prop::DestinationPropagation,
601600
&o1(simplify_branches::SimplifyConstCondition::Final),
602601
&o1(remove_noop_landing_pads::RemoveNoopLandingPads),
603602
&o1(simplify::SimplifyCfg::Final),
603+
&copy_prop::CopyProp,
604+
&dead_store_elimination::DeadStoreElimination::Final,
604605
&nrvo::RenameReturnPlace,
605606
&simplify::SimplifyLocals::Final,
606607
&multiple_return_terminators::MultipleReturnTerminators,

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff

+9-6
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@
2525
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2626
debug ptr => _6;
2727
let mut _8: *const [bool; 0];
28+
let mut _9: *mut [bool; 0];
2829
scope 12 {
2930
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
30-
debug ptr => _6;
31+
debug ptr => _9;
3132
scope 14 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
32-
debug self => _6;
33-
let mut _9: *mut u8;
33+
debug self => _9;
34+
let mut _10: *mut u8;
3435
scope 15 {
3536
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
36-
debug ptr => _9;
37+
debug ptr => _10;
3738
scope 17 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
38-
debug self => _9;
39+
debug self => _10;
3940
scope 18 {
4041
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
41-
debug self => _9;
42+
debug self => _10;
4243
}
4344
}
4445
}
@@ -74,8 +75,10 @@
7475
StorageDead(_7);
7576
StorageLive(_8);
7677
StorageLive(_9);
78+
StorageLive(_10);
7779
_8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
7880
_5 = NonNull::<[bool; 0]> { pointer: _8 };
81+
StorageDead(_10);
7982
StorageDead(_9);
8083
StorageDead(_8);
8184
StorageDead(_6);

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff

+9-6
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@
2525
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2626
debug ptr => _6;
2727
let mut _8: *const [bool; 0];
28+
let mut _9: *mut [bool; 0];
2829
scope 12 {
2930
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
30-
debug ptr => _6;
31+
debug ptr => _9;
3132
scope 14 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
32-
debug self => _6;
33-
let mut _9: *mut u8;
33+
debug self => _9;
34+
let mut _10: *mut u8;
3435
scope 15 {
3536
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
36-
debug ptr => _9;
37+
debug ptr => _10;
3738
scope 17 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
38-
debug self => _9;
39+
debug self => _10;
3940
scope 18 {
4041
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
41-
debug self => _9;
42+
debug self => _10;
4243
}
4344
}
4445
}
@@ -74,8 +75,10 @@
7475
StorageDead(_7);
7576
StorageLive(_8);
7677
StorageLive(_9);
78+
StorageLive(_10);
7779
_8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
7880
_5 = NonNull::<[bool; 0]> { pointer: _8 };
81+
StorageDead(_10);
7982
StorageDead(_9);
8083
StorageDead(_8);
8184
StorageDead(_6);

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff

+9-6
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@
2525
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2626
debug ptr => _6;
2727
let mut _8: *const [bool; 0];
28+
let mut _9: *mut [bool; 0];
2829
scope 12 {
2930
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
30-
debug ptr => _6;
31+
debug ptr => _9;
3132
scope 14 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
32-
debug self => _6;
33-
let mut _9: *mut u8;
33+
debug self => _9;
34+
let mut _10: *mut u8;
3435
scope 15 {
3536
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
36-
debug ptr => _9;
37+
debug ptr => _10;
3738
scope 17 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
38-
debug self => _9;
39+
debug self => _10;
3940
scope 18 {
4041
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
41-
debug self => _9;
42+
debug self => _10;
4243
}
4344
}
4445
}
@@ -74,8 +75,10 @@
7475
StorageDead(_7);
7576
StorageLive(_8);
7677
StorageLive(_9);
78+
StorageLive(_10);
7779
_8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
7880
_5 = NonNull::<[bool; 0]> { pointer: _8 };
81+
StorageDead(_10);
7982
StorageDead(_9);
8083
StorageDead(_8);
8184
StorageDead(_6);

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff

+9-6
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@
2525
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2626
debug ptr => _6;
2727
let mut _8: *const [bool; 0];
28+
let mut _9: *mut [bool; 0];
2829
scope 12 {
2930
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
30-
debug ptr => _6;
31+
debug ptr => _9;
3132
scope 14 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
32-
debug self => _6;
33-
let mut _9: *mut u8;
33+
debug self => _9;
34+
let mut _10: *mut u8;
3435
scope 15 {
3536
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
36-
debug ptr => _9;
37+
debug ptr => _10;
3738
scope 17 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
38-
debug self => _9;
39+
debug self => _10;
3940
scope 18 {
4041
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
41-
debug self => _9;
42+
debug self => _10;
4243
}
4344
}
4445
}
@@ -74,8 +75,10 @@
7475
StorageDead(_7);
7576
StorageLive(_8);
7677
StorageLive(_9);
78+
StorageLive(_10);
7779
_8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
7880
_5 = NonNull::<[bool; 0]> { pointer: _8 };
81+
StorageDead(_10);
7982
StorageDead(_9);
8083
StorageDead(_8);
8184
StorageDead(_6);

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff

+9-6
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@
2525
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2626
debug ptr => _6;
2727
let mut _8: *const [bool; 0];
28+
let mut _9: *mut [bool; 0];
2829
scope 12 {
2930
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
30-
debug ptr => _6;
31+
debug ptr => _9;
3132
scope 14 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
32-
debug self => _6;
33-
let mut _9: *mut u8;
33+
debug self => _9;
34+
let mut _10: *mut u8;
3435
scope 15 {
3536
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
36-
debug ptr => _9;
37+
debug ptr => _10;
3738
scope 17 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
38-
debug self => _9;
39+
debug self => _10;
3940
scope 18 {
4041
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
41-
debug self => _9;
42+
debug self => _10;
4243
}
4344
}
4445
}
@@ -76,9 +77,11 @@
7677
StorageDead(_7);
7778
StorageLive(_8);
7879
StorageLive(_9);
80+
StorageLive(_10);
7981
- _8 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer));
8082
+ _8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
8183
_5 = NonNull::<[bool; 0]> { pointer: _8 };
84+
StorageDead(_10);
8285
StorageDead(_9);
8386
StorageDead(_8);
8487
StorageDead(_6);

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff

+9-6
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@
2525
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2626
debug ptr => _6;
2727
let mut _8: *const [bool; 0];
28+
let mut _9: *mut [bool; 0];
2829
scope 12 {
2930
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
30-
debug ptr => _6;
31+
debug ptr => _9;
3132
scope 14 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
32-
debug self => _6;
33-
let mut _9: *mut u8;
33+
debug self => _9;
34+
let mut _10: *mut u8;
3435
scope 15 {
3536
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
36-
debug ptr => _9;
37+
debug ptr => _10;
3738
scope 17 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
38-
debug self => _9;
39+
debug self => _10;
3940
scope 18 {
4041
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
41-
debug self => _9;
42+
debug self => _10;
4243
}
4344
}
4445
}
@@ -76,9 +77,11 @@
7677
StorageDead(_7);
7778
StorageLive(_8);
7879
StorageLive(_9);
80+
StorageLive(_10);
7981
- _8 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer));
8082
+ _8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
8183
_5 = NonNull::<[bool; 0]> { pointer: _8 };
84+
StorageDead(_10);
8285
StorageDead(_9);
8386
StorageDead(_8);
8487
StorageDead(_6);

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff

+9-6
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@
2525
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2626
debug ptr => _6;
2727
let mut _8: *const [bool; 0];
28+
let mut _9: *mut [bool; 0];
2829
scope 12 {
2930
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
30-
debug ptr => _6;
31+
debug ptr => _9;
3132
scope 14 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
32-
debug self => _6;
33-
let mut _9: *mut u8;
33+
debug self => _9;
34+
let mut _10: *mut u8;
3435
scope 15 {
3536
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
36-
debug ptr => _9;
37+
debug ptr => _10;
3738
scope 17 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
38-
debug self => _9;
39+
debug self => _10;
3940
scope 18 {
4041
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
41-
debug self => _9;
42+
debug self => _10;
4243
}
4344
}
4445
}
@@ -76,9 +77,11 @@
7677
StorageDead(_7);
7778
StorageLive(_8);
7879
StorageLive(_9);
80+
StorageLive(_10);
7981
- _8 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer));
8082
+ _8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
8183
_5 = NonNull::<[bool; 0]> { pointer: _8 };
84+
StorageDead(_10);
8285
StorageDead(_9);
8386
StorageDead(_8);
8487
StorageDead(_6);

0 commit comments

Comments
 (0)