From 4893c1162939dc65ae5d4e6b7593f3cfefd1a2a4 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 8 Oct 2020 01:08:30 +0200 Subject: [PATCH 1/4] Turn on UnreachablePropagation by default --- compiler/rustc_mir/src/transform/unreachable_prop.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/compiler/rustc_mir/src/transform/unreachable_prop.rs b/compiler/rustc_mir/src/transform/unreachable_prop.rs index c6426a06ea155..d15cffab0ad9b 100644 --- a/compiler/rustc_mir/src/transform/unreachable_prop.rs +++ b/compiler/rustc_mir/src/transform/unreachable_prop.rs @@ -12,13 +12,7 @@ use std::borrow::Cow; pub struct UnreachablePropagation; impl MirPass<'_> for UnreachablePropagation { - fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - if tcx.sess.opts.debugging_opts.mir_opt_level < 3 { - // Enable only under -Zmir-opt-level=3 as in some cases (check the deeply-nested-opt - // perf benchmark) LLVM may spend quite a lot of time optimizing the generated code. - return; - } - + fn run_pass<'tcx>(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let mut unreachable_blocks = FxHashSet::default(); let mut replacements = FxHashMap::default(); From 2b641defb6f6d242a4c6cd1f1335fcb471640ef0 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 8 Oct 2020 23:11:50 +0200 Subject: [PATCH 2/4] Bless mir-opt tests --- .../mir-opt/simplify_arm.id.SimplifyArmIdentity.diff | 12 ++++-------- .../mir-opt/simplify_arm.id.SimplifyBranchSame.diff | 12 ++++-------- .../simplify_arm.id_result.SimplifyArmIdentity.diff | 12 ++++-------- .../simplify_arm.id_result.SimplifyBranchSame.diff | 12 ++++-------- .../simplify_arm.id_try.SimplifyArmIdentity.diff | 12 ++++-------- .../simplify_arm.id_try.SimplifyBranchSame.diff | 12 ++++-------- ..._arm_identity.main.SimplifyArmIdentity.64bit.diff | 12 ++++-------- 7 files changed, 28 insertions(+), 56 deletions(-) diff --git a/src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff index e390662307e04..f7064ce58c2a4 100644 --- a/src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff @@ -14,19 +14,15 @@ bb0: { _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 - switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 + switchInt(move _2) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 } bb1: { discriminant(_0) = 0; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21 - goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 + goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 } bb2: { - unreachable; // scope 0 at $DIR/simplify-arm.rs:10:11: 10:12 - } - - 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 @@ -36,10 +32,10 @@ - StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:11:26: 11:27 - StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:11:26: 11:27 + _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27 - goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 + goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 } - bb4: { + bb3: { return; // scope 0 at $DIR/simplify-arm.rs:14:2: 14:2 } } diff --git a/src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff b/src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff index 81a0e6ba0b4ee..abf9c5458dced 100644 --- a/src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff @@ -13,26 +13,22 @@ bb0: { _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 -- switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 +- switchInt(move _2) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 + goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 } bb1: { - discriminant(_0) = 0; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21 -- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 +- goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 - } - - bb2: { -- unreachable; // scope 0 at $DIR/simplify-arm.rs:10:11: 10:12 -- } -- -- bb3: { _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27 -- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 +- goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 + goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 } -- bb4: { +- bb3: { + bb2: { return; // scope 0 at $DIR/simplify-arm.rs:14:2: 14:2 } diff --git a/src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff index 253e3236ff7d1..33937982c51ac 100644 --- a/src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff @@ -20,7 +20,7 @@ bb0: { _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 - switchInt(move _2) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 + switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 } bb1: { @@ -33,14 +33,10 @@ - StorageDead(_6); // scope 2 at $DIR/simplify-arm.rs:19:24: 19:25 - StorageDead(_5); // scope 0 at $DIR/simplify-arm.rs:19:24: 19:25 + _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 + goto -> bb3; // 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: { - 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 @@ -50,10 +46,10 @@ - StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:18:22: 18:23 - StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:18:22: 18:23 + _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 -> bb3; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 } - bb4: { + bb3: { return; // scope 0 at $DIR/simplify-arm.rs:21:2: 21:2 } } diff --git a/src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff b/src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff index 23cf43c531973..e25610221fef7 100644 --- a/src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff @@ -18,26 +18,22 @@ bb0: { _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 -- switchInt(move _2) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 +- switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 + goto -> bb1; // 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 +- goto -> bb3; // 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 -> bb3; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 + goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 } -- bb4: { +- bb3: { + bb2: { return; // scope 0 at $DIR/simplify-arm.rs:21:2: 21:2 } diff --git a/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff index a811a2c178f17..a5aca3a64b0d3 100644 --- a/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff @@ -51,7 +51,7 @@ _3 = move _4; // scope 6 at $SRC_DIR/core/src/result.rs:LL:COL StorageDead(_4); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 _5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 - switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 + switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 } bb1: { @@ -67,14 +67,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 -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 + goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 } bb2: { - unreachable; // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15 - } - - bb3: { - StorageLive(_6); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 - _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 - StorageLive(_8); // scope 3 at $DIR/simplify-arm.rs:24:14: 24:15 @@ -92,10 +88,10 @@ + _0 = move _3; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16 StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2 - goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 + goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 } - bb4: { + bb3: { return; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 } } diff --git a/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff b/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff index b0cc3e88f35ac..798724bdae216 100644 --- a/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff @@ -46,7 +46,7 @@ _3 = move _4; // scope 6 at $SRC_DIR/core/src/result.rs:LL:COL StorageDead(_4); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 _5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 -- switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 +- switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 + goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 } @@ -54,22 +54,18 @@ _0 = move _3; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10 StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16 StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2 -- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 +- goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 + goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 } bb2: { -- unreachable; // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15 -- } -- -- bb3: { - _0 = move _3; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL - StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16 - StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2 -- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 +- goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 - } - -- bb4: { +- bb3: { return; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 } } diff --git a/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.64bit.diff b/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.64bit.diff index adcda7fcde0f9..6e3ff7c872682 100644 --- a/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.64bit.diff +++ b/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.64bit.diff @@ -23,20 +23,16 @@ discriminant(_1) = 0; // scope 0 at $DIR/simplify-arm-identity.rs:18:18: 18:29 StorageLive(_2); // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 _3 = const 0_isize; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 - goto -> bb3; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 + goto -> bb2; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 } bb1: { ((_2 as Foo).0: u8) = const 0_u8; // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 discriminant(_2) = 0; // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 - goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 + goto -> bb3; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 } bb2: { - unreachable; // scope 1 at $DIR/simplify-arm-identity.rs:19:24: 19:25 - } - - bb3: { StorageLive(_4); // scope 1 at $DIR/simplify-arm-identity.rs:20:18: 20:19 _4 = ((_1 as Foo).0: u8); // scope 1 at $DIR/simplify-arm-identity.rs:20:18: 20:19 StorageLive(_5); // scope 3 at $DIR/simplify-arm-identity.rs:20:33: 20:34 @@ -45,10 +41,10 @@ discriminant(_2) = 0; // scope 3 at $DIR/simplify-arm-identity.rs:20:24: 20:35 StorageDead(_5); // scope 3 at $DIR/simplify-arm-identity.rs:20:34: 20:35 StorageDead(_4); // scope 1 at $DIR/simplify-arm-identity.rs:20:34: 20:35 - goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 + goto -> bb3; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 } - bb4: { + bb3: { StorageDead(_2); // scope 1 at $DIR/simplify-arm-identity.rs:22:6: 22:7 _0 = const (); // scope 0 at $DIR/simplify-arm-identity.rs:17:11: 23:2 StorageDead(_1); // scope 0 at $DIR/simplify-arm-identity.rs:23:1: 23:2 From 134f3dab82d351a147d2b4276beb5ac6cbc554d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Sat, 10 Oct 2020 00:00:00 +0000 Subject: [PATCH 3/4] Unreachable propagation: preserve information about unreachable values Unreachable propagation pass removes all unreachable terminators. As a consequence, for switch int terminators, where two or more targets remain after the optimization, where otherwise branch is reachable, switching on unreachable values will use otherwise branch after the optimization. Consequently, the information about unreachable values is irrevocably lost. To preserve the information about unreachable values, keep the existing terminator if otherwise branch is reachable. Additionally, since now unreachable blocks might remain in use, remove their statements. --- .../src/transform/unreachable_prop.rs | 21 +++++------- ...nch_noopt.noopt1.EarlyOtherwiseBranch.diff | 26 ++++++++------ ..._73223.main.SimplifyArmIdentity.64bit.diff | 28 ++++++++------- ...match.MatchBranchSimplification.64bit.diff | 12 ++++--- ...ch_i8.MatchBranchSimplification.64bit.diff | 12 ++++--- .../simplify_arm.id.SimplifyArmIdentity.diff | 12 ++++--- .../simplify_arm.id.SimplifyBranchSame.diff | 12 ++++--- ...ify_arm.id_result.SimplifyArmIdentity.diff | 12 ++++--- ...lify_arm.id_result.SimplifyBranchSame.diff | 12 ++++--- ...mplify_arm.id_try.SimplifyArmIdentity.diff | 12 ++++--- ...implify_arm.id_try.SimplifyBranchSame.diff | 12 ++++--- ...entity.main.SimplifyArmIdentity.64bit.diff | 12 ++++--- ..._try.try_identity.SimplifyArmIdentity.diff | 6 +++- ...num.process_never.SimplifyLocals.after.mir | 3 -- ...after-uninhabited-enum-branching.after.mir | 24 +++++++++---- ...anching.main.UninhabitedEnumBranching.diff | 34 ++++++++++++------- ...reachable.main.UnreachablePropagation.diff | 10 +++--- ...diverging.main.UnreachablePropagation.diff | 22 ++++++------ 18 files changed, 170 insertions(+), 112 deletions(-) diff --git a/compiler/rustc_mir/src/transform/unreachable_prop.rs b/compiler/rustc_mir/src/transform/unreachable_prop.rs index d15cffab0ad9b..caf3f9e33ece5 100644 --- a/compiler/rustc_mir/src/transform/unreachable_prop.rs +++ b/compiler/rustc_mir/src/transform/unreachable_prop.rs @@ -44,10 +44,12 @@ impl MirPass<'_> for UnreachablePropagation { } let replaced = !replacements.is_empty(); + for bb in unreachable_blocks { + body.basic_blocks_mut()[bb].statements.clear(); + } for (bb, terminator_kind) in replacements { body.basic_blocks_mut()[bb].terminator_mut().kind = terminator_kind; } - if replaced { simplify::remove_dead_blocks(body); } @@ -64,32 +66,25 @@ where let terminator = match *terminator_kind { TerminatorKind::Goto { target } if predicate(target) => TerminatorKind::Unreachable, TerminatorKind::SwitchInt { ref discr, switch_ty, ref values, ref targets } => { - let original_targets_len = targets.len(); let (otherwise, targets) = targets.split_last().unwrap(); - let (mut values, mut targets): (Vec<_>, Vec<_>) = - values.iter().zip(targets.iter()).filter(|(_, &t)| !predicate(t)).unzip(); if !predicate(*otherwise) { - targets.push(*otherwise); - } else { - values.pop(); + return None; } - let retained_targets_len = targets.len(); + let (values, mut targets): (Vec<_>, Vec<_>) = + values.iter().zip(targets.iter()).filter(|(_, &t)| !predicate(t)).unzip(); if targets.is_empty() { TerminatorKind::Unreachable - } else if targets.len() == 1 { - TerminatorKind::Goto { target: targets[0] } - } else if original_targets_len != retained_targets_len { + } else { + targets.push(*otherwise); TerminatorKind::SwitchInt { discr: discr.clone(), switch_ty, values: Cow::from(values), targets, } - } else { - return None; } } _ => return None, diff --git a/src/test/mir-opt/early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff index 9a6094f12dfb1..e24a1c9c7cfa5 100644 --- a/src/test/mir-opt/early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff @@ -37,25 +37,29 @@ StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:16: 8:17 StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:16: 8:17 _8 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:10: 9:17 - switchInt(move _8) -> [0_isize: bb1, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:10: 9:17 + switchInt(move _8) -> [0_isize: bb1, 1_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:10: 9:17 } bb1: { _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:11:16: 11:23 - switchInt(move _6) -> [0_isize: bb2, otherwise: bb6]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:11:16: 11:23 + switchInt(move _6) -> [0_isize: bb2, 1_isize: bb7, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:11:16: 11:23 } bb2: { _0 = const 3_u32; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:12:25: 12:26 - goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 13:6 + goto -> bb8; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 13:6 } bb3: { - _7 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:19: 9:26 - switchInt(move _7) -> [0_isize: bb5, otherwise: bb4]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:19: 9:26 + unreachable; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:11: 8:17 } bb4: { + _7 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:19: 9:26 + switchInt(move _7) -> [0_isize: bb6, 1_isize: bb5, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:19: 9:26 + } + + bb5: { StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:15: 9:16 _9 = (((_3.0: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:15: 9:16 StorageLive(_10); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:24: 9:25 @@ -63,26 +67,26 @@ _0 = const 0_u32; // scope 1 at $DIR/early_otherwise_branch_noopt.rs:9:31: 9:32 StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:31: 9:32 StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:31: 9:32 - goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 13:6 + goto -> bb8; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 13:6 } - bb5: { + bb6: { StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:10:15: 10:16 _11 = (((_3.0: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:10:15: 10:16 _0 = const 1_u32; // scope 2 at $DIR/early_otherwise_branch_noopt.rs:10:28: 10:29 StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:10:28: 10:29 - goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 13:6 + goto -> bb8; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 13:6 } - bb6: { + bb7: { StorageLive(_12); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:11:21: 11:22 _12 = (((_3.1: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:11:21: 11:22 _0 = const 2_u32; // scope 3 at $DIR/early_otherwise_branch_noopt.rs:11:28: 11:29 StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:11:28: 11:29 - goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 13:6 + goto -> bb8; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 13:6 } - bb7: { + bb8: { StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:14:1: 14:2 return; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:14:2: 14:2 } diff --git a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff index 9039735f6ba38..ecd9db24968d0 100644 --- a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff +++ b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff @@ -99,7 +99,7 @@ ((_2 as Some).0: i32) = const 1_i32; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 discriminant(_2) = 1; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 _3 = const 1_isize; // scope 0 at $DIR/issue-73223.rs:3:9: 3:16 - goto -> bb2; // scope 0 at $DIR/issue-73223.rs:3:9: 3:16 + goto -> bb3; // scope 0 at $DIR/issue-73223.rs:3:9: 3:16 } bb1: { @@ -110,6 +110,10 @@ } bb2: { + unreachable; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + } + + bb3: { StorageLive(_4); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 _4 = ((_2 as Some).0: i32); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 _1 = _4; // scope 2 at $DIR/issue-73223.rs:3:20: 3:21 @@ -153,10 +157,10 @@ StorageDead(_17); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL _15 = Not(move _16); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageDead(_16); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - switchInt(_15) -> [false: bb3, otherwise: bb4]; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + switchInt(_15) -> [false: bb4, otherwise: bb5]; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL } - bb3: { + bb4: { _8 = const (); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageDead(_15); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageDead(_14); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL @@ -169,7 +173,7 @@ return; // scope 0 at $DIR/issue-73223.rs:9:2: 9:2 } - bb4: { + bb5: { StorageLive(_19); // scope 4 at $SRC_DIR/std/src/macros.rs:LL:COL StorageLive(_20); // scope 4 at $SRC_DIR/std/src/macros.rs:LL:COL StorageLive(_21); // scope 4 at $SRC_DIR/std/src/macros.rs:LL:COL @@ -220,24 +224,24 @@ StorageLive(_46); // scope 7 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL StorageLive(_47); // scope 7 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL _47 = _40; // scope 7 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL - _46 = transmute:: fn(&'r &i32, &'s mut Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>(move _47) -> bb5; // scope 7 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + _46 = transmute:: fn(&'r &i32, &'s mut Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>(move _47) -> bb6; // scope 7 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL // mir::Constant // + span: $SRC_DIR/core/src/fmt/mod.rs:LL:COL // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>}, val: Value(Scalar()) } } - bb5: { + bb6: { StorageDead(_47); // scope 7 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL StorageLive(_48); // scope 7 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL StorageLive(_49); // scope 7 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL _49 = _39; // scope 7 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL - _48 = transmute::<&&i32, &core::fmt::Opaque>(move _49) -> bb6; // scope 7 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + _48 = transmute::<&&i32, &core::fmt::Opaque>(move _49) -> bb7; // scope 7 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL // mir::Constant // + span: $SRC_DIR/core/src/fmt/mod.rs:LL:COL // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>}, val: Value(Scalar()) } } - bb6: { + bb7: { StorageDead(_49); // scope 7 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL (_38.0: &core::fmt::Opaque) = move _48; // scope 7 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL (_38.1: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) = move _46; // scope 7 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL @@ -256,24 +260,24 @@ StorageLive(_50); // scope 9 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL StorageLive(_51); // scope 9 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL _51 = _43; // scope 9 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL - _50 = transmute:: fn(&'r &i32, &'s mut Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>(move _51) -> bb7; // scope 9 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + _50 = transmute:: fn(&'r &i32, &'s mut Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>(move _51) -> bb8; // scope 9 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL // mir::Constant // + span: $SRC_DIR/core/src/fmt/mod.rs:LL:COL // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>}, val: Value(Scalar()) } } - bb7: { + bb8: { StorageDead(_51); // scope 9 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL StorageLive(_52); // scope 9 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL StorageLive(_53); // scope 9 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL _53 = _42; // scope 9 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL - _52 = transmute::<&&i32, &core::fmt::Opaque>(move _53) -> bb8; // scope 9 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + _52 = transmute::<&&i32, &core::fmt::Opaque>(move _53) -> bb9; // scope 9 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL // mir::Constant // + span: $SRC_DIR/core/src/fmt/mod.rs:LL:COL // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>}, val: Value(Scalar()) } } - bb8: { + bb9: { StorageDead(_53); // scope 9 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL (_41.0: &core::fmt::Opaque) = move _52; // scope 9 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL (_41.1: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) = move _50; // scope 9 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL diff --git a/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.64bit.diff b/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.64bit.diff index 9fde4888809d1..3c5b329c49ca7 100644 --- a/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.64bit.diff +++ b/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.64bit.diff @@ -8,20 +8,24 @@ bb0: { _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:13:9: 13:13 - switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:13:9: 13:13 + switchInt(move _2) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/matches_u8.rs:13:9: 13:13 } bb1: { _0 = const 1_u8; // scope 0 at $DIR/matches_u8.rs:14:17: 14:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:12:5: 15:6 + goto -> bb4; // scope 0 at $DIR/matches_u8.rs:12:5: 15:6 } bb2: { - _0 = const 0_u8; // scope 0 at $DIR/matches_u8.rs:13:17: 13:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:12:5: 15:6 + unreachable; // scope 0 at $DIR/matches_u8.rs:12:11: 12:12 } bb3: { + _0 = const 0_u8; // scope 0 at $DIR/matches_u8.rs:13:17: 13:18 + goto -> bb4; // scope 0 at $DIR/matches_u8.rs:12:5: 15:6 + } + + bb4: { return; // scope 0 at $DIR/matches_u8.rs:16:2: 16:2 } } diff --git a/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.64bit.diff b/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.64bit.diff index 2dd0a3edb479a..2509d827354b5 100644 --- a/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.64bit.diff +++ b/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.64bit.diff @@ -8,20 +8,24 @@ bb0: { _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:21:9: 21:13 - switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:21:9: 21:13 + switchInt(move _2) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/matches_u8.rs:21:9: 21:13 } bb1: { _0 = const 1_i8; // scope 0 at $DIR/matches_u8.rs:22:17: 22:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:20:5: 23:6 + goto -> bb4; // scope 0 at $DIR/matches_u8.rs:20:5: 23:6 } bb2: { - _0 = const 0_i8; // scope 0 at $DIR/matches_u8.rs:21:17: 21:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:20:5: 23:6 + unreachable; // scope 0 at $DIR/matches_u8.rs:20:11: 20:12 } bb3: { + _0 = const 0_i8; // scope 0 at $DIR/matches_u8.rs:21:17: 21:18 + goto -> bb4; // scope 0 at $DIR/matches_u8.rs:20:5: 23:6 + } + + bb4: { return; // scope 0 at $DIR/matches_u8.rs:24:2: 24:2 } } diff --git a/src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff index f7064ce58c2a4..e390662307e04 100644 --- a/src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff @@ -14,15 +14,19 @@ bb0: { _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 - switchInt(move _2) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 + switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 } bb1: { discriminant(_0) = 0; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21 - goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 + goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 } bb2: { + unreachable; // scope 0 at $DIR/simplify-arm.rs:10:11: 10:12 + } + + 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 @@ -32,10 +36,10 @@ - StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:11:26: 11:27 - StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:11:26: 11:27 + _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27 - goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 + goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 } - bb3: { + bb4: { return; // scope 0 at $DIR/simplify-arm.rs:14:2: 14:2 } } diff --git a/src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff b/src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff index abf9c5458dced..81a0e6ba0b4ee 100644 --- a/src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff @@ -13,22 +13,26 @@ bb0: { _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 -- switchInt(move _2) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 +- switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 + goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 } bb1: { - discriminant(_0) = 0; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21 -- goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 +- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 - } - - bb2: { +- unreachable; // scope 0 at $DIR/simplify-arm.rs:10:11: 10:12 +- } +- +- bb3: { _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27 -- goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 +- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 + goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 } -- bb3: { +- bb4: { + bb2: { return; // scope 0 at $DIR/simplify-arm.rs:14:2: 14:2 } diff --git a/src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff index 33937982c51ac..253e3236ff7d1 100644 --- a/src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff @@ -20,7 +20,7 @@ bb0: { _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 - switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 + switchInt(move _2) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 } bb1: { @@ -33,10 +33,14 @@ - StorageDead(_6); // scope 2 at $DIR/simplify-arm.rs:19:24: 19:25 - StorageDead(_5); // scope 0 at $DIR/simplify-arm.rs:19:24: 19:25 + _0 = move _1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25 - goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 + 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: { - 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 @@ -46,10 +50,10 @@ - StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:18:22: 18:23 - StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:18:22: 18:23 + _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23 - goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 + goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 } - bb3: { + bb4: { return; // scope 0 at $DIR/simplify-arm.rs:21:2: 21:2 } } diff --git a/src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff b/src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff index e25610221fef7..23cf43c531973 100644 --- a/src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff @@ -18,22 +18,26 @@ bb0: { _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 -- switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 +- switchInt(move _2) -> [0_isize: bb3, 1_isize: 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 } bb1: { - _0 = move _1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25 -- goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 +- 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 -> bb3; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 +- 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 } -- bb3: { +- bb4: { + bb2: { return; // scope 0 at $DIR/simplify-arm.rs:21:2: 21:2 } diff --git a/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff index a5aca3a64b0d3..a811a2c178f17 100644 --- a/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff @@ -51,7 +51,7 @@ _3 = move _4; // scope 6 at $SRC_DIR/core/src/result.rs:LL:COL StorageDead(_4); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 _5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 - switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 + switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 } bb1: { @@ -67,10 +67,14 @@ - 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 -> bb3; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 + goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 } bb2: { + unreachable; // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15 + } + + bb3: { - StorageLive(_6); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 - _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 - StorageLive(_8); // scope 3 at $DIR/simplify-arm.rs:24:14: 24:15 @@ -88,10 +92,10 @@ + _0 = move _3; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16 StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2 - goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 + goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 } - bb3: { + bb4: { return; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 } } diff --git a/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff b/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff index 798724bdae216..b0cc3e88f35ac 100644 --- a/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff @@ -46,7 +46,7 @@ _3 = move _4; // scope 6 at $SRC_DIR/core/src/result.rs:LL:COL StorageDead(_4); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 _5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 -- switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 +- switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 + goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 } @@ -54,18 +54,22 @@ _0 = move _3; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10 StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16 StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2 -- goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 +- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 + goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 } bb2: { +- unreachable; // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15 +- } +- +- bb3: { - _0 = move _3; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL - StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16 - StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2 -- goto -> bb3; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 +- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 - } - -- bb3: { +- bb4: { return; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2 } } diff --git a/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.64bit.diff b/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.64bit.diff index 6e3ff7c872682..adcda7fcde0f9 100644 --- a/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.64bit.diff +++ b/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.64bit.diff @@ -23,16 +23,20 @@ discriminant(_1) = 0; // scope 0 at $DIR/simplify-arm-identity.rs:18:18: 18:29 StorageLive(_2); // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 _3 = const 0_isize; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 - goto -> bb2; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 + goto -> bb3; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 } bb1: { ((_2 as Foo).0: u8) = const 0_u8; // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 discriminant(_2) = 0; // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 - goto -> bb3; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 + goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 } bb2: { + unreachable; // scope 1 at $DIR/simplify-arm-identity.rs:19:24: 19:25 + } + + bb3: { StorageLive(_4); // scope 1 at $DIR/simplify-arm-identity.rs:20:18: 20:19 _4 = ((_1 as Foo).0: u8); // scope 1 at $DIR/simplify-arm-identity.rs:20:18: 20:19 StorageLive(_5); // scope 3 at $DIR/simplify-arm-identity.rs:20:33: 20:34 @@ -41,10 +45,10 @@ discriminant(_2) = 0; // scope 3 at $DIR/simplify-arm-identity.rs:20:24: 20:35 StorageDead(_5); // scope 3 at $DIR/simplify-arm-identity.rs:20:34: 20:35 StorageDead(_4); // scope 1 at $DIR/simplify-arm-identity.rs:20:34: 20:35 - goto -> bb3; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 + goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 } - bb3: { + bb4: { StorageDead(_2); // scope 1 at $DIR/simplify-arm-identity.rs:22:6: 22:7 _0 = const (); // scope 0 at $DIR/simplify-arm-identity.rs:17:11: 23:2 StorageDead(_1); // scope 0 at $DIR/simplify-arm-identity.rs:23:1: 23:2 diff --git a/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff index 534836eff7b2d..2798f9cfbe182 100644 --- a/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff @@ -51,7 +51,7 @@ _3 = move _4; // scope 6 at $SRC_DIR/core/src/result.rs:LL:COL StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:8:14: 8:15 _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:8:14: 8:15 - switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:8:14: 8:15 + switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:8:14: 8:15 } bb1: { @@ -71,6 +71,10 @@ } bb2: { + unreachable; // scope 0 at $DIR/simplify_try.rs:8:13: 8:15 + } + + bb3: { - StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:8:14: 8:15 - _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:8:14: 8:15 - StorageLive(_8); // scope 3 at $DIR/simplify_try.rs:8:14: 8:15 diff --git a/src/test/mir-opt/uninhabited_enum.process_never.SimplifyLocals.after.mir b/src/test/mir-opt/uninhabited_enum.process_never.SimplifyLocals.after.mir index c17fe3bb75757..3b5110c634d84 100644 --- a/src/test/mir-opt/uninhabited_enum.process_never.SimplifyLocals.after.mir +++ b/src/test/mir-opt/uninhabited_enum.process_never.SimplifyLocals.after.mir @@ -11,9 +11,6 @@ fn process_never(_1: *const !) -> () { } bb0: { - StorageLive(_2); // scope 0 at $DIR/uninhabited-enum.rs:8:8: 8:14 - _2 = &(*_1); // scope 2 at $DIR/uninhabited-enum.rs:8:26: 8:33 - StorageDead(_2); // scope 0 at $DIR/uninhabited-enum.rs:9:1: 9:2 unreachable; // scope 0 at $DIR/uninhabited-enum.rs:7:39: 9:2 } } diff --git a/src/test/mir-opt/uninhabited_enum_branching.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir b/src/test/mir-opt/uninhabited_enum_branching.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir index 0c6378cf92de7..2d9398f31fd1d 100644 --- a/src/test/mir-opt/uninhabited_enum_branching.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir +++ b/src/test/mir-opt/uninhabited_enum_branching.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir @@ -17,6 +17,10 @@ fn main() -> () { StorageLive(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 discriminant(_2) = 2; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 _3 = discriminant(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 + switchInt(move _3) -> [2_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 + } + + bb1: { StorageLive(_5); // scope 0 at $DIR/uninhabited_enum_branching.rs:23:21: 23:24 _5 = const "C"; // scope 0 at $DIR/uninhabited_enum_branching.rs:23:21: 23:24 // ty::Const @@ -33,10 +37,14 @@ fn main() -> () { StorageLive(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 discriminant(_7) = 0; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 _8 = discriminant(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 - switchInt(move _8) -> [4_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 + switchInt(move _8) -> [4_isize: bb5, 5_isize: bb3, otherwise: bb4]; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 } - bb1: { + bb2: { + unreachable; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 + } + + bb3: { StorageLive(_9); // scope 0 at $DIR/uninhabited_enum_branching.rs:28:21: 28:24 _9 = const "E"; // scope 0 at $DIR/uninhabited_enum_branching.rs:28:21: 28:24 // ty::Const @@ -47,10 +55,14 @@ fn main() -> () { // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [69], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, size: Size { raw: 1 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _6 = &(*_9); // scope 0 at $DIR/uninhabited_enum_branching.rs:28:21: 28:24 StorageDead(_9); // scope 0 at $DIR/uninhabited_enum_branching.rs:28:23: 28:24 - goto -> bb3; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 + goto -> bb6; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 } - bb2: { + bb4: { + unreachable; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 + } + + bb5: { _6 = const "D"; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:21: 27:24 // ty::Const // + ty: &str @@ -58,10 +70,10 @@ fn main() -> () { // mir::Constant // + span: $DIR/uninhabited_enum_branching.rs:27:21: 27:24 // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [68], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, size: Size { raw: 1 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } - goto -> bb3; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 + goto -> bb6; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 } - bb3: { + bb6: { StorageDead(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:29:6: 29:7 StorageDead(_6); // scope 0 at $DIR/uninhabited_enum_branching.rs:29:6: 29:7 _0 = const (); // scope 0 at $DIR/uninhabited_enum_branching.rs:19:11: 30:2 diff --git a/src/test/mir-opt/uninhabited_enum_branching.main.UninhabitedEnumBranching.diff b/src/test/mir-opt/uninhabited_enum_branching.main.UninhabitedEnumBranching.diff index d66f81b80982c..bd30bb4b3a621 100644 --- a/src/test/mir-opt/uninhabited_enum_branching.main.UninhabitedEnumBranching.diff +++ b/src/test/mir-opt/uninhabited_enum_branching.main.UninhabitedEnumBranching.diff @@ -18,8 +18,8 @@ StorageLive(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 discriminant(_2) = 2; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 _3 = discriminant(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 -- switchInt(move _3) -> [0_isize: bb2, 1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 -+ switchInt(move _3) -> bb1; // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 +- switchInt(move _3) -> [0_isize: bb3, 1_isize: bb4, 2_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 ++ switchInt(move _3) -> [2_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 } bb1: { @@ -33,10 +33,14 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [67], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, size: Size { raw: 1 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _1 = &(*_5); // scope 0 at $DIR/uninhabited_enum_branching.rs:23:21: 23:24 StorageDead(_5); // scope 0 at $DIR/uninhabited_enum_branching.rs:23:23: 23:24 - goto -> bb4; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 24:6 + goto -> bb5; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 24:6 } bb2: { + unreachable; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 + } + + bb3: { _1 = const "A(Empty)"; // scope 0 at $DIR/uninhabited_enum_branching.rs:21:24: 21:34 // ty::Const // + ty: &str @@ -44,10 +48,10 @@ // mir::Constant // + span: $DIR/uninhabited_enum_branching.rs:21:24: 21:34 // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [65, 40, 69, 109, 112, 116, 121, 41], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [255], len: Size { raw: 8 } }, size: Size { raw: 8 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 8 }) } - goto -> bb4; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 24:6 + goto -> bb5; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 24:6 } - bb3: { + bb4: { StorageLive(_4); // scope 0 at $DIR/uninhabited_enum_branching.rs:22:24: 22:34 _4 = const "B(Empty)"; // scope 0 at $DIR/uninhabited_enum_branching.rs:22:24: 22:34 // ty::Const @@ -58,20 +62,20 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [66, 40, 69, 109, 112, 116, 121, 41], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [255], len: Size { raw: 8 } }, size: Size { raw: 8 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 8 }) } _1 = &(*_4); // scope 0 at $DIR/uninhabited_enum_branching.rs:22:24: 22:34 StorageDead(_4); // scope 0 at $DIR/uninhabited_enum_branching.rs:22:33: 22:34 - goto -> bb4; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 24:6 + goto -> bb5; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 24:6 } - bb4: { + bb5: { StorageDead(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:24:6: 24:7 StorageDead(_1); // scope 0 at $DIR/uninhabited_enum_branching.rs:24:6: 24:7 StorageLive(_6); // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 StorageLive(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 discriminant(_7) = 0; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 _8 = discriminant(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 - switchInt(move _8) -> [4_isize: bb6, otherwise: bb5]; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 + switchInt(move _8) -> [4_isize: bb8, 5_isize: bb6, otherwise: bb7]; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 } - bb5: { + bb6: { StorageLive(_9); // scope 0 at $DIR/uninhabited_enum_branching.rs:28:21: 28:24 _9 = const "E"; // scope 0 at $DIR/uninhabited_enum_branching.rs:28:21: 28:24 // ty::Const @@ -82,10 +86,14 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [69], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, size: Size { raw: 1 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _6 = &(*_9); // scope 0 at $DIR/uninhabited_enum_branching.rs:28:21: 28:24 StorageDead(_9); // scope 0 at $DIR/uninhabited_enum_branching.rs:28:23: 28:24 - goto -> bb7; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 + goto -> bb9; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 } - bb6: { + bb7: { + unreachable; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 + } + + bb8: { _6 = const "D"; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:21: 27:24 // ty::Const // + ty: &str @@ -93,10 +101,10 @@ // mir::Constant // + span: $DIR/uninhabited_enum_branching.rs:27:21: 27:24 // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [68], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, size: Size { raw: 1 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } - goto -> bb7; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 + goto -> bb9; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 } - bb7: { + bb9: { StorageDead(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:29:6: 29:7 StorageDead(_6); // scope 0 at $DIR/uninhabited_enum_branching.rs:29:6: 29:7 _0 = const (); // scope 0 at $DIR/uninhabited_enum_branching.rs:19:11: 30:2 diff --git a/src/test/mir-opt/unreachable.main.UnreachablePropagation.diff b/src/test/mir-opt/unreachable.main.UnreachablePropagation.diff index 37ff5c6ee3bbd..679df3b45ef4c 100644 --- a/src/test/mir-opt/unreachable.main.UnreachablePropagation.diff +++ b/src/test/mir-opt/unreachable.main.UnreachablePropagation.diff @@ -27,17 +27,16 @@ bb1: { _2 = discriminant(_1); // scope 0 at $DIR/unreachable.rs:9:12: 9:20 -- switchInt(move _2) -> [1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/unreachable.rs:9:12: 9:20 -+ goto -> bb2; // scope 0 at $DIR/unreachable.rs:9:12: 9:20 + switchInt(move _2) -> [1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/unreachable.rs:9:12: 9:20 } bb2: { _0 = const (); // scope 0 at $DIR/unreachable.rs:9:5: 19:6 StorageDead(_1); // scope 0 at $DIR/unreachable.rs:20:1: 20:2 return; // scope 0 at $DIR/unreachable.rs:20:2: 20:2 -- } -- -- bb3: { + } + + bb3: { - StorageLive(_3); // scope 0 at $DIR/unreachable.rs:9:17: 9:19 - _3 = move ((_1 as Some).0: Empty); // scope 0 at $DIR/unreachable.rs:9:17: 9:19 - StorageLive(_4); // scope 1 at $DIR/unreachable.rs:10:13: 10:19 @@ -64,6 +63,7 @@ - StorageDead(_5); // scope 2 at $DIR/unreachable.rs:16:9: 16:10 - StorageLive(_7); // scope 2 at $DIR/unreachable.rs:18:9: 18:21 - unreachable; // scope 2 at $DIR/unreachable.rs:18:15: 18:17 ++ unreachable; // scope 2 at $DIR/unreachable.rs:12:9: 16:10 } } diff --git a/src/test/mir-opt/unreachable_diverging.main.UnreachablePropagation.diff b/src/test/mir-opt/unreachable_diverging.main.UnreachablePropagation.diff index c809483d8c2c4..d7a1b7fb675f3 100644 --- a/src/test/mir-opt/unreachable_diverging.main.UnreachablePropagation.diff +++ b/src/test/mir-opt/unreachable_diverging.main.UnreachablePropagation.diff @@ -45,28 +45,26 @@ StorageLive(_5); // scope 2 at $DIR/unreachable_diverging.rs:15:9: 17:10 StorageLive(_6); // scope 2 at $DIR/unreachable_diverging.rs:15:12: 15:13 _6 = _1; // scope 2 at $DIR/unreachable_diverging.rs:15:12: 15:13 -- switchInt(_6) -> [false: bb4, otherwise: bb5]; // scope 2 at $DIR/unreachable_diverging.rs:15:9: 17:10 -+ goto -> bb4; // scope 2 at $DIR/unreachable_diverging.rs:15:9: 17:10 + switchInt(_6) -> [false: bb4, otherwise: bb5]; // scope 2 at $DIR/unreachable_diverging.rs:15:9: 17:10 } bb4: { - _5 = const (); // scope 2 at $DIR/unreachable_diverging.rs:15:9: 17:10 - goto -> bb6; // scope 2 at $DIR/unreachable_diverging.rs:15:9: 17:10 -- } -- -- bb5: { -- _5 = loop_forever() -> bb6; // scope 2 at $DIR/unreachable_diverging.rs:16:13: 16:27 -+ _5 = loop_forever() -> bb5; // scope 2 at $DIR/unreachable_diverging.rs:16:13: 16:27 ++ unreachable; // scope 2 at $DIR/unreachable_diverging.rs:15:9: 17:10 + } + + bb5: { + _5 = loop_forever() -> bb6; // scope 2 at $DIR/unreachable_diverging.rs:16:13: 16:27 // mir::Constant // + span: $DIR/unreachable_diverging.rs:16:13: 16:25 // + literal: Const { ty: fn() {loop_forever}, val: Value(Scalar()) } } -- bb6: { -+ bb5: { - StorageDead(_6); // scope 2 at $DIR/unreachable_diverging.rs:17:9: 17:10 - StorageDead(_5); // scope 2 at $DIR/unreachable_diverging.rs:17:9: 17:10 - StorageLive(_7); // scope 2 at $DIR/unreachable_diverging.rs:18:9: 18:22 + bb6: { +- StorageDead(_6); // scope 2 at $DIR/unreachable_diverging.rs:17:9: 17:10 +- StorageDead(_5); // scope 2 at $DIR/unreachable_diverging.rs:17:9: 17:10 +- StorageLive(_7); // scope 2 at $DIR/unreachable_diverging.rs:18:9: 18:22 unreachable; // scope 2 at $DIR/unreachable_diverging.rs:18:15: 18:19 } } From 1ad305e66ce5aaeedd8480bf8b760c8314c3ab15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Sat, 10 Oct 2020 00:00:00 +0000 Subject: [PATCH 4/4] Use meaningful predicate name --- compiler/rustc_mir/src/transform/unreachable_prop.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_mir/src/transform/unreachable_prop.rs b/compiler/rustc_mir/src/transform/unreachable_prop.rs index caf3f9e33ece5..bff0fc372d89d 100644 --- a/compiler/rustc_mir/src/transform/unreachable_prop.rs +++ b/compiler/rustc_mir/src/transform/unreachable_prop.rs @@ -58,22 +58,22 @@ impl MirPass<'_> for UnreachablePropagation { fn remove_successors( terminator_kind: &TerminatorKind<'tcx>, - predicate: F, + is_unreachable: F, ) -> Option> where F: Fn(BasicBlock) -> bool, { let terminator = match *terminator_kind { - TerminatorKind::Goto { target } if predicate(target) => TerminatorKind::Unreachable, + TerminatorKind::Goto { target } if is_unreachable(target) => TerminatorKind::Unreachable, TerminatorKind::SwitchInt { ref discr, switch_ty, ref values, ref targets } => { let (otherwise, targets) = targets.split_last().unwrap(); - if !predicate(*otherwise) { + if !is_unreachable(*otherwise) { return None; } let (values, mut targets): (Vec<_>, Vec<_>) = - values.iter().zip(targets.iter()).filter(|(_, &t)| !predicate(t)).unzip(); + values.iter().zip(targets.iter()).filter(|(_, &t)| !is_unreachable(t)).unzip(); if targets.is_empty() { TerminatorKind::Unreachable