Skip to content

Commit b860a54

Browse files
committed
Only run return terminator opt if mir-opt-level=3
1 parent 1906f5f commit b860a54

10 files changed

+66
-28
lines changed

src/librustc_mir/transform/multiple_return_terminators.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ use rustc_middle::ty::TyCtxt;
99
pub struct MultipleReturnTerminators;
1010

1111
impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
12-
fn run_pass(&self, _: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) {
12+
fn run_pass(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) {
13+
if tcx.sess.opts.debugging_opts.mir_opt_level < 3 {
14+
return;
15+
}
16+
1317
// find basic blocks with no statement and a return terminator
1418
let mut bbs_simple_returns = BitSet::new_empty(body.basic_blocks().len());
1519
let bbs = body.basic_blocks_mut();

src/test/mir-opt/multiple_return_terminators.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// compile-flags: -Z mir-opt-level=3
12
// EMIT_MIR multiple_return_terminators.test.MultipleReturnTerminators.diff
23

34
fn test(x: bool) {

src/test/mir-opt/multiple_return_terminators.test.MultipleReturnTerminators.diff

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
+ // MIR for `test` after MultipleReturnTerminators
33

44
fn test(_1: bool) -> () {
5-
debug x => _1; // in scope 0 at $DIR/multiple_return_terminators.rs:3:9: 3:10
6-
let mut _0: (); // return place in scope 0 at $DIR/multiple_return_terminators.rs:3:18: 3:18
5+
debug x => _1; // in scope 0 at $DIR/multiple_return_terminators.rs:4:9: 4:10
6+
let mut _0: (); // return place in scope 0 at $DIR/multiple_return_terminators.rs:4:18: 4:18
77

88
bb0: {
9-
switchInt(_1) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/multiple_return_terminators.rs:4:5: 8:6
9+
switchInt(_1) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/multiple_return_terminators.rs:5:5: 9:6
1010
}
1111

1212
bb1: {
13-
_0 = const (); // scope 0 at $DIR/multiple_return_terminators.rs:6:12: 8:6
14-
- goto -> bb3; // scope 0 at $DIR/multiple_return_terminators.rs:4:5: 8:6
15-
+ return; // scope 0 at $DIR/multiple_return_terminators.rs:4:5: 8:6
13+
_0 = const (); // scope 0 at $DIR/multiple_return_terminators.rs:7:12: 9:6
14+
- goto -> bb3; // scope 0 at $DIR/multiple_return_terminators.rs:5:5: 9:6
15+
+ return; // scope 0 at $DIR/multiple_return_terminators.rs:5:5: 9:6
1616
}
1717

1818
bb2: {
19-
_0 = const (); // scope 0 at $DIR/multiple_return_terminators.rs:4:10: 6:6
20-
- goto -> bb3; // scope 0 at $DIR/multiple_return_terminators.rs:4:5: 8:6
19+
_0 = const (); // scope 0 at $DIR/multiple_return_terminators.rs:5:10: 7:6
20+
- goto -> bb3; // scope 0 at $DIR/multiple_return_terminators.rs:5:5: 9:6
2121
- }
2222
-
2323
- bb3: {
24-
- return; // scope 0 at $DIR/multiple_return_terminators.rs:9:2: 9:2
25-
+ return; // scope 0 at $DIR/multiple_return_terminators.rs:4:5: 8:6
24+
- return; // scope 0 at $DIR/multiple_return_terminators.rs:10:2: 10:2
25+
+ return; // scope 0 at $DIR/multiple_return_terminators.rs:5:5: 9:6
2626
}
2727
}
2828

src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff

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

2020
bb1: {
2121
discriminant(_0) = 0; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21
22-
return; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
22+
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
2323
}
2424

2525
bb2: {
@@ -36,7 +36,11 @@
3636
- StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:11:26: 11:27
3737
- StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:11:26: 11:27
3838
+ _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
39-
return; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
39+
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
40+
}
41+
42+
bb4: {
43+
return; // scope 0 at $DIR/simplify-arm.rs:14:2: 14:2
4044
}
4145
}
4246

src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
bb1: {
2121
- discriminant(_0) = 0; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21
22-
- return; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
22+
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
2323
- }
2424
-
2525
- bb2: {
@@ -28,7 +28,13 @@
2828
-
2929
- bb3: {
3030
_0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
31-
return; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
31+
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
32+
+ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
33+
}
34+
35+
- bb4: {
36+
+ bb2: {
37+
return; // scope 0 at $DIR/simplify-arm.rs:14:2: 14:2
3238
}
3339
}
3440

src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
- StorageDead(_6); // scope 2 at $DIR/simplify-arm.rs:19:24: 19:25
3434
- StorageDead(_5); // scope 0 at $DIR/simplify-arm.rs:19:24: 19:25
3535
+ _0 = move _1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
36-
return; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
36+
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
3737
}
3838

3939
bb2: {
@@ -50,7 +50,11 @@
5050
- StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:18:22: 18:23
5151
- StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:18:22: 18:23
5252
+ _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
53-
return; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
53+
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
54+
}
55+
56+
bb4: {
57+
return; // scope 0 at $DIR/simplify-arm.rs:21:2: 21:2
5458
}
5559
}
5660

src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff

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

2525
bb1: {
2626
- _0 = move _1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
27-
- return; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
27+
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
2828
- }
2929
-
3030
- bb2: {
@@ -33,7 +33,13 @@
3333
-
3434
- bb3: {
3535
_0 = move _1; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
36-
return; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
36+
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
37+
+ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
38+
}
39+
40+
- bb4: {
41+
+ bb2: {
42+
return; // scope 0 at $DIR/simplify-arm.rs:21:2: 21:2
3743
}
3844
}
3945

src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
- discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
6868
- StorageDead(_11); // scope 1 at $DIR/simplify-arm.rs:25:9: 25:10
6969
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
70-
return; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
70+
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
7171
}
7272

7373
bb2: {
@@ -92,7 +92,11 @@
9292
+ _0 = move _3; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
9393
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16
9494
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
95-
return; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
95+
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
96+
}
97+
98+
bb4: {
99+
return; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
96100
}
97101
}
98102

src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,23 @@
5454
_0 = move _3; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
5555
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16
5656
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
57-
return; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
58-
- }
59-
-
60-
- bb2: {
57+
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
58+
+ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
59+
}
60+
61+
bb2: {
6162
- unreachable; // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
6263
- }
6364
-
6465
- bb3: {
6566
- _0 = move _3; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
6667
- StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16
6768
- StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
68-
- return; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
69+
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
70+
- }
71+
-
72+
- bb4: {
73+
return; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
6974
}
7075
}
7176

src/test/mir-opt/simplify_try_if_let.{{impl}}-append.SimplifyArmIdentity.diff

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

4848
bb3: {
4949
_0 = const (); // scope 0 at $DIR/simplify_try_if_let.rs:22:21: 22:24
50-
return; // scope 0 at $DIR/simplify_try_if_let.rs:21:9: 32:10
50+
goto -> bb9; // scope 0 at $DIR/simplify_try_if_let.rs:21:9: 32:10
5151
}
5252

5353
bb4: {
@@ -92,7 +92,11 @@
9292
bb8: {
9393
StorageDead(_5); // scope 1 at $DIR/simplify_try_if_let.rs:31:13: 31:14
9494
StorageDead(_4); // scope 0 at $DIR/simplify_try_if_let.rs:31:13: 31:14
95-
return; // scope 0 at $DIR/simplify_try_if_let.rs:21:9: 32:10
95+
goto -> bb9; // scope 0 at $DIR/simplify_try_if_let.rs:21:9: 32:10
96+
}
97+
98+
bb9: {
99+
return; // scope 0 at $DIR/simplify_try_if_let.rs:33:6: 33:6
96100
}
97101
}
98102

0 commit comments

Comments
 (0)