Skip to content

Commit afd7fba

Browse files
committed
Reorder passes.
1 parent 26089ba commit afd7fba

7 files changed

+38
-39
lines changed

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,12 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
528528
&check_alignment::CheckAlignment,
529529
&reveal_all::RevealAll, // has to be done before inlining, since inlined code is in RevealAll mode.
530530
&lower_slice_len::LowerSliceLenCalls, // has to be done before inlining, otherwise actual call will be almost always inlined. Also simple, so can just do first
531-
&unreachable_prop::UnreachablePropagation,
531+
&inline::Inline,
532+
// Substitutions during inlining may introduce switch on enums with uninhabited
533+
// branches.
532534
&uninhabited_enum_branching::UninhabitedEnumBranching,
535+
&unreachable_prop::UnreachablePropagation,
533536
&o1(simplify::SimplifyCfg::AfterUninhabitedEnumBranching),
534-
&inline::Inline,
535537
&remove_storage_markers::RemoveStorageMarkers,
536538
&remove_zsts::RemoveZsts,
537539
&normalize_array_len::NormalizeArrayLen, // has to run after `slice::len` lowering

compiler/rustc_mir_transform/src/unreachable_prop.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//! when all of their successors are unreachable. This is achieved through a
33
//! post-order traversal of the blocks.
44
5-
use crate::simplify;
65
use crate::MirPass;
76
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
87
use rustc_middle::mir::*;
@@ -48,8 +47,6 @@ impl MirPass<'_> for UnreachablePropagation {
4847
body.basic_blocks_mut()[bb].statements.clear();
4948
}
5049

51-
let replaced = !replacements.is_empty();
52-
5350
for (bb, terminator_kind) in replacements {
5451
if !tcx.consider_optimizing(|| {
5552
format!("UnreachablePropagation {:?} ", body.source.def_id())
@@ -60,9 +57,7 @@ impl MirPass<'_> for UnreachablePropagation {
6057
body.basic_blocks_mut()[bb].terminator_mut().kind = terminator_kind;
6158
}
6259

63-
if replaced {
64-
simplify::remove_dead_blocks(tcx, body);
65-
}
60+
// Do not remove dead blocks, let `SimplifyCfg` do it.
6661
}
6762
}
6863

tests/mir-opt/separate_const_switch.identity.SeparateConstSwitch.diff

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
StorageLive(_10);
5252
StorageLive(_11);
5353
_9 = discriminant(_1);
54-
switchInt(move _9) -> [0: bb7, 1: bb5, otherwise: bb6];
54+
switchInt(move _9) -> [0: bb6, 1: bb5, otherwise: bb3];
5555
}
5656

5757
bb1: {
@@ -90,10 +90,6 @@
9090
}
9191

9292
bb6: {
93-
unreachable;
94-
}
95-
96-
bb7: {
9793
_10 = ((_1 as Ok).0: i32);
9894
_3 = ControlFlow::<Result<Infallible, i32>, i32>::Continue(move _10);
9995
goto -> bb1;

tests/mir-opt/unreachable.main.UnreachablePropagation.panic-abort.diff

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424

2525
bb1: {
2626
_2 = discriminant(_1);
27-
- switchInt(move _2) -> [1: bb2, otherwise: bb6];
28-
+ switchInt(move _2) -> [1: bb2, otherwise: bb3];
27+
switchInt(move _2) -> [1: bb2, otherwise: bb6];
2928
}
3029

3130
bb2: {
@@ -36,29 +35,31 @@
3635
- StorageLive(_6);
3736
- _6 = const true;
3837
- switchInt(move _6) -> [0: bb4, otherwise: bb3];
39-
- }
40-
-
41-
- bb3: {
38+
+ unreachable;
39+
}
40+
41+
bb3: {
4242
- _4 = const 21_i32;
4343
- _5 = const ();
4444
- goto -> bb5;
45-
- }
46-
-
47-
- bb4: {
45+
+ unreachable;
46+
}
47+
48+
bb4: {
4849
- _4 = const 42_i32;
4950
- _5 = const ();
5051
- goto -> bb5;
51-
- }
52-
-
53-
- bb5: {
52+
+ unreachable;
53+
}
54+
55+
bb5: {
5456
- StorageDead(_6);
5557
- StorageDead(_5);
5658
- StorageLive(_7);
5759
unreachable;
5860
}
5961

60-
- bb6: {
61-
+ bb3: {
62+
bb6: {
6263
_0 = const ();
6364
StorageDead(_1);
6465
return;

tests/mir-opt/unreachable.main.UnreachablePropagation.panic-unwind.diff

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424

2525
bb1: {
2626
_2 = discriminant(_1);
27-
- switchInt(move _2) -> [1: bb2, otherwise: bb6];
28-
+ switchInt(move _2) -> [1: bb2, otherwise: bb3];
27+
switchInt(move _2) -> [1: bb2, otherwise: bb6];
2928
}
3029

3130
bb2: {
@@ -36,29 +35,31 @@
3635
- StorageLive(_6);
3736
- _6 = const true;
3837
- switchInt(move _6) -> [0: bb4, otherwise: bb3];
39-
- }
40-
-
41-
- bb3: {
38+
+ unreachable;
39+
}
40+
41+
bb3: {
4242
- _4 = const 21_i32;
4343
- _5 = const ();
4444
- goto -> bb5;
45-
- }
46-
-
47-
- bb4: {
45+
+ unreachable;
46+
}
47+
48+
bb4: {
4849
- _4 = const 42_i32;
4950
- _5 = const ();
5051
- goto -> bb5;
51-
- }
52-
-
53-
- bb5: {
52+
+ unreachable;
53+
}
54+
55+
bb5: {
5456
- StorageDead(_6);
5557
- StorageDead(_5);
5658
- StorageLive(_7);
5759
unreachable;
5860
}
5961

60-
- bb6: {
61-
+ bb3: {
62+
bb6: {
6263
_0 = const ();
6364
StorageDead(_1);
6465
return;

tests/mir-opt/unreachable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
// unit-test: UnreachablePropagation
12
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
3+
24
enum Empty {}
35

46
fn empty() -> Option<Empty> {

tests/mir-opt/unreachable_diverging.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
// unit-test: UnreachablePropagation
12
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
3+
24
pub enum Empty {}
35

46
fn empty() -> Option<Empty> {

0 commit comments

Comments
 (0)