Skip to content

Commit b74a144

Browse files
committed
Enable by default.
1 parent 341e0f7 commit b74a144

22 files changed

+574
-761
lines changed

compiler/rustc_mir_transform/src/ref_prop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub struct ReferencePropagation;
7171

7272
impl<'tcx> MirPass<'tcx> for ReferencePropagation {
7373
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
74-
sess.mir_opt_level() >= 4
74+
sess.mir_opt_level() >= 2
7575
}
7676

7777
#[instrument(level = "trace", skip(self, tcx, body))]

tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.Inline.panic-abort.diff

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
let mut _2: std::option::Option<T>;
88
+ scope 1 (inlined #[track_caller] Option::<T>::unwrap_unchecked) {
99
+ debug self => _2;
10-
+ let mut _3: &std::option::Option<T>;
11-
+ let mut _4: isize;
10+
+ let mut _3: isize;
1211
+ scope 2 {
1312
+ debug val => _0;
1413
+ }
@@ -21,17 +20,16 @@
2120
+ }
2221
+ }
2322
+ scope 4 (inlined Option::<T>::is_some) {
24-
+ debug self => _3;
23+
+ debug self => &_2;
2524
+ }
2625
+ }
2726

2827
bb0: {
2928
StorageLive(_2);
3029
_2 = move _1;
3130
- _0 = Option::<T>::unwrap_unchecked(move _2) -> [return: bb1, unwind unreachable];
32-
+ StorageLive(_3);
33-
+ _4 = discriminant(_2);
34-
+ switchInt(move _4) -> [1: bb2, otherwise: bb1];
31+
+ _3 = discriminant(_2);
32+
+ switchInt(move _3) -> [1: bb2, otherwise: bb1];
3533
}
3634

3735
bb1: {
@@ -40,7 +38,6 @@
4038
+
4139
+ bb2: {
4240
+ _0 = move ((_2 as Some).0: T);
43-
+ StorageDead(_3);
4441
StorageDead(_2);
4542
return;
4643
}

tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.Inline.panic-unwind.diff

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
let mut _2: std::option::Option<T>;
88
+ scope 1 (inlined #[track_caller] Option::<T>::unwrap_unchecked) {
99
+ debug self => _2;
10-
+ let mut _3: &std::option::Option<T>;
11-
+ let mut _4: isize;
10+
+ let mut _3: isize;
1211
+ scope 2 {
1312
+ debug val => _0;
1413
+ }
@@ -21,17 +20,16 @@
2120
+ }
2221
+ }
2322
+ scope 4 (inlined Option::<T>::is_some) {
24-
+ debug self => _3;
23+
+ debug self => &_2;
2524
+ }
2625
+ }
2726

2827
bb0: {
2928
StorageLive(_2);
3029
_2 = move _1;
3130
- _0 = Option::<T>::unwrap_unchecked(move _2) -> [return: bb1, unwind: bb2];
32-
+ StorageLive(_3);
33-
+ _4 = discriminant(_2);
34-
+ switchInt(move _4) -> [1: bb2, otherwise: bb1];
31+
+ _3 = discriminant(_2);
32+
+ switchInt(move _3) -> [1: bb2, otherwise: bb1];
3533
}
3634

3735
bb1: {
@@ -44,7 +42,6 @@
4442
- resume;
4543
+ bb2: {
4644
+ _0 = move ((_2 as Some).0: T);
47-
+ StorageDead(_3);
4845
+ StorageDead(_2);
4946
+ return;
5047
}

tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.PreCodegen.after.panic-abort.mir

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ fn unwrap_unchecked(_1: Option<T>) -> T {
66
scope 1 (inlined #[track_caller] Option::<T>::unwrap_unchecked) {
77
debug self => _1;
88
let mut _2: isize;
9-
let mut _3: &std::option::Option<T>;
109
scope 2 {
1110
debug val => _0;
1211
}
@@ -19,19 +18,17 @@ fn unwrap_unchecked(_1: Option<T>) -> T {
1918
}
2019
}
2120
scope 4 (inlined Option::<T>::is_some) {
22-
debug self => _3;
21+
debug self => &_1;
2322
}
2423
}
2524

2625
bb0: {
27-
StorageLive(_3);
2826
_2 = discriminant(_1);
2927
switchInt(move _2) -> [1: bb1, otherwise: bb2];
3028
}
3129

3230
bb1: {
3331
_0 = move ((_1 as Some).0: T);
34-
StorageDead(_3);
3532
return;
3633
}
3734

tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.PreCodegen.after.panic-unwind.mir

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ fn unwrap_unchecked(_1: Option<T>) -> T {
66
scope 1 (inlined #[track_caller] Option::<T>::unwrap_unchecked) {
77
debug self => _1;
88
let mut _2: isize;
9-
let mut _3: &std::option::Option<T>;
109
scope 2 {
1110
debug val => _0;
1211
}
@@ -19,19 +18,17 @@ fn unwrap_unchecked(_1: Option<T>) -> T {
1918
}
2019
}
2120
scope 4 (inlined Option::<T>::is_some) {
22-
debug self => _3;
21+
debug self => &_1;
2322
}
2423
}
2524

2625
bb0: {
27-
StorageLive(_3);
2826
_2 = discriminant(_1);
2927
switchInt(move _2) -> [1: bb1, otherwise: bb2];
3028
}
3129

3230
bb1: {
3331
_0 = move ((_1 as Some).0: T);
34-
StorageDead(_3);
3532
return;
3633
}
3734

tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-abort.mir

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,53 @@
33
fn num_to_digit(_1: char) -> u32 {
44
debug num => _1;
55
let mut _0: u32;
6-
let mut _5: std::option::Option<u32>;
6+
let mut _4: std::option::Option<u32>;
77
scope 1 (inlined char::methods::<impl char>::is_digit) {
88
debug self => _1;
99
debug radix => const 8_u32;
1010
let _2: std::option::Option<u32>;
11-
let mut _3: &std::option::Option<u32>;
1211
scope 2 (inlined Option::<u32>::is_some) {
13-
debug self => _3;
14-
let mut _4: isize;
12+
debug self => &_2;
13+
let mut _3: isize;
1514
}
1615
}
1716
scope 3 (inlined #[track_caller] Option::<u32>::unwrap) {
18-
debug self => _5;
19-
let mut _6: isize;
20-
let mut _7: !;
17+
debug self => _4;
18+
let mut _5: isize;
19+
let mut _6: !;
2120
scope 4 {
2221
debug val => _0;
2322
}
2423
}
2524

2625
bb0: {
27-
StorageLive(_3);
2826
StorageLive(_2);
2927
_2 = char::methods::<impl char>::to_digit(_1, const 8_u32) -> [return: bb1, unwind unreachable];
3028
}
3129

3230
bb1: {
33-
_3 = &_2;
34-
_4 = discriminant((*_3));
35-
StorageDead(_3);
31+
_3 = discriminant(_2);
3632
StorageDead(_2);
37-
switchInt(move _4) -> [1: bb2, otherwise: bb7];
33+
switchInt(move _3) -> [1: bb2, otherwise: bb7];
3834
}
3935

4036
bb2: {
41-
StorageLive(_5);
42-
_5 = char::methods::<impl char>::to_digit(_1, const 8_u32) -> [return: bb3, unwind unreachable];
37+
StorageLive(_4);
38+
_4 = char::methods::<impl char>::to_digit(_1, const 8_u32) -> [return: bb3, unwind unreachable];
4339
}
4440

4541
bb3: {
46-
_6 = discriminant(_5);
47-
switchInt(move _6) -> [0: bb4, 1: bb5, otherwise: bb6];
42+
_5 = discriminant(_4);
43+
switchInt(move _5) -> [0: bb4, 1: bb5, otherwise: bb6];
4844
}
4945

5046
bb4: {
51-
_7 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind unreachable;
47+
_6 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind unreachable;
5248
}
5349

5450
bb5: {
55-
_0 = move ((_5 as Some).0: u32);
56-
StorageDead(_5);
51+
_0 = move ((_4 as Some).0: u32);
52+
StorageDead(_4);
5753
goto -> bb8;
5854
}
5955

tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-unwind.mir

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,53 @@
33
fn num_to_digit(_1: char) -> u32 {
44
debug num => _1;
55
let mut _0: u32;
6-
let mut _5: std::option::Option<u32>;
6+
let mut _4: std::option::Option<u32>;
77
scope 1 (inlined char::methods::<impl char>::is_digit) {
88
debug self => _1;
99
debug radix => const 8_u32;
1010
let _2: std::option::Option<u32>;
11-
let mut _3: &std::option::Option<u32>;
1211
scope 2 (inlined Option::<u32>::is_some) {
13-
debug self => _3;
14-
let mut _4: isize;
12+
debug self => &_2;
13+
let mut _3: isize;
1514
}
1615
}
1716
scope 3 (inlined #[track_caller] Option::<u32>::unwrap) {
18-
debug self => _5;
19-
let mut _6: isize;
20-
let mut _7: !;
17+
debug self => _4;
18+
let mut _5: isize;
19+
let mut _6: !;
2120
scope 4 {
2221
debug val => _0;
2322
}
2423
}
2524

2625
bb0: {
27-
StorageLive(_3);
2826
StorageLive(_2);
2927
_2 = char::methods::<impl char>::to_digit(_1, const 8_u32) -> [return: bb1, unwind continue];
3028
}
3129

3230
bb1: {
33-
_3 = &_2;
34-
_4 = discriminant((*_3));
35-
StorageDead(_3);
31+
_3 = discriminant(_2);
3632
StorageDead(_2);
37-
switchInt(move _4) -> [1: bb2, otherwise: bb7];
33+
switchInt(move _3) -> [1: bb2, otherwise: bb7];
3834
}
3935

4036
bb2: {
41-
StorageLive(_5);
42-
_5 = char::methods::<impl char>::to_digit(_1, const 8_u32) -> [return: bb3, unwind continue];
37+
StorageLive(_4);
38+
_4 = char::methods::<impl char>::to_digit(_1, const 8_u32) -> [return: bb3, unwind continue];
4339
}
4440

4541
bb3: {
46-
_6 = discriminant(_5);
47-
switchInt(move _6) -> [0: bb4, 1: bb5, otherwise: bb6];
42+
_5 = discriminant(_4);
43+
switchInt(move _5) -> [0: bb4, 1: bb5, otherwise: bb6];
4844
}
4945

5046
bb4: {
51-
_7 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind continue;
47+
_6 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind continue;
5248
}
5349

5450
bb5: {
55-
_0 = move ((_5 as Some).0: u32);
56-
StorageDead(_5);
51+
_0 = move ((_4 as Some).0: u32);
52+
StorageDead(_4);
5753
goto -> bb8;
5854
}
5955

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

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,50 @@ fn step_forward(_1: u32, _2: usize) -> u32 {
88
debug start => _1;
99
debug n => _2;
1010
let _3: std::option::Option<u32>;
11-
let mut _4: &std::option::Option<u32>;
12-
let mut _7: bool;
13-
let mut _8: u32;
11+
let mut _6: bool;
12+
let mut _7: u32;
1413
scope 2 {
1514
}
1615
scope 3 (inlined Option::<u32>::is_none) {
17-
debug self => _4;
18-
let mut _6: bool;
16+
debug self => &_3;
17+
let mut _5: bool;
1918
scope 4 (inlined Option::<u32>::is_some) {
20-
debug self => _4;
21-
let mut _5: isize;
19+
debug self => &_3;
20+
let mut _4: isize;
2221
}
2322
}
2423
scope 5 (inlined core::num::<impl u32>::wrapping_add) {
2524
debug self => _1;
26-
debug rhs => _8;
25+
debug rhs => _7;
2726
}
2827
}
2928

3029
bb0: {
31-
StorageLive(_7);
32-
StorageLive(_4);
30+
StorageLive(_6);
3331
StorageLive(_3);
3432
_3 = <u32 as Step>::forward_checked(_1, _2) -> [return: bb1, unwind continue];
3533
}
3634

3735
bb1: {
38-
_4 = &_3;
39-
StorageLive(_6);
40-
_5 = discriminant((*_4));
41-
_6 = Eq(_5, const 1_isize);
42-
_7 = Not(move _6);
43-
StorageDead(_6);
36+
StorageLive(_5);
37+
_4 = discriminant(_3);
38+
_5 = Eq(_4, const 1_isize);
39+
_6 = Not(move _5);
40+
StorageDead(_5);
4441
StorageDead(_3);
45-
StorageDead(_4);
46-
switchInt(move _7) -> [0: bb3, otherwise: bb2];
42+
switchInt(move _6) -> [0: bb3, otherwise: bb2];
4743
}
4844

4945
bb2: {
5046
assert(!const true, "attempt to compute `{} + {}`, which would overflow", const _, const 1_u32) -> [success: bb3, unwind continue];
5147
}
5248

5349
bb3: {
50+
StorageDead(_6);
51+
StorageLive(_7);
52+
_7 = _2 as u32 (IntToInt);
53+
_0 = Add(_1, _7);
5454
StorageDead(_7);
55-
StorageLive(_8);
56-
_8 = _2 as u32 (IntToInt);
57-
_0 = Add(_1, _8);
58-
StorageDead(_8);
5955
return;
6056
}
6157
}

0 commit comments

Comments
 (0)