Skip to content

Commit 49d1f0a

Browse files
committed
Auto merge of #123256 - saethlin:instsimplify-earlier, r=<try>
Run InstSimplify before UnreachablePropagation This is the pass ordering change I was musing about: #122975 (comment) r? `@ghost`
2 parents 5baf1e1 + 0b77e30 commit 49d1f0a

File tree

32 files changed

+181
-198
lines changed

32 files changed

+181
-198
lines changed

compiler/rustc_mir_transform/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
581581
&remove_unneeded_drops::RemoveUnneededDrops,
582582
// Type instantiation may create uninhabited enums.
583583
&uninhabited_enum_branching::UninhabitedEnumBranching,
584+
&instsimplify::InstSimplify,
584585
&unreachable_prop::UnreachablePropagation,
585586
&o1(simplify::SimplifyCfg::AfterUninhabitedEnumBranching),
586587
// Inlining may have introduced a lot of redundant code and a large move pattern.
@@ -593,7 +594,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
593594
&match_branches::MatchBranchSimplification,
594595
// inst combine is after MatchBranchSimplification to clean up Ne(_1, false)
595596
&multiple_return_terminators::MultipleReturnTerminators,
596-
&instsimplify::InstSimplify,
597597
&simplify::SimplifyLocals::BeforeConstProp,
598598
&dead_store_elimination::DeadStoreElimination::Initial,
599599
&gvn::GVN,

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

+15-15
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
debug ptr => _6;
2424
scope 12 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2525
debug ptr => _6;
26-
let mut _8: bool;
27-
let _9: ();
28-
let mut _10: *mut ();
29-
let mut _11: *const [bool; 0];
26+
let _8: ();
27+
let mut _9: *mut ();
28+
let mut _10: *const [bool; 0];
3029
scope 13 {
3130
scope 14 (inlined core::ub_checks::check_language_ub) {
31+
let mut _11: bool;
3232
scope 15 (inlined core::ub_checks::check_language_ub::runtime) {
3333
}
3434
}
@@ -54,18 +54,18 @@
5454
StorageLive(_1);
5555
StorageLive(_2);
5656
StorageLive(_3);
57-
StorageLive(_9);
57+
StorageLive(_8);
5858
StorageLive(_4);
5959
StorageLive(_5);
6060
StorageLive(_6);
6161
StorageLive(_7);
6262
_7 = const 1_usize;
6363
_6 = const {0x1 as *mut [bool; 0]};
6464
StorageDead(_7);
65+
StorageLive(_10);
6566
StorageLive(_11);
66-
StorageLive(_8);
67-
_8 = UbChecks();
68-
switchInt(move _8) -> [0: bb4, otherwise: bb2];
67+
_11 = UbChecks();
68+
switchInt(_11) -> [0: bb4, otherwise: bb2];
6969
}
7070

7171
bb1: {
@@ -74,28 +74,28 @@
7474
}
7575

7676
bb2: {
77-
StorageLive(_10);
78-
_10 = const {0x1 as *mut ()};
79-
_9 = NonNull::<T>::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb3, unwind unreachable];
77+
StorageLive(_9);
78+
_9 = const {0x1 as *mut ()};
79+
_8 = NonNull::<T>::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb3, unwind unreachable];
8080
}
8181

8282
bb3: {
83-
StorageDead(_10);
83+
StorageDead(_9);
8484
goto -> bb4;
8585
}
8686

8787
bb4: {
88-
StorageDead(_8);
89-
_11 = const {0x1 as *const [bool; 0]};
88+
_10 = const {0x1 as *const [bool; 0]};
9089
_5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
9190
StorageDead(_11);
91+
StorageDead(_10);
9292
StorageDead(_6);
9393
_4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }};
9494
StorageDead(_5);
9595
_3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }};
9696
StorageDead(_4);
9797
_2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global);
98-
StorageDead(_9);
98+
StorageDead(_8);
9999
StorageDead(_3);
100100
_1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }};
101101
StorageDead(_2);

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

+15-15
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
debug ptr => _6;
2424
scope 12 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2525
debug ptr => _6;
26-
let mut _8: bool;
27-
let _9: ();
28-
let mut _10: *mut ();
29-
let mut _11: *const [bool; 0];
26+
let _8: ();
27+
let mut _9: *mut ();
28+
let mut _10: *const [bool; 0];
3029
scope 13 {
3130
scope 14 (inlined core::ub_checks::check_language_ub) {
31+
let mut _11: bool;
3232
scope 15 (inlined core::ub_checks::check_language_ub::runtime) {
3333
}
3434
}
@@ -54,18 +54,18 @@
5454
StorageLive(_1);
5555
StorageLive(_2);
5656
StorageLive(_3);
57-
StorageLive(_9);
57+
StorageLive(_8);
5858
StorageLive(_4);
5959
StorageLive(_5);
6060
StorageLive(_6);
6161
StorageLive(_7);
6262
_7 = const 1_usize;
6363
_6 = const {0x1 as *mut [bool; 0]};
6464
StorageDead(_7);
65+
StorageLive(_10);
6566
StorageLive(_11);
66-
StorageLive(_8);
67-
_8 = UbChecks();
68-
switchInt(move _8) -> [0: bb5, otherwise: bb3];
67+
_11 = UbChecks();
68+
switchInt(_11) -> [0: bb5, otherwise: bb3];
6969
}
7070

7171
bb1: {
@@ -78,28 +78,28 @@
7878
}
7979

8080
bb3: {
81-
StorageLive(_10);
82-
_10 = const {0x1 as *mut ()};
83-
_9 = NonNull::<T>::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb4, unwind unreachable];
81+
StorageLive(_9);
82+
_9 = const {0x1 as *mut ()};
83+
_8 = NonNull::<T>::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb4, unwind unreachable];
8484
}
8585

8686
bb4: {
87-
StorageDead(_10);
87+
StorageDead(_9);
8888
goto -> bb5;
8989
}
9090

9191
bb5: {
92-
StorageDead(_8);
93-
_11 = const {0x1 as *const [bool; 0]};
92+
_10 = const {0x1 as *const [bool; 0]};
9493
_5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
9594
StorageDead(_11);
95+
StorageDead(_10);
9696
StorageDead(_6);
9797
_4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }};
9898
StorageDead(_5);
9999
_3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }};
100100
StorageDead(_4);
101101
_2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global);
102-
StorageDead(_9);
102+
StorageDead(_8);
103103
StorageDead(_3);
104104
_1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }};
105105
StorageDead(_2);

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

+15-15
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
debug ptr => _6;
2424
scope 12 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2525
debug ptr => _6;
26-
let mut _8: bool;
27-
let _9: ();
28-
let mut _10: *mut ();
29-
let mut _11: *const [bool; 0];
26+
let _8: ();
27+
let mut _9: *mut ();
28+
let mut _10: *const [bool; 0];
3029
scope 13 {
3130
scope 14 (inlined core::ub_checks::check_language_ub) {
31+
let mut _11: bool;
3232
scope 15 (inlined core::ub_checks::check_language_ub::runtime) {
3333
}
3434
}
@@ -54,18 +54,18 @@
5454
StorageLive(_1);
5555
StorageLive(_2);
5656
StorageLive(_3);
57-
StorageLive(_9);
57+
StorageLive(_8);
5858
StorageLive(_4);
5959
StorageLive(_5);
6060
StorageLive(_6);
6161
StorageLive(_7);
6262
_7 = const 1_usize;
6363
_6 = const {0x1 as *mut [bool; 0]};
6464
StorageDead(_7);
65+
StorageLive(_10);
6566
StorageLive(_11);
66-
StorageLive(_8);
67-
_8 = UbChecks();
68-
switchInt(move _8) -> [0: bb4, otherwise: bb2];
67+
_11 = UbChecks();
68+
switchInt(_11) -> [0: bb4, otherwise: bb2];
6969
}
7070

7171
bb1: {
@@ -74,28 +74,28 @@
7474
}
7575

7676
bb2: {
77-
StorageLive(_10);
78-
_10 = const {0x1 as *mut ()};
79-
_9 = NonNull::<T>::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb3, unwind unreachable];
77+
StorageLive(_9);
78+
_9 = const {0x1 as *mut ()};
79+
_8 = NonNull::<T>::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb3, unwind unreachable];
8080
}
8181

8282
bb3: {
83-
StorageDead(_10);
83+
StorageDead(_9);
8484
goto -> bb4;
8585
}
8686

8787
bb4: {
88-
StorageDead(_8);
89-
_11 = const {0x1 as *const [bool; 0]};
88+
_10 = const {0x1 as *const [bool; 0]};
9089
_5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
9190
StorageDead(_11);
91+
StorageDead(_10);
9292
StorageDead(_6);
9393
_4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }};
9494
StorageDead(_5);
9595
_3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }};
9696
StorageDead(_4);
9797
_2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global);
98-
StorageDead(_9);
98+
StorageDead(_8);
9999
StorageDead(_3);
100100
_1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }};
101101
StorageDead(_2);

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

+15-15
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
debug ptr => _6;
2424
scope 12 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2525
debug ptr => _6;
26-
let mut _8: bool;
27-
let _9: ();
28-
let mut _10: *mut ();
29-
let mut _11: *const [bool; 0];
26+
let _8: ();
27+
let mut _9: *mut ();
28+
let mut _10: *const [bool; 0];
3029
scope 13 {
3130
scope 14 (inlined core::ub_checks::check_language_ub) {
31+
let mut _11: bool;
3232
scope 15 (inlined core::ub_checks::check_language_ub::runtime) {
3333
}
3434
}
@@ -54,18 +54,18 @@
5454
StorageLive(_1);
5555
StorageLive(_2);
5656
StorageLive(_3);
57-
StorageLive(_9);
57+
StorageLive(_8);
5858
StorageLive(_4);
5959
StorageLive(_5);
6060
StorageLive(_6);
6161
StorageLive(_7);
6262
_7 = const 1_usize;
6363
_6 = const {0x1 as *mut [bool; 0]};
6464
StorageDead(_7);
65+
StorageLive(_10);
6566
StorageLive(_11);
66-
StorageLive(_8);
67-
_8 = UbChecks();
68-
switchInt(move _8) -> [0: bb5, otherwise: bb3];
67+
_11 = UbChecks();
68+
switchInt(_11) -> [0: bb5, otherwise: bb3];
6969
}
7070

7171
bb1: {
@@ -78,28 +78,28 @@
7878
}
7979

8080
bb3: {
81-
StorageLive(_10);
82-
_10 = const {0x1 as *mut ()};
83-
_9 = NonNull::<T>::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb4, unwind unreachable];
81+
StorageLive(_9);
82+
_9 = const {0x1 as *mut ()};
83+
_8 = NonNull::<T>::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb4, unwind unreachable];
8484
}
8585

8686
bb4: {
87-
StorageDead(_10);
87+
StorageDead(_9);
8888
goto -> bb5;
8989
}
9090

9191
bb5: {
92-
StorageDead(_8);
93-
_11 = const {0x1 as *const [bool; 0]};
92+
_10 = const {0x1 as *const [bool; 0]};
9493
_5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
9594
StorageDead(_11);
95+
StorageDead(_10);
9696
StorageDead(_6);
9797
_4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }};
9898
StorageDead(_5);
9999
_3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }};
100100
StorageDead(_4);
101101
_2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global);
102-
StorageDead(_9);
102+
StorageDead(_8);
103103
StorageDead(_3);
104104
_1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }};
105105
StorageDead(_2);

0 commit comments

Comments
 (0)