Skip to content

Commit 8536b02

Browse files
committed
Enable by default.
1 parent 4ad11ad commit 8536b02

8 files changed

+186
-177
lines changed

compiler/rustc_mir_transform/src/jump_threading.rs

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

6161
impl<'tcx> MirPass<'tcx> for JumpThreading {
6262
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
63-
sess.mir_opt_level() >= 4
63+
sess.mir_opt_level() >= 2
6464
}
6565

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

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

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn int_range(_1: usize, _2: usize) -> () {
88
let mut _4: std::ops::Range<usize>;
99
let mut _5: &mut std::ops::Range<usize>;
1010
let mut _11: std::option::Option<usize>;
11-
let mut _14: isize;
11+
let mut _12: isize;
1212
let _16: ();
1313
scope 1 {
1414
debug iter => _4;
@@ -23,10 +23,10 @@ fn int_range(_1: usize, _2: usize) -> () {
2323
let mut _6: &usize;
2424
let mut _7: &usize;
2525
let mut _10: bool;
26-
let _12: usize;
27-
let mut _13: usize;
26+
let _13: usize;
27+
let mut _14: usize;
2828
scope 6 {
29-
debug old => _12;
29+
debug old => _13;
3030
scope 7 {
3131
}
3232
}
@@ -53,7 +53,7 @@ fn int_range(_1: usize, _2: usize) -> () {
5353
bb1: {
5454
StorageLive(_11);
5555
_5 = &mut _4;
56-
StorageLive(_12);
56+
StorageLive(_13);
5757
StorageLive(_10);
5858
StorageLive(_6);
5959
_6 = &(_4.0: usize);
@@ -66,42 +66,44 @@ fn int_range(_1: usize, _2: usize) -> () {
6666
_10 = Lt(move _8, move _9);
6767
StorageDead(_9);
6868
StorageDead(_8);
69-
switchInt(move _10) -> [0: bb2, otherwise: bb3];
69+
switchInt(move _10) -> [0: bb2, otherwise: bb5];
7070
}
7171

7272
bb2: {
7373
StorageDead(_7);
7474
StorageDead(_6);
7575
_11 = const Option::<usize>::None;
76-
goto -> bb5;
76+
StorageDead(_10);
77+
StorageDead(_13);
78+
_12 = discriminant(_11);
79+
switchInt(move _12) -> [0: bb3, 1: bb7, otherwise: bb4];
7780
}
7881

7982
bb3: {
80-
StorageDead(_7);
81-
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];
83+
StorageDead(_11);
84+
StorageDead(_4);
85+
return;
8586
}
8687

8788
bb4: {
88-
(_4.0: usize) = move _13;
89-
StorageDead(_13);
90-
_11 = Option::<usize>::Some(_12);
91-
goto -> bb5;
89+
unreachable;
9290
}
9391

9492
bb5: {
95-
StorageDead(_10);
96-
StorageDead(_12);
97-
_14 = discriminant(_11);
98-
switchInt(move _14) -> [0: bb6, 1: bb7, otherwise: bb9];
93+
StorageDead(_7);
94+
StorageDead(_6);
95+
_13 = (_4.0: usize);
96+
StorageLive(_14);
97+
_14 = <usize as Step>::forward_unchecked(_13, const 1_usize) -> [return: bb6, unwind continue];
9998
}
10099

101100
bb6: {
102-
StorageDead(_11);
103-
StorageDead(_4);
104-
return;
101+
(_4.0: usize) = move _14;
102+
StorageDead(_14);
103+
_11 = Option::<usize>::Some(_13);
104+
StorageDead(_10);
105+
StorageDead(_13);
106+
goto -> bb7;
105107
}
106108

107109
bb7: {
@@ -113,10 +115,6 @@ fn int_range(_1: usize, _2: usize) -> () {
113115
StorageDead(_11);
114116
goto -> bb1;
115117
}
116-
117-
bb9: {
118-
unreachable;
119-
}
120118
}
121119

122120
ALLOC0 (size: 16, align: 8) {

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 std::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 std::ptr::const_ptr::<impl *const T>::is_null::runtime_impl) {
27+
debug ptr => _5;
28+
scope 23 (inlined std::ptr::const_ptr::<impl *const u8>::addr) {
29+
debug self => _5;
30+
scope 24 {
31+
scope 25 (inlined std::ptr::const_ptr::<impl *const u8>::cast::<()>) {
32+
debug self => _5;
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}
39+
scope 26 (inlined std::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: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
99
let mut _5: std::ops::Range<u32>;
1010
let mut _6: &mut std::ops::Range<u32>;
1111
let mut _12: std::option::Option<u32>;
12-
let mut _15: isize;
12+
let mut _13: isize;
1313
let mut _17: &impl Fn(u32);
1414
let mut _18: (u32,);
1515
let _19: ();
@@ -26,10 +26,10 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
2626
let mut _7: &u32;
2727
let mut _8: &u32;
2828
let mut _11: bool;
29-
let _13: u32;
30-
let mut _14: u32;
29+
let _14: u32;
30+
let mut _15: u32;
3131
scope 6 {
32-
debug old => _13;
32+
debug old => _14;
3333
scope 7 {
3434
}
3535
}
@@ -56,7 +56,7 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
5656
bb1: {
5757
StorageLive(_12);
5858
_6 = &mut _5;
59-
StorageLive(_13);
59+
StorageLive(_14);
6060
StorageLive(_11);
6161
StorageLive(_7);
6262
_7 = &(_5.0: u32);
@@ -69,46 +69,48 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
6969
_11 = Lt(move _9, move _10);
7070
StorageDead(_10);
7171
StorageDead(_9);
72-
switchInt(move _11) -> [0: bb2, otherwise: bb3];
72+
switchInt(move _11) -> [0: bb2, otherwise: bb6];
7373
}
7474

7575
bb2: {
7676
StorageDead(_8);
7777
StorageDead(_7);
7878
_12 = const Option::<u32>::None;
79-
goto -> bb5;
79+
StorageDead(_11);
80+
StorageDead(_14);
81+
_13 = discriminant(_12);
82+
switchInt(move _13) -> [0: bb3, 1: bb8, otherwise: bb5];
8083
}
8184

8285
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];
86+
StorageDead(_12);
87+
StorageDead(_5);
88+
drop(_3) -> [return: bb4, unwind unreachable];
8889
}
8990

9091
bb4: {
91-
(_5.0: u32) = move _14;
92-
StorageDead(_14);
93-
_12 = Option::<u32>::Some(_13);
94-
goto -> bb5;
92+
return;
9593
}
9694

9795
bb5: {
98-
StorageDead(_11);
99-
StorageDead(_13);
100-
_15 = discriminant(_12);
101-
switchInt(move _15) -> [0: bb6, 1: bb8, otherwise: bb10];
96+
unreachable;
10297
}
10398

10499
bb6: {
105-
StorageDead(_12);
106-
StorageDead(_5);
107-
drop(_3) -> [return: bb7, unwind unreachable];
100+
StorageDead(_8);
101+
StorageDead(_7);
102+
_14 = (_5.0: u32);
103+
StorageLive(_15);
104+
_15 = <u32 as Step>::forward_unchecked(_14, const 1_usize) -> [return: bb7, unwind unreachable];
108105
}
109106

110107
bb7: {
111-
return;
108+
(_5.0: u32) = move _15;
109+
StorageDead(_15);
110+
_12 = Option::<u32>::Some(_14);
111+
StorageDead(_11);
112+
StorageDead(_14);
113+
goto -> bb8;
112114
}
113115

114116
bb8: {
@@ -126,10 +128,6 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
126128
StorageDead(_12);
127129
goto -> bb1;
128130
}
129-
130-
bb10: {
131-
unreachable;
132-
}
133131
}
134132

135133
ALLOC0 (size: 8, align: 4) {

0 commit comments

Comments
 (0)