Skip to content

Commit e78394c

Browse files
committed
WIP enable by default.
1 parent 2e4e2a8 commit e78394c

9 files changed

+235
-355
lines changed

compiler/rustc_mir_transform/src/jump_threading.rs

+1-1
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")]

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

+1-55
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

+24-41
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
}

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

+33
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

+34-51
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
}

0 commit comments

Comments
 (0)