Skip to content

Commit 5b99523

Browse files
committed
rustc_mir::transform::simplify - remove nops first
Removing nops can allow more basic blocks to be merged, but merging basic blocks can't allow for more nops to be removed, so we should remove nops first. This doesn't matter *that* much, because normally we run SimplifyCfg several times, but there's no reason not to do it.
1 parent ca3105c commit 5b99523

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

src/librustc_mir/transform/simplify.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ impl<'a, 'tcx: 'a> CfgSimplifier<'a, 'tcx> {
105105
}
106106

107107
pub fn simplify(mut self) {
108+
self.strip_nops();
109+
108110
loop {
109111
let mut changed = false;
110112

@@ -141,8 +143,6 @@ impl<'a, 'tcx: 'a> CfgSimplifier<'a, 'tcx> {
141143

142144
if !changed { break }
143145
}
144-
145-
self.strip_nops()
146146
}
147147

148148
// Collapse a goto chain starting from `start`

src/test/mir-opt/basic_assignment.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ fn main() {
5050
// StorageLive(_5);
5151
// StorageLive(_6);
5252
// _6 = _4;
53-
// replace(_5 <- _6) -> [return: bb1, unwind: bb7];
53+
// replace(_5 <- _6) -> [return: bb1, unwind: bb5];
5454
// }
5555
// bb1: {
56-
// drop(_6) -> [return: bb8, unwind: bb5];
56+
// drop(_6) -> [return: bb6, unwind: bb4];
5757
// }
5858
// bb2: {
5959
// resume;
@@ -62,27 +62,21 @@ fn main() {
6262
// drop(_4) -> bb2;
6363
// }
6464
// bb4: {
65-
// goto -> bb3;
65+
// drop(_5) -> bb3;
6666
// }
6767
// bb5: {
68-
// drop(_5) -> bb4;
68+
// drop(_6) -> bb4;
6969
// }
7070
// bb6: {
71-
// goto -> bb5;
72-
// }
73-
// bb7: {
74-
// drop(_6) -> bb6;
75-
// }
76-
// bb8: {
7771
// StorageDead(_6);
7872
// _0 = ();
79-
// drop(_5) -> [return: bb9, unwind: bb3];
73+
// drop(_5) -> [return: bb7, unwind: bb3];
8074
// }
81-
// bb9: {
75+
// bb7: {
8276
// StorageDead(_5);
83-
// drop(_4) -> bb10;
77+
// drop(_4) -> bb8;
8478
// }
85-
// bb10: {
79+
// bb8: {
8680
// StorageDead(_4);
8781
// StorageDead(_2);
8882
// StorageDead(_1);

0 commit comments

Comments
 (0)