Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ba11b7d

Browse files
committedOct 26, 2023
Auto merge of rust-lang#117206 - cjgillot:jump-threading-default, r=<try>
PERF: Enable MIR JumpThreading by default Mostly for perf r? `@ghost`
2 parents ccb160d + ada7a64 commit ba11b7d

25 files changed

+411
-1090
lines changed
 

‎compiler/rustc_mir_transform/src/const_goto.rs

Lines changed: 0 additions & 129 deletions
This file was deleted.

‎compiler/rustc_mir_transform/src/jump_threading.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const MAX_PLACES: usize = 100;
5555

5656
impl<'tcx> MirPass<'tcx> for JumpThreading {
5757
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
58-
sess.mir_opt_level() >= 4
58+
sess.mir_opt_level() >= 2
5959
}
6060

6161
#[instrument(skip_all level = "debug")]

‎compiler/rustc_mir_transform/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ mod remove_place_mention;
5757
mod add_subtyping_projections;
5858
pub mod cleanup_post_borrowck;
5959
mod const_debuginfo;
60-
mod const_goto;
6160
mod const_prop;
6261
mod const_prop_lint;
6362
mod copy_prop;
@@ -99,7 +98,6 @@ mod remove_unneeded_drops;
9998
mod remove_zsts;
10099
mod required_consts;
101100
mod reveal_all;
102-
mod separate_const_switch;
103101
mod shim;
104102
mod ssa;
105103
// This pass is public to allow external drivers to perform MIR cleanup
@@ -554,7 +552,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
554552
&remove_storage_markers::RemoveStorageMarkers,
555553
&remove_zsts::RemoveZsts,
556554
&normalize_array_len::NormalizeArrayLen, // has to run after `slice::len` lowering
557-
&const_goto::ConstGoto,
558555
&remove_unneeded_drops::RemoveUnneededDrops,
559556
&ref_prop::ReferencePropagation,
560557
&sroa::ScalarReplacementOfAggregates,
@@ -564,10 +561,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
564561
&instsimplify::InstSimplify,
565562
&simplify::SimplifyLocals::BeforeConstProp,
566563
&copy_prop::CopyProp,
567-
// Perform `SeparateConstSwitch` after SSA-based analyses, as cloning blocks may
568-
// destroy the SSA property. It should still happen before const-propagation, so the
569-
// latter pass will leverage the created opportunities.
570-
&separate_const_switch::SeparateConstSwitch,
571564
&const_prop::ConstProp,
572565
&gvn::GVN,
573566
&dataflow_const_prop::DataflowConstProp,

‎compiler/rustc_mir_transform/src/separate_const_switch.rs

Lines changed: 0 additions & 344 deletions
This file was deleted.

‎tests/mir-opt/const_goto.issue_77355_opt.ConstGoto.diff

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
- // MIR for `issue_77355_opt` before JumpThreading
2+
+ // MIR for `issue_77355_opt` after JumpThreading
3+
4+
fn issue_77355_opt(_1: Foo) -> u64 {
5+
debug num => _1;
6+
let mut _0: u64;
7+
let mut _2: bool;
8+
let mut _3: isize;
9+
10+
bb0: {
11+
StorageLive(_2);
12+
_3 = discriminant(_1);
13+
switchInt(move _3) -> [1: bb2, 2: bb2, otherwise: bb1];
14+
}
15+
16+
bb1: {
17+
_2 = const false;
18+
- goto -> bb3;
19+
+ goto -> bb7;
20+
}
21+
22+
bb2: {
23+
_2 = const true;
24+
goto -> bb3;
25+
}
26+
27+
bb3: {
28+
- switchInt(move _2) -> [0: bb5, otherwise: bb4];
29+
+ goto -> bb4;
30+
}
31+
32+
bb4: {
33+
_0 = const 23_u64;
34+
goto -> bb6;
35+
}
36+
37+
bb5: {
38+
_0 = const 42_u64;
39+
goto -> bb6;
40+
}
41+
42+
bb6: {
43+
StorageDead(_2);
44+
return;
45+
+ }
46+
+
47+
+ bb7: {
48+
+ goto -> bb5;
49+
}
50+
}
51+

‎tests/mir-opt/const_goto.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

‎tests/mir-opt/const_goto_const_eval_fail.f.ConstGoto.diff

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
- // MIR for `f` before JumpThreading
2+
+ // MIR for `f` after JumpThreading
3+
4+
fn f() -> u64 {
5+
let mut _0: u64;
6+
let mut _1: bool;
7+
let mut _2: i32;
8+
9+
bb0: {
10+
StorageLive(_1);
11+
switchInt(const A) -> [1: bb2, 2: bb2, 3: bb2, otherwise: bb1];
12+
}
13+
14+
bb1: {
15+
_1 = const true;
16+
- goto -> bb3;
17+
+ goto -> bb7;
18+
}
19+
20+
bb2: {
21+
_1 = const B;
22+
goto -> bb3;
23+
}
24+
25+
bb3: {
26+
switchInt(_1) -> [0: bb5, otherwise: bb4];
27+
}
28+
29+
bb4: {
30+
_0 = const 2_u64;
31+
goto -> bb6;
32+
}
33+
34+
bb5: {
35+
_0 = const 1_u64;
36+
goto -> bb6;
37+
}
38+
39+
bb6: {
40+
StorageDead(_1);
41+
return;
42+
+ }
43+
+
44+
+ bb7: {
45+
+ goto -> bb4;
46+
}
47+
}
48+

‎tests/mir-opt/const_goto_const_eval_fail.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// compile-flags: -Zunsound-mir-opts
66

77
// If const eval fails, then don't crash
8-
// EMIT_MIR const_goto_const_eval_fail.f.ConstGoto.diff
8+
// EMIT_MIR const_goto_const_eval_fail.f.JumpThreading.diff
99
pub fn f<const A: i32, const B: bool>() -> u64 {
1010
match {
1111
match A {

‎tests/mir-opt/const_goto_storage.match_nested_if.ConstGoto.diff

Lines changed: 0 additions & 102 deletions
This file was deleted.

‎tests/mir-opt/const_goto_storage.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.

‎tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,12 @@ fn step_forward(_1: u32, _2: usize) -> u32 {
44
debug x => _1;
55
debug n => _2;
66
let mut _0: u32;
7-
scope 1 (inlined <u32 as Step>::forward) {
8-
debug start => _1;
9-
debug n => _2;
10-
let _3: std::option::Option<u32>;
11-
let mut _4: &std::option::Option<u32>;
12-
let mut _7: bool;
13-
let mut _8: u32;
14-
scope 2 {
15-
}
16-
scope 3 (inlined Option::<u32>::is_none) {
17-
debug self => _4;
18-
let mut _6: bool;
19-
scope 4 (inlined Option::<u32>::is_some) {
20-
debug self => _4;
21-
let mut _5: isize;
22-
}
23-
}
24-
scope 5 (inlined core::num::<impl u32>::wrapping_add) {
25-
debug self => _1;
26-
debug rhs => _8;
27-
}
28-
}
297

308
bb0: {
31-
StorageLive(_7);
32-
StorageLive(_4);
33-
StorageLive(_3);
34-
_3 = <u32 as Step>::forward_checked(_1, _2) -> [return: bb1, unwind continue];
9+
_0 = <u32 as Step>::forward(move _1, move _2) -> [return: bb1, unwind continue];
3510
}
3611

3712
bb1: {
38-
_4 = &_3;
39-
StorageLive(_6);
40-
StorageLive(_5);
41-
_5 = discriminant(_3);
42-
_6 = Eq(_5, const 1_isize);
43-
StorageDead(_5);
44-
_7 = Not(move _6);
45-
StorageDead(_6);
46-
switchInt(move _7) -> [0: bb2, otherwise: bb3];
47-
}
48-
49-
bb2: {
50-
StorageDead(_3);
51-
StorageDead(_4);
52-
goto -> bb4;
53-
}
54-
55-
bb3: {
56-
StorageDead(_3);
57-
StorageDead(_4);
58-
assert(!const true, "attempt to compute `{} + {}`, which would overflow", const _, const 1_u32) -> [success: bb4, unwind continue];
59-
}
60-
61-
bb4: {
62-
StorageDead(_7);
63-
StorageLive(_8);
64-
_8 = _2 as u32 (IntToInt);
65-
_0 = Add(_1, _8);
66-
StorageDead(_8);
6713
return;
6814
}
6915
}

‎tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ fn int_range(_1: usize, _2: usize) -> () {
77
let mut _3: std::ops::Range<usize>;
88
let mut _4: std::ops::Range<usize>;
99
let mut _5: &mut std::ops::Range<usize>;
10-
let mut _11: std::option::Option<usize>;
11-
let mut _14: isize;
12-
let _16: ();
10+
let mut _13: std::option::Option<usize>;
11+
let _15: ();
1312
scope 1 {
1413
debug iter => _4;
15-
let _15: usize;
14+
let _14: usize;
1615
scope 2 {
17-
debug i => _15;
16+
debug i => _14;
1817
}
1918
scope 4 (inlined iter::range::<impl Iterator for std::ops::Range<usize>>::next) {
2019
debug self => _5;
@@ -23,10 +22,10 @@ fn int_range(_1: usize, _2: usize) -> () {
2322
let mut _6: &usize;
2423
let mut _7: &usize;
2524
let mut _10: bool;
26-
let _12: usize;
27-
let mut _13: usize;
25+
let _11: usize;
26+
let mut _12: usize;
2827
scope 6 {
29-
debug old => _12;
28+
debug old => _11;
3029
scope 7 {
3130
}
3231
}
@@ -51,9 +50,9 @@ fn int_range(_1: usize, _2: usize) -> () {
5150
}
5251

5352
bb1: {
54-
StorageLive(_11);
53+
StorageLive(_13);
5554
_5 = &mut _4;
56-
StorageLive(_12);
55+
StorageLive(_11);
5756
StorageLive(_10);
5857
StorageLive(_6);
5958
_6 = &(_4.0: usize);
@@ -72,49 +71,33 @@ fn int_range(_1: usize, _2: usize) -> () {
7271
bb2: {
7372
StorageDead(_7);
7473
StorageDead(_6);
75-
_11 = Option::<usize>::None;
76-
goto -> bb5;
74+
StorageDead(_10);
75+
StorageDead(_11);
76+
StorageDead(_13);
77+
StorageDead(_4);
78+
return;
7779
}
7880

7981
bb3: {
8082
StorageDead(_7);
8183
StorageDead(_6);
82-
_12 = (_4.0: usize);
83-
StorageLive(_13);
84-
_13 = <usize as Step>::forward_unchecked(_12, const 1_usize) -> [return: bb4, unwind continue];
84+
_11 = (_4.0: usize);
85+
StorageLive(_12);
86+
_12 = <usize as Step>::forward_unchecked(_11, const 1_usize) -> [return: bb4, unwind continue];
8587
}
8688

8789
bb4: {
88-
(_4.0: usize) = move _13;
89-
StorageDead(_13);
90-
_11 = Option::<usize>::Some(_12);
91-
goto -> bb5;
92-
}
93-
94-
bb5: {
95-
StorageDead(_10);
90+
(_4.0: usize) = move _12;
9691
StorageDead(_12);
97-
_14 = discriminant(_11);
98-
switchInt(move _14) -> [0: bb6, 1: bb7, otherwise: bb9];
99-
}
100-
101-
bb6: {
92+
_13 = Option::<usize>::Some(_11);
93+
StorageDead(_10);
10294
StorageDead(_11);
103-
StorageDead(_4);
104-
return;
95+
_14 = ((_13 as Some).0: usize);
96+
_15 = opaque::<usize>(move _14) -> [return: bb5, unwind continue];
10597
}
10698

107-
bb7: {
108-
_15 = ((_11 as Some).0: usize);
109-
_16 = opaque::<usize>(move _15) -> [return: bb8, unwind continue];
110-
}
111-
112-
bb8: {
113-
StorageDead(_11);
99+
bb5: {
100+
StorageDead(_13);
114101
goto -> bb1;
115102
}
116-
117-
bb9: {
118-
unreachable;
119-
}
120103
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// MIR for `issue_77355_opt` after PreCodegen
2+
3+
fn issue_77355_opt(_1: Foo) -> u64 {
4+
debug num => _1;
5+
let mut _0: u64;
6+
let mut _2: isize;
7+
8+
bb0: {
9+
_2 = discriminant(_1);
10+
switchInt(move _2) -> [1: bb1, 2: bb1, otherwise: bb2];
11+
}
12+
13+
bb1: {
14+
_0 = const 23_u64;
15+
return;
16+
}
17+
18+
bb2: {
19+
_0 = const 42_u64;
20+
return;
21+
}
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This test verifies that the MIR we output using the `matches!()` macro is close
2+
// to the MIR for an `if let` branch.
3+
4+
pub enum Foo {
5+
A,
6+
B,
7+
C,
8+
D,
9+
E,
10+
F,
11+
}
12+
13+
// EMIT_MIR matches_macro.issue_77355_opt.PreCodegen.after.mir
14+
fn issue_77355_opt(num: Foo) -> u64 {
15+
// CHECK-LABEL: fn issue_77355_opt(
16+
// CHECK: switchInt({{.*}}) -> [1: bb1, 2: bb1, otherwise: bb2];
17+
// CHECK: bb1: {
18+
// CHECK-NEXT: _0 = const 23_u64;
19+
// CHECK-NEXT: return;
20+
// CHECK: bb2: {
21+
// CHECK-NEXT: _0 = const 42_u64;
22+
// CHECK-NEXT: return;
23+
if matches!(num, Foo::B | Foo::C) { 23 } else { 42 }
24+
}
25+
fn main() {
26+
issue_77355_opt(Foo::A);
27+
}

‎tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.mir

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,35 @@ fn mem_replace(_1: &mut u32, _2: u32) -> u32 {
1414
debug dst => _1;
1515
debug src => _2;
1616
scope 17 {
17+
scope 18 (inlined std::ptr::write::runtime::<u32>) {
18+
debug dst => _1;
19+
let mut _4: *const u32;
20+
scope 19 (inlined intrinsics::is_aligned_and_not_null::<u32>) {
21+
debug ptr => _4;
22+
scope 20 (inlined ptr::const_ptr::<impl *const u32>::is_null) {
23+
debug self => _4;
24+
let mut _5: *const u8;
25+
scope 21 {
26+
scope 22 (inlined ptr::const_ptr::<impl *const T>::is_null::runtime_impl) {
27+
debug ptr => _5;
28+
scope 23 (inlined ptr::const_ptr::<impl *const u8>::addr) {
29+
debug self => _5;
30+
scope 24 {
31+
scope 25 (inlined ptr::const_ptr::<impl *const u8>::cast::<()>) {
32+
debug self => _5;
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}
39+
scope 26 (inlined ptr::const_ptr::<impl *const u32>::is_aligned) {
40+
debug self => _4;
41+
scope 27 (inlined align_of::<u32>) {
42+
}
43+
}
44+
}
45+
}
1746
}
1847
}
1948
}
@@ -57,7 +86,11 @@ fn mem_replace(_1: &mut u32, _2: u32) -> u32 {
5786
StorageLive(_3);
5887
_0 = (*_1);
5988
StorageDead(_3);
89+
StorageLive(_4);
90+
StorageLive(_5);
6091
(*_1) = _2;
92+
StorageDead(_5);
93+
StorageDead(_4);
6194
return;
6295
}
6396
}

‎tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir

Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
88
let mut _4: std::ops::Range<u32>;
99
let mut _5: std::ops::Range<u32>;
1010
let mut _6: &mut std::ops::Range<u32>;
11-
let mut _12: std::option::Option<u32>;
12-
let mut _15: isize;
13-
let mut _17: &impl Fn(u32);
14-
let mut _18: (u32,);
15-
let _19: ();
11+
let mut _14: std::option::Option<u32>;
12+
let mut _16: &impl Fn(u32);
13+
let mut _17: (u32,);
14+
let _18: ();
1615
scope 1 {
1716
debug iter => _5;
18-
let _16: u32;
17+
let _15: u32;
1918
scope 2 {
20-
debug x => _16;
19+
debug x => _15;
2120
}
2221
scope 4 (inlined iter::range::<impl Iterator for std::ops::Range<u32>>::next) {
2322
debug self => _6;
@@ -26,10 +25,10 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
2625
let mut _7: &u32;
2726
let mut _8: &u32;
2827
let mut _11: bool;
29-
let _13: u32;
30-
let mut _14: u32;
28+
let _12: u32;
29+
let mut _13: u32;
3130
scope 6 {
32-
debug old => _13;
31+
debug old => _12;
3332
scope 7 {
3433
}
3534
}
@@ -54,9 +53,9 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
5453
}
5554

5655
bb1: {
57-
StorageLive(_12);
56+
StorageLive(_14);
5857
_6 = &mut _5;
59-
StorageLive(_13);
58+
StorageLive(_12);
6059
StorageLive(_11);
6160
StorageLive(_7);
6261
_7 = &(_5.0: u32);
@@ -69,65 +68,49 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
6968
_11 = Lt(move _9, move _10);
7069
StorageDead(_10);
7170
StorageDead(_9);
72-
switchInt(move _11) -> [0: bb2, otherwise: bb3];
71+
switchInt(move _11) -> [0: bb2, otherwise: bb4];
7372
}
7473

7574
bb2: {
7675
StorageDead(_8);
7776
StorageDead(_7);
78-
_12 = Option::<u32>::None;
79-
goto -> bb5;
77+
StorageDead(_11);
78+
StorageDead(_12);
79+
StorageDead(_14);
80+
StorageDead(_5);
81+
drop(_3) -> [return: bb3, unwind unreachable];
8082
}
8183

8284
bb3: {
83-
StorageDead(_8);
84-
StorageDead(_7);
85-
_13 = (_5.0: u32);
86-
StorageLive(_14);
87-
_14 = <u32 as Step>::forward_unchecked(_13, const 1_usize) -> [return: bb4, unwind unreachable];
85+
return;
8886
}
8987

9088
bb4: {
91-
(_5.0: u32) = move _14;
92-
StorageDead(_14);
93-
_12 = Option::<u32>::Some(_13);
94-
goto -> bb5;
89+
StorageDead(_8);
90+
StorageDead(_7);
91+
_12 = (_5.0: u32);
92+
StorageLive(_13);
93+
_13 = <u32 as Step>::forward_unchecked(_12, const 1_usize) -> [return: bb5, unwind unreachable];
9594
}
9695

9796
bb5: {
98-
StorageDead(_11);
97+
(_5.0: u32) = move _13;
9998
StorageDead(_13);
100-
_15 = discriminant(_12);
101-
switchInt(move _15) -> [0: bb6, 1: bb8, otherwise: bb10];
102-
}
103-
104-
bb6: {
99+
_14 = Option::<u32>::Some(_12);
100+
StorageDead(_11);
105101
StorageDead(_12);
106-
StorageDead(_5);
107-
drop(_3) -> [return: bb7, unwind unreachable];
108-
}
109-
110-
bb7: {
111-
return;
112-
}
113-
114-
bb8: {
115-
_16 = ((_12 as Some).0: u32);
102+
_15 = ((_14 as Some).0: u32);
103+
StorageLive(_16);
104+
_16 = &_3;
116105
StorageLive(_17);
117-
_17 = &_3;
118-
StorageLive(_18);
119-
_18 = (_16,);
120-
_19 = <impl Fn(u32) as Fn<(u32,)>>::call(move _17, move _18) -> [return: bb9, unwind unreachable];
106+
_17 = (_15,);
107+
_18 = <impl Fn(u32) as Fn<(u32,)>>::call(move _16, move _17) -> [return: bb6, unwind unreachable];
121108
}
122109

123-
bb9: {
124-
StorageDead(_18);
110+
bb6: {
125111
StorageDead(_17);
126-
StorageDead(_12);
112+
StorageDead(_16);
113+
StorageDead(_14);
127114
goto -> bb1;
128115
}
129-
130-
bb10: {
131-
unreachable;
132-
}
133116
}

‎tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir

Lines changed: 37 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
88
let mut _4: std::ops::Range<u32>;
99
let mut _5: std::ops::Range<u32>;
1010
let mut _6: &mut std::ops::Range<u32>;
11-
let mut _12: std::option::Option<u32>;
12-
let mut _15: isize;
13-
let mut _17: &impl Fn(u32);
14-
let mut _18: (u32,);
15-
let _19: ();
11+
let mut _14: std::option::Option<u32>;
12+
let mut _16: &impl Fn(u32);
13+
let mut _17: (u32,);
14+
let _18: ();
1615
scope 1 {
1716
debug iter => _5;
18-
let _16: u32;
17+
let _15: u32;
1918
scope 2 {
20-
debug x => _16;
19+
debug x => _15;
2120
}
2221
scope 4 (inlined iter::range::<impl Iterator for std::ops::Range<u32>>::next) {
2322
debug self => _6;
@@ -26,10 +25,10 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
2625
let mut _7: &u32;
2726
let mut _8: &u32;
2827
let mut _11: bool;
29-
let _13: u32;
30-
let mut _14: u32;
28+
let _12: u32;
29+
let mut _13: u32;
3130
scope 6 {
32-
debug old => _13;
31+
debug old => _12;
3332
scope 7 {
3433
}
3534
}
@@ -54,9 +53,9 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
5453
}
5554

5655
bb1: {
57-
StorageLive(_12);
56+
StorageLive(_14);
5857
_6 = &mut _5;
59-
StorageLive(_13);
58+
StorageLive(_12);
6059
StorageLive(_11);
6160
StorageLive(_7);
6261
_7 = &(_5.0: u32);
@@ -69,73 +68,57 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
6968
_11 = Lt(move _9, move _10);
7069
StorageDead(_10);
7170
StorageDead(_9);
72-
switchInt(move _11) -> [0: bb2, otherwise: bb3];
71+
switchInt(move _11) -> [0: bb2, otherwise: bb4];
7372
}
7473

7574
bb2: {
7675
StorageDead(_8);
7776
StorageDead(_7);
78-
_12 = Option::<u32>::None;
79-
goto -> bb5;
77+
StorageDead(_11);
78+
StorageDead(_12);
79+
StorageDead(_14);
80+
StorageDead(_5);
81+
drop(_3) -> [return: bb3, unwind continue];
8082
}
8183

8284
bb3: {
83-
StorageDead(_8);
84-
StorageDead(_7);
85-
_13 = (_5.0: u32);
86-
StorageLive(_14);
87-
_14 = <u32 as Step>::forward_unchecked(_13, const 1_usize) -> [return: bb4, unwind: bb11];
85+
return;
8886
}
8987

9088
bb4: {
91-
(_5.0: u32) = move _14;
92-
StorageDead(_14);
93-
_12 = Option::<u32>::Some(_13);
94-
goto -> bb5;
89+
StorageDead(_8);
90+
StorageDead(_7);
91+
_12 = (_5.0: u32);
92+
StorageLive(_13);
93+
_13 = <u32 as Step>::forward_unchecked(_12, const 1_usize) -> [return: bb5, unwind: bb7];
9594
}
9695

9796
bb5: {
98-
StorageDead(_11);
97+
(_5.0: u32) = move _13;
9998
StorageDead(_13);
100-
_15 = discriminant(_12);
101-
switchInt(move _15) -> [0: bb6, 1: bb8, otherwise: bb10];
102-
}
103-
104-
bb6: {
99+
_14 = Option::<u32>::Some(_12);
100+
StorageDead(_11);
105101
StorageDead(_12);
106-
StorageDead(_5);
107-
drop(_3) -> [return: bb7, unwind continue];
108-
}
109-
110-
bb7: {
111-
return;
112-
}
113-
114-
bb8: {
115-
_16 = ((_12 as Some).0: u32);
102+
_15 = ((_14 as Some).0: u32);
103+
StorageLive(_16);
104+
_16 = &_3;
116105
StorageLive(_17);
117-
_17 = &_3;
118-
StorageLive(_18);
119-
_18 = (_16,);
120-
_19 = <impl Fn(u32) as Fn<(u32,)>>::call(move _17, move _18) -> [return: bb9, unwind: bb11];
106+
_17 = (_15,);
107+
_18 = <impl Fn(u32) as Fn<(u32,)>>::call(move _16, move _17) -> [return: bb6, unwind: bb7];
121108
}
122109

123-
bb9: {
124-
StorageDead(_18);
110+
bb6: {
125111
StorageDead(_17);
126-
StorageDead(_12);
112+
StorageDead(_16);
113+
StorageDead(_14);
127114
goto -> bb1;
128115
}
129116

130-
bb10: {
131-
unreachable;
132-
}
133-
134-
bb11 (cleanup): {
135-
drop(_3) -> [return: bb12, unwind terminate(cleanup)];
117+
bb7 (cleanup): {
118+
drop(_3) -> [return: bb8, unwind terminate(cleanup)];
136119
}
137120

138-
bb12 (cleanup): {
121+
bb8 (cleanup): {
139122
resume;
140123
}
141124
}

‎tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir

Lines changed: 43 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,20 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
88
let mut _4: std::ops::Range<usize>;
99
let mut _5: std::ops::Range<usize>;
1010
let mut _6: &mut std::ops::Range<usize>;
11-
let mut _12: std::option::Option<usize>;
12-
let mut _15: isize;
13-
let mut _17: usize;
14-
let mut _18: bool;
15-
let mut _20: &impl Fn(usize, &T);
16-
let mut _21: (usize, &T);
17-
let _22: ();
11+
let mut _14: std::option::Option<usize>;
12+
let mut _16: usize;
13+
let mut _17: bool;
14+
let mut _19: &impl Fn(usize, &T);
15+
let mut _20: (usize, &T);
16+
let _21: ();
1817
scope 1 {
1918
debug iter => _5;
20-
let _16: usize;
19+
let _15: usize;
2120
scope 2 {
22-
debug i => _16;
23-
let _19: &T;
21+
debug i => _15;
22+
let _18: &T;
2423
scope 3 {
25-
debug x => _19;
24+
debug x => _18;
2625
}
2726
}
2827
scope 5 (inlined iter::range::<impl Iterator for std::ops::Range<usize>>::next) {
@@ -32,10 +31,10 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
3231
let mut _7: &usize;
3332
let mut _8: &usize;
3433
let mut _11: bool;
35-
let _13: usize;
36-
let mut _14: usize;
34+
let _12: usize;
35+
let mut _13: usize;
3736
scope 7 {
38-
debug old => _13;
37+
debug old => _12;
3938
scope 8 {
4039
}
4140
}
@@ -63,9 +62,9 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
6362
}
6463

6564
bb1: {
66-
StorageLive(_12);
65+
StorageLive(_14);
6766
_6 = &mut _5;
68-
StorageLive(_13);
67+
StorageLive(_12);
6968
StorageLive(_11);
7069
StorageLive(_7);
7170
_7 = &(_5.0: usize);
@@ -78,72 +77,56 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
7877
_11 = Lt(move _9, move _10);
7978
StorageDead(_10);
8079
StorageDead(_9);
81-
switchInt(move _11) -> [0: bb2, otherwise: bb3];
80+
switchInt(move _11) -> [0: bb2, otherwise: bb4];
8281
}
8382

8483
bb2: {
8584
StorageDead(_8);
8685
StorageDead(_7);
87-
_12 = Option::<usize>::None;
88-
goto -> bb5;
86+
StorageDead(_11);
87+
StorageDead(_12);
88+
StorageDead(_14);
89+
StorageDead(_5);
90+
drop(_2) -> [return: bb3, unwind unreachable];
8991
}
9092

9193
bb3: {
92-
StorageDead(_8);
93-
StorageDead(_7);
94-
_13 = (_5.0: usize);
95-
StorageLive(_14);
96-
_14 = <usize as Step>::forward_unchecked(_13, const 1_usize) -> [return: bb4, unwind unreachable];
94+
return;
9795
}
9896

9997
bb4: {
100-
(_5.0: usize) = move _14;
101-
StorageDead(_14);
102-
_12 = Option::<usize>::Some(_13);
103-
goto -> bb5;
98+
StorageDead(_8);
99+
StorageDead(_7);
100+
_12 = (_5.0: usize);
101+
StorageLive(_13);
102+
_13 = <usize as Step>::forward_unchecked(_12, const 1_usize) -> [return: bb5, unwind unreachable];
104103
}
105104

106105
bb5: {
107-
StorageDead(_11);
106+
(_5.0: usize) = move _13;
108107
StorageDead(_13);
109-
_15 = discriminant(_12);
110-
switchInt(move _15) -> [0: bb6, 1: bb8, otherwise: bb11];
111-
}
112-
113-
bb6: {
108+
_14 = Option::<usize>::Some(_12);
109+
StorageDead(_11);
114110
StorageDead(_12);
115-
StorageDead(_5);
116-
drop(_2) -> [return: bb7, unwind unreachable];
117-
}
118-
119-
bb7: {
120-
return;
111+
_15 = ((_14 as Some).0: usize);
112+
_16 = Len((*_1));
113+
_17 = Lt(_15, _16);
114+
assert(move _17, "index out of bounds: the length is {} but the index is {}", move _16, _15) -> [success: bb6, unwind unreachable];
121115
}
122116

123-
bb8: {
124-
_16 = ((_12 as Some).0: usize);
125-
_17 = Len((*_1));
126-
_18 = Lt(_16, _17);
127-
assert(move _18, "index out of bounds: the length is {} but the index is {}", move _17, _16) -> [success: bb9, unwind unreachable];
128-
}
129-
130-
bb9: {
131-
_19 = &(*_1)[_16];
117+
bb6: {
118+
_18 = &(*_1)[_15];
119+
StorageLive(_19);
120+
_19 = &_2;
132121
StorageLive(_20);
133-
_20 = &_2;
134-
StorageLive(_21);
135-
_21 = (_16, _19);
136-
_22 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _20, move _21) -> [return: bb10, unwind unreachable];
122+
_20 = (_15, _18);
123+
_21 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _19, move _20) -> [return: bb7, unwind unreachable];
137124
}
138125

139-
bb10: {
140-
StorageDead(_21);
126+
bb7: {
141127
StorageDead(_20);
142-
StorageDead(_12);
128+
StorageDead(_19);
129+
StorageDead(_14);
143130
goto -> bb1;
144131
}
145-
146-
bb11: {
147-
unreachable;
148-
}
149132
}

‎tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir

Lines changed: 46 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,20 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
88
let mut _4: std::ops::Range<usize>;
99
let mut _5: std::ops::Range<usize>;
1010
let mut _6: &mut std::ops::Range<usize>;
11-
let mut _12: std::option::Option<usize>;
12-
let mut _15: isize;
13-
let mut _17: usize;
14-
let mut _18: bool;
15-
let mut _20: &impl Fn(usize, &T);
16-
let mut _21: (usize, &T);
17-
let _22: ();
11+
let mut _14: std::option::Option<usize>;
12+
let mut _16: usize;
13+
let mut _17: bool;
14+
let mut _19: &impl Fn(usize, &T);
15+
let mut _20: (usize, &T);
16+
let _21: ();
1817
scope 1 {
1918
debug iter => _5;
20-
let _16: usize;
19+
let _15: usize;
2120
scope 2 {
22-
debug i => _16;
23-
let _19: &T;
21+
debug i => _15;
22+
let _18: &T;
2423
scope 3 {
25-
debug x => _19;
24+
debug x => _18;
2625
}
2726
}
2827
scope 5 (inlined iter::range::<impl Iterator for std::ops::Range<usize>>::next) {
@@ -32,10 +31,10 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
3231
let mut _7: &usize;
3332
let mut _8: &usize;
3433
let mut _11: bool;
35-
let _13: usize;
36-
let mut _14: usize;
34+
let _12: usize;
35+
let mut _13: usize;
3736
scope 7 {
38-
debug old => _13;
37+
debug old => _12;
3938
scope 8 {
4039
}
4140
}
@@ -63,9 +62,9 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
6362
}
6463

6564
bb1: {
66-
StorageLive(_12);
65+
StorageLive(_14);
6766
_6 = &mut _5;
68-
StorageLive(_13);
67+
StorageLive(_12);
6968
StorageLive(_11);
7069
StorageLive(_7);
7170
_7 = &(_5.0: usize);
@@ -78,80 +77,64 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
7877
_11 = Lt(move _9, move _10);
7978
StorageDead(_10);
8079
StorageDead(_9);
81-
switchInt(move _11) -> [0: bb2, otherwise: bb3];
80+
switchInt(move _11) -> [0: bb2, otherwise: bb4];
8281
}
8382

8483
bb2: {
8584
StorageDead(_8);
8685
StorageDead(_7);
87-
_12 = Option::<usize>::None;
88-
goto -> bb5;
86+
StorageDead(_11);
87+
StorageDead(_12);
88+
StorageDead(_14);
89+
StorageDead(_5);
90+
drop(_2) -> [return: bb3, unwind continue];
8991
}
9092

9193
bb3: {
92-
StorageDead(_8);
93-
StorageDead(_7);
94-
_13 = (_5.0: usize);
95-
StorageLive(_14);
96-
_14 = <usize as Step>::forward_unchecked(_13, const 1_usize) -> [return: bb4, unwind: bb12];
94+
return;
9795
}
9896

9997
bb4: {
100-
(_5.0: usize) = move _14;
101-
StorageDead(_14);
102-
_12 = Option::<usize>::Some(_13);
103-
goto -> bb5;
98+
StorageDead(_8);
99+
StorageDead(_7);
100+
_12 = (_5.0: usize);
101+
StorageLive(_13);
102+
_13 = <usize as Step>::forward_unchecked(_12, const 1_usize) -> [return: bb5, unwind: bb8];
104103
}
105104

106105
bb5: {
107-
StorageDead(_11);
106+
(_5.0: usize) = move _13;
108107
StorageDead(_13);
109-
_15 = discriminant(_12);
110-
switchInt(move _15) -> [0: bb6, 1: bb8, otherwise: bb11];
111-
}
112-
113-
bb6: {
108+
_14 = Option::<usize>::Some(_12);
109+
StorageDead(_11);
114110
StorageDead(_12);
115-
StorageDead(_5);
116-
drop(_2) -> [return: bb7, unwind continue];
117-
}
118-
119-
bb7: {
120-
return;
111+
_15 = ((_14 as Some).0: usize);
112+
_16 = Len((*_1));
113+
_17 = Lt(_15, _16);
114+
assert(move _17, "index out of bounds: the length is {} but the index is {}", move _16, _15) -> [success: bb6, unwind: bb8];
121115
}
122116

123-
bb8: {
124-
_16 = ((_12 as Some).0: usize);
125-
_17 = Len((*_1));
126-
_18 = Lt(_16, _17);
127-
assert(move _18, "index out of bounds: the length is {} but the index is {}", move _17, _16) -> [success: bb9, unwind: bb12];
128-
}
129-
130-
bb9: {
131-
_19 = &(*_1)[_16];
117+
bb6: {
118+
_18 = &(*_1)[_15];
119+
StorageLive(_19);
120+
_19 = &_2;
132121
StorageLive(_20);
133-
_20 = &_2;
134-
StorageLive(_21);
135-
_21 = (_16, _19);
136-
_22 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _20, move _21) -> [return: bb10, unwind: bb12];
122+
_20 = (_15, _18);
123+
_21 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _19, move _20) -> [return: bb7, unwind: bb8];
137124
}
138125

139-
bb10: {
140-
StorageDead(_21);
126+
bb7: {
141127
StorageDead(_20);
142-
StorageDead(_12);
128+
StorageDead(_19);
129+
StorageDead(_14);
143130
goto -> bb1;
144131
}
145132

146-
bb11: {
147-
unreachable;
148-
}
149-
150-
bb12 (cleanup): {
151-
drop(_2) -> [return: bb13, unwind terminate(cleanup)];
133+
bb8 (cleanup): {
134+
drop(_2) -> [return: bb9, unwind terminate(cleanup)];
152135
}
153136

154-
bb13 (cleanup): {
137+
bb9 (cleanup): {
155138
resume;
156139
}
157140
}

‎tests/mir-opt/pre-codegen/try_identity.new.PreCodegen.after.mir

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,51 @@ fn new(_1: Result<T, E>) -> Result<T, E> {
66
let mut _2: isize;
77
let _3: T;
88
let mut _4: std::ops::ControlFlow<E, T>;
9-
let _5: E;
10-
let mut _6: isize;
11-
let _7: T;
12-
let _8: E;
9+
let _5: T;
10+
let _6: E;
11+
let _7: E;
1312
scope 1 {
1413
debug v => _3;
1514
}
1615
scope 2 {
17-
debug e => _5;
16+
debug e => _6;
1817
}
1918
scope 3 {
20-
debug v => _7;
19+
debug v => _5;
2120
}
2221
scope 4 {
23-
debug e => _8;
22+
debug e => _7;
2423
}
2524

2625
bb0: {
2726
StorageLive(_4);
2827
_2 = discriminant(_1);
29-
switchInt(move _2) -> [0: bb1, 1: bb2, otherwise: bb7];
28+
switchInt(move _2) -> [0: bb1, 1: bb2, otherwise: bb4];
3029
}
3130

3231
bb1: {
3332
_3 = move ((_1 as Ok).0: T);
3433
_4 = ControlFlow::<E, T>::Continue(move _3);
34+
_5 = move ((_4 as Continue).0: T);
35+
_0 = Result::<T, E>::Ok(move _5);
36+
StorageDead(_4);
3537
goto -> bb3;
3638
}
3739

3840
bb2: {
39-
_5 = move ((_1 as Err).0: E);
40-
_4 = ControlFlow::<E, T>::Break(move _5);
41+
_6 = move ((_1 as Err).0: E);
42+
_4 = ControlFlow::<E, T>::Break(move _6);
43+
_7 = move ((_4 as Break).0: E);
44+
_0 = Result::<T, E>::Err(move _7);
45+
StorageDead(_4);
4146
goto -> bb3;
4247
}
4348

4449
bb3: {
45-
_6 = discriminant(_4);
46-
switchInt(move _6) -> [0: bb4, 1: bb5, otherwise: bb7];
47-
}
48-
49-
bb4: {
50-
_7 = move ((_4 as Continue).0: T);
51-
_0 = Result::<T, E>::Ok(move _7);
52-
StorageDead(_4);
53-
goto -> bb6;
54-
}
55-
56-
bb5: {
57-
_8 = move ((_4 as Break).0: E);
58-
_0 = Result::<T, E>::Err(move _8);
59-
StorageDead(_4);
60-
goto -> bb6;
61-
}
62-
63-
bb6: {
6450
return;
6551
}
6652

67-
bb7: {
53+
bb4: {
6854
unreachable;
6955
}
7056
}

‎tests/mir-opt/separate_const_switch.identity.SeparateConstSwitch.diff renamed to ‎tests/mir-opt/separate_const_switch.identity.JumpThreading.diff

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `identity` before SeparateConstSwitch
2-
+ // MIR for `identity` after SeparateConstSwitch
1+
- // MIR for `identity` before JumpThreading
2+
+ // MIR for `identity` after JumpThreading
33

44
fn identity(_1: Result<i32, i32>) -> Result<i32, i32> {
55
debug x => _1;
@@ -60,7 +60,8 @@
6060
StorageDead(_10);
6161
StorageDead(_9);
6262
_5 = discriminant(_3);
63-
switchInt(move _5) -> [0: bb2, 1: bb4, otherwise: bb3];
63+
- switchInt(move _5) -> [0: bb2, 1: bb4, otherwise: bb3];
64+
+ goto -> bb2;
6465
}
6566

6667
bb2: {
@@ -88,7 +89,8 @@
8889
_12 = Result::<Infallible, i32>::Err(move _11);
8990
_3 = ControlFlow::<Result<Infallible, i32>, i32>::Break(move _12);
9091
StorageDead(_12);
91-
goto -> bb1;
92+
- goto -> bb1;
93+
+ goto -> bb8;
9294
}
9395

9496
bb6: {
@@ -99,6 +101,14 @@
99101
_10 = ((_1 as Ok).0: i32);
100102
_3 = ControlFlow::<Result<Infallible, i32>, i32>::Continue(move _10);
101103
goto -> bb1;
104+
+ }
105+
+
106+
+ bb8: {
107+
+ StorageDead(_11);
108+
+ StorageDead(_10);
109+
+ StorageDead(_9);
110+
+ _5 = discriminant(_3);
111+
+ goto -> bb4;
102112
}
103113
}
104114

‎tests/mir-opt/separate_const_switch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use std::ops::ControlFlow;
88

9-
// EMIT_MIR separate_const_switch.too_complex.SeparateConstSwitch.diff
9+
// EMIT_MIR separate_const_switch.too_complex.JumpThreading.diff
1010
fn too_complex(x: Result<i32, usize>) -> Option<i32> {
1111
// The pass should break the outer match into
1212
// two blocks that only have one parent each.
@@ -23,7 +23,7 @@ fn too_complex(x: Result<i32, usize>) -> Option<i32> {
2323
}
2424
}
2525

26-
// EMIT_MIR separate_const_switch.identity.SeparateConstSwitch.diff
26+
// EMIT_MIR separate_const_switch.identity.JumpThreading.diff
2727
fn identity(x: Result<i32, i32>) -> Result<i32, i32> {
2828
Ok(x?)
2929
}

‎tests/mir-opt/separate_const_switch.too_complex.SeparateConstSwitch.diff renamed to ‎tests/mir-opt/separate_const_switch.too_complex.JumpThreading.diff

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `too_complex` before SeparateConstSwitch
2-
+ // MIR for `too_complex` after SeparateConstSwitch
1+
- // MIR for `too_complex` before JumpThreading
2+
+ // MIR for `too_complex` after JumpThreading
33

44
fn too_complex(_1: Result<i32, usize>) -> Option<i32> {
55
debug x => _1;
@@ -36,7 +36,8 @@
3636
bb1: {
3737
_6 = ((_1 as Err).0: usize);
3838
_2 = ControlFlow::<usize, i32>::Break(_6);
39-
goto -> bb4;
39+
- goto -> bb4;
40+
+ goto -> bb8;
4041
}
4142

4243
bb2: {
@@ -51,7 +52,8 @@
5152

5253
bb4: {
5354
_8 = discriminant(_2);
54-
switchInt(move _8) -> [0: bb6, 1: bb5, otherwise: bb2];
55+
- switchInt(move _8) -> [0: bb6, 1: bb5, otherwise: bb2];
56+
+ goto -> bb6;
5557
}
5658

5759
bb5: {
@@ -71,6 +73,11 @@
7173
bb7: {
7274
StorageDead(_2);
7375
return;
76+
+ }
77+
+
78+
+ bb8: {
79+
+ _8 = discriminant(_2);
80+
+ goto -> bb5;
7481
}
7582
}
7683

0 commit comments

Comments
 (0)
This repository has been archived.