diff --git a/src/librustc_mir/transform/simplify_try.rs b/src/librustc_mir/transform/simplify_try.rs index 61f9c281559b7..50136ac3becca 100644 --- a/src/librustc_mir/transform/simplify_try.rs +++ b/src/librustc_mir/transform/simplify_try.rs @@ -306,7 +306,11 @@ fn optimization_applies<'tcx>( } impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity { - fn run_pass(&self, _: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) { + if tcx.sess.opts.debugging_opts.mir_opt_level < 2 { + return; + } + trace!("running SimplifyArmIdentity on {:?}", source); let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut(); for bb in basic_blocks { diff --git a/src/test/mir-opt/simplify-arm/rustc.id.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify-arm/rustc.id.SimplifyArmIdentity.diff index 8d08267d75bfd..8bb28206964f1 100644 --- a/src/test/mir-opt/simplify-arm/rustc.id.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify-arm/rustc.id.SimplifyArmIdentity.diff @@ -26,15 +26,14 @@ } bb3: { -- StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15 -- _3 = ((_1 as Some).0: u8); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15 -- StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26 -- _4 = _3; // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26 -- ((_0 as Some).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27 -- discriminant(_0) = 1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27 -- StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:11:26: 11:27 -- StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:11:27: 11:28 -+ _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27 + StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15 + _3 = ((_1 as Some).0: u8); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15 + StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26 + _4 = _3; // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26 + ((_0 as Some).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27 + discriminant(_0) = 1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27 + StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:11:26: 11:27 + StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:11:27: 11:28 goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 } diff --git a/src/test/mir-opt/simplify-arm/rustc.id.SimplifyBranchSame.diff b/src/test/mir-opt/simplify-arm/rustc.id.SimplifyBranchSame.diff index 23fa9817f80f6..1226b4feaf41f 100644 --- a/src/test/mir-opt/simplify-arm/rustc.id.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify-arm/rustc.id.SimplifyBranchSame.diff @@ -26,7 +26,14 @@ } bb3: { - _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27 + StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15 + _3 = ((_1 as Some).0: u8); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15 + StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26 + _4 = _3; // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26 + ((_0 as Some).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27 + discriminant(_0) = 1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27 + StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:11:26: 11:27 + StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:11:27: 11:28 goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 } diff --git a/src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyArmIdentity.diff index e2a12ca5be26c..5a5d67b36d9a5 100644 --- a/src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyArmIdentity.diff @@ -22,15 +22,14 @@ } bb1: { -- StorageLive(_5); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14 -- _5 = ((_1 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14 -- StorageLive(_6); // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24 -- _6 = _5; // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24 -- ((_0 as Err).0: i32) = move _6; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25 -- discriminant(_0) = 1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25 -- StorageDead(_6); // scope 2 at $DIR/simplify-arm.rs:19:24: 19:25 -- StorageDead(_5); // scope 0 at $DIR/simplify-arm.rs:19:25: 19:26 -+ _0 = move _1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25 + StorageLive(_5); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14 + _5 = ((_1 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14 + StorageLive(_6); // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24 + _6 = _5; // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24 + ((_0 as Err).0: i32) = move _6; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25 + discriminant(_0) = 1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25 + StorageDead(_6); // scope 2 at $DIR/simplify-arm.rs:19:24: 19:25 + StorageDead(_5); // scope 0 at $DIR/simplify-arm.rs:19:25: 19:26 goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 } @@ -39,15 +38,14 @@ } bb3: { -- StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13 -- _3 = ((_1 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13 -- StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22 -- _4 = _3; // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22 -- ((_0 as Ok).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23 -- discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23 -- StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:18:22: 18:23 -- StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:18:23: 18:24 -+ _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23 + StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13 + _3 = ((_1 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13 + StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22 + _4 = _3; // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22 + ((_0 as Ok).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23 + discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23 + StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:18:22: 18:23 + StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:18:23: 18:24 goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 } diff --git a/src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyBranchSame.diff b/src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyBranchSame.diff index 9d1ff22dc5109..e82865162615e 100644 --- a/src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyBranchSame.diff @@ -18,27 +18,38 @@ bb0: { _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 -- switchInt(move _2) -> [0isize: bb3, 1isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 -+ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 + switchInt(move _2) -> [0isize: bb3, 1isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 } bb1: { -- _0 = move _1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25 -- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 -- } -- -- bb2: { -- unreachable; // scope 0 at $DIR/simplify-arm.rs:17:11: 17:12 -- } -- -- bb3: { - _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23 -- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 -+ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 + StorageLive(_5); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14 + _5 = ((_1 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14 + StorageLive(_6); // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24 + _6 = _5; // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24 + ((_0 as Err).0: i32) = move _6; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25 + discriminant(_0) = 1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25 + StorageDead(_6); // scope 2 at $DIR/simplify-arm.rs:19:24: 19:25 + StorageDead(_5); // scope 0 at $DIR/simplify-arm.rs:19:25: 19:26 + goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 } -- bb4: { -+ bb2: { + bb2: { + unreachable; // scope 0 at $DIR/simplify-arm.rs:17:11: 17:12 + } + + bb3: { + StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13 + _3 = ((_1 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13 + StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22 + _4 = _3; // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22 + ((_0 as Ok).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23 + discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23 + StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:18:22: 18:23 + StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:18:23: 18:24 + goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 + } + + bb4: { return; // scope 0 at $DIR/simplify-arm.rs:21:2: 21:2 } } diff --git a/src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyArmIdentity.diff index 64b5f17430023..44f475346e016 100644 --- a/src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyArmIdentity.diff @@ -49,17 +49,16 @@ } bb2: { -- StorageLive(_10); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15 -- _10 = ((_3 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15 -- _2 = _10; // scope 5 at $DIR/simplify-arm.rs:24:13: 24:15 -- StorageDead(_10); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 -+ _0 = move _3; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10 + StorageLive(_10); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15 + _10 = ((_3 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15 + _2 = _10; // scope 5 at $DIR/simplify-arm.rs:24:13: 24:15 + StorageDead(_10); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16 -- StorageLive(_11); // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9 -- _11 = _2; // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9 -- ((_0 as Ok).0: u8) = move _11; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10 -- discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10 -- StorageDead(_11); // scope 1 at $DIR/simplify-arm.rs:25:9: 25:10 + StorageLive(_11); // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9 + _11 = _2; // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9 + ((_0 as Ok).0: u8) = move _11; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10 + discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10 + StorageDead(_11); // scope 1 at $DIR/simplify-arm.rs:25:9: 25:10 StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2 goto -> bb5; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 } diff --git a/src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyBranchSame.diff b/src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyBranchSame.diff index 01f57bec71a87..c91c55dfb04c4 100644 --- a/src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyBranchSame.diff @@ -49,8 +49,16 @@ } bb2: { - _0 = move _3; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10 + StorageLive(_10); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15 + _10 = ((_3 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15 + _2 = _10; // scope 5 at $DIR/simplify-arm.rs:24:13: 24:15 + StorageDead(_10); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16 + StorageLive(_11); // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9 + _11 = _2; // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9 + ((_0 as Ok).0: u8) = move _11; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10 + discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10 + StorageDead(_11); // scope 1 at $DIR/simplify-arm.rs:25:9: 25:10 StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2 goto -> bb5; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 } diff --git a/src/test/mir-opt/simplify_try_if_let/rustc.{{impl}}-append.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_try_if_let/rustc.{{impl}}-append.SimplifyArmIdentity.diff index 6ccec937b9b90..7d3537d094347 100644 --- a/src/test/mir-opt/simplify_try_if_let/rustc.{{impl}}-append.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_try_if_let/rustc.{{impl}}-append.SimplifyArmIdentity.diff @@ -80,12 +80,11 @@ StorageLive(_8); // scope 1 at $DIR/simplify_try_if_let.rs:26:29: 26:39 _8 = ((_5 as Some).0: std::ptr::NonNull); // scope 1 at $DIR/simplify_try_if_let.rs:26:29: 26:39 StorageLive(_9); // scope 3 at $DIR/simplify_try_if_let.rs:28:46: 28:62 -- StorageLive(_10); // scope 3 at $DIR/simplify_try_if_let.rs:28:51: 28:61 -- _10 = _8; // scope 3 at $DIR/simplify_try_if_let.rs:28:51: 28:61 -- ((_9 as Some).0: std::ptr::NonNull) = move _10; // scope 3 at $DIR/simplify_try_if_let.rs:28:46: 28:62 -- discriminant(_9) = 1; // scope 3 at $DIR/simplify_try_if_let.rs:28:46: 28:62 -- StorageDead(_10); // scope 3 at $DIR/simplify_try_if_let.rs:28:61: 28:62 -+ _9 = move _5; // scope 3 at $DIR/simplify_try_if_let.rs:28:46: 28:62 + StorageLive(_10); // scope 3 at $DIR/simplify_try_if_let.rs:28:51: 28:61 + _10 = _8; // scope 3 at $DIR/simplify_try_if_let.rs:28:51: 28:61 + ((_9 as Some).0: std::ptr::NonNull) = move _10; // scope 3 at $DIR/simplify_try_if_let.rs:28:46: 28:62 + discriminant(_9) = 1; // scope 3 at $DIR/simplify_try_if_let.rs:28:46: 28:62 + StorageDead(_10); // scope 3 at $DIR/simplify_try_if_let.rs:28:61: 28:62 StorageLive(_11); // scope 3 at $DIR/simplify_try_if_let.rs:28:25: 28:38 StorageLive(_12); // scope 3 at $DIR/simplify_try_if_let.rs:28:25: 28:29 _12 = &mut _4; // scope 3 at $DIR/simplify_try_if_let.rs:28:25: 28:29