From 081074b237527c3ad80472ea59bd8aadbbb33395 Mon Sep 17 00:00:00 2001 From: Simon Vandel Sillesen Date: Thu, 24 Sep 2020 20:33:23 +0200 Subject: [PATCH 1/6] Make the EarlyOtherwiseBranch optimization less conservative It is not important that the types match in this optimization. Instead, we can apply the optimization more liberally if the layouts match. Locally when compiling stage 1 std, stage2 and stage 2 std this increases the times the optimization fires from 543 to 573. A ~5% increase. --- .../src/transform/early_otherwise_branch.rs | 19 ++--- ...wise_branch.opt3.EarlyOtherwiseBranch.diff | 78 +++++++++++++++++++ src/test/mir-opt/early_otherwise_branch.rs | 20 +++++ .../mir-opt/early_otherwise_branch_noopt.rs | 2 +- 4 files changed, 109 insertions(+), 10 deletions(-) create mode 100644 src/test/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff diff --git a/compiler/rustc_mir/src/transform/early_otherwise_branch.rs b/compiler/rustc_mir/src/transform/early_otherwise_branch.rs index 7a9089d0f3675..bdf759e0b956f 100644 --- a/compiler/rustc_mir/src/transform/early_otherwise_branch.rs +++ b/compiler/rustc_mir/src/transform/early_otherwise_branch.rs @@ -2,8 +2,8 @@ use crate::{ transform::{MirPass, MirSource}, util::patch::MirPatch, }; -use rustc_middle::mir::*; use rustc_middle::ty::{Ty, TyCtxt}; +use rustc_middle::{mir::*, ty::ParamEnv}; use std::{borrow::Cow, fmt::Debug}; use super::simplify::simplify_cfg; @@ -40,7 +40,7 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch { let opts_to_apply: Vec> = bbs_with_switch .flat_map(|(bb_idx, bb)| { let switch = bb.terminator(); - let helper = Helper { body, tcx }; + let helper = Helper { body, tcx, param_env: tcx.param_env(source.def_id()) }; let infos = helper.go(bb, switch)?; Some(OptimizationToApply { infos, basic_block_first_switch: bb_idx }) }) @@ -170,6 +170,7 @@ fn is_switch<'tcx>(terminator: &Terminator<'tcx>) -> bool { struct Helper<'a, 'tcx> { body: &'a Body<'tcx>, tcx: TyCtxt<'tcx>, + param_env: ParamEnv<'tcx>, } #[derive(Debug, Clone)] @@ -239,13 +240,13 @@ impl<'a, 'tcx> Helper<'a, 'tcx> { if is_switch(terminator) { let this_bb_discr_info = self.find_switch_discriminant_info(bb, terminator)?; - // the types of the two adts matched on have to be equalfor this optimization to apply - if discr_info.type_adt_matched_on != this_bb_discr_info.type_adt_matched_on { - trace!( - "NO: types do not match. LHS: {:?}, RHS: {:?}", - discr_info.type_adt_matched_on, - this_bb_discr_info.type_adt_matched_on - ); + // The layouts of the two ADTs have to be equal for this optimization to apply + let layout_of_adt = + |ty: Ty<'tcx>| self.tcx.layout_of(self.param_env.and(ty)).ok().map(|x| x.layout); + let layout_lhs = layout_of_adt(discr_info.type_adt_matched_on); + let layout_rhs = layout_of_adt(this_bb_discr_info.type_adt_matched_on); + if layout_lhs != layout_rhs { + trace!("NO: Layouts do not match. LHS: {:?}, RHS: {:?}", layout_lhs, layout_rhs); return None; } diff --git a/src/test/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff new file mode 100644 index 0000000000000..d2d1af19a77a7 --- /dev/null +++ b/src/test/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff @@ -0,0 +1,78 @@ +- // MIR for `opt3` before EarlyOtherwiseBranch ++ // MIR for `opt3` after EarlyOtherwiseBranch + + fn opt3(_1: MyOption1, _2: MyOption2) -> u32 { + debug x => _1; // in scope 0 at $DIR/early_otherwise_branch.rs:31:9: 31:10 + debug y => _2; // in scope 0 at $DIR/early_otherwise_branch.rs:31:28: 31:29 + let mut _0: u32; // return place in scope 0 at $DIR/early_otherwise_branch.rs:31:50: 31:53 + let mut _3: (MyOption1, MyOption2); // in scope 0 at $DIR/early_otherwise_branch.rs:32:11: 32:17 + let mut _4: MyOption1; // in scope 0 at $DIR/early_otherwise_branch.rs:32:12: 32:13 + let mut _5: MyOption2; // in scope 0 at $DIR/early_otherwise_branch.rs:32:15: 32:16 + let mut _6: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:33:30: 33:48 + let mut _7: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 + let _8: u32; // in scope 0 at $DIR/early_otherwise_branch.rs:33:26: 33:27 + let _9: u32; // in scope 0 at $DIR/early_otherwise_branch.rs:33:46: 33:47 ++ let mut _10: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:33:30: 33:48 ++ let mut _11: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:33:30: 33:48 + scope 1 { + debug a => _8; // in scope 1 at $DIR/early_otherwise_branch.rs:33:26: 33:27 + debug b => _9; // in scope 1 at $DIR/early_otherwise_branch.rs:33:46: 33:47 + } + + bb0: { + StorageLive(_3); // scope 0 at $DIR/early_otherwise_branch.rs:32:11: 32:17 + StorageLive(_4); // scope 0 at $DIR/early_otherwise_branch.rs:32:12: 32:13 + _4 = move _1; // scope 0 at $DIR/early_otherwise_branch.rs:32:12: 32:13 + StorageLive(_5); // scope 0 at $DIR/early_otherwise_branch.rs:32:15: 32:16 + _5 = move _2; // scope 0 at $DIR/early_otherwise_branch.rs:32:15: 32:16 + (_3.0: MyOption1) = move _4; // scope 0 at $DIR/early_otherwise_branch.rs:32:11: 32:17 + (_3.1: MyOption2) = move _5; // scope 0 at $DIR/early_otherwise_branch.rs:32:11: 32:17 + StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch.rs:32:16: 32:17 + StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch.rs:32:16: 32:17 + _7 = discriminant((_3.0: MyOption1)); // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 +- switchInt(move _7) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 ++ StorageLive(_10); // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 ++ _10 = discriminant((_3.1: MyOption2)); // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 ++ StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 ++ _11 = Ne(_10, _7); // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 ++ StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 ++ switchInt(move _11) -> [false: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 + } + + bb1: { +- _6 = discriminant((_3.1: MyOption2)); // scope 0 at $DIR/early_otherwise_branch.rs:33:30: 33:48 +- switchInt(move _6) -> [0_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:33:30: 33:48 +- } +- +- bb2: { ++ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:34:14: 34:15 + _0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch.rs:34:14: 34:15 +- goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:32:5: 35:6 ++ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:32:5: 35:6 + } + +- bb3: { ++ bb2: { + StorageLive(_8); // scope 0 at $DIR/early_otherwise_branch.rs:33:26: 33:27 + _8 = (((_3.0: MyOption1) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:33:26: 33:27 + StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:33:46: 33:47 + _9 = (((_3.1: MyOption2) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:33:46: 33:47 + _0 = const 0_u32; // scope 1 at $DIR/early_otherwise_branch.rs:33:53: 33:54 + StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:33:53: 33:54 + StorageDead(_8); // scope 0 at $DIR/early_otherwise_branch.rs:33:53: 33:54 +- goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:32:5: 35:6 ++ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:32:5: 35:6 + } + +- bb4: { ++ bb3: { + StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:36:1: 36:2 + return; // scope 0 at $DIR/early_otherwise_branch.rs:36:2: 36:2 ++ } ++ ++ bb4: { ++ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:33:30: 33:48 ++ switchInt(_7) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:33:30: 33:48 + } + } + diff --git a/src/test/mir-opt/early_otherwise_branch.rs b/src/test/mir-opt/early_otherwise_branch.rs index 77003442080f4..3c8e31c173aab 100644 --- a/src/test/mir-opt/early_otherwise_branch.rs +++ b/src/test/mir-opt/early_otherwise_branch.rs @@ -16,7 +16,27 @@ fn opt2(x: Option, y: Option) -> u32 { } } +enum MyOption1 { + Some(T), + None, +} + +enum MyOption2 { + Some(T), + None, +} + +// must optimize as the tag encoding of the discriminant are the same +// EMIT_MIR early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff +fn opt3(x: MyOption1, y: MyOption2) -> u32 { + match (x, y) { + (MyOption1::Some(a), MyOption2::Some(b)) => 0, + _ => 1, + } +} + fn main() { opt1(None, Some(0)); opt2(None, Some(0)); + opt3(MyOption1::None, MyOption2::Some(0)); } diff --git a/src/test/mir-opt/early_otherwise_branch_noopt.rs b/src/test/mir-opt/early_otherwise_branch_noopt.rs index bd15f520dfcd4..2d1281b24b77b 100644 --- a/src/test/mir-opt/early_otherwise_branch_noopt.rs +++ b/src/test/mir-opt/early_otherwise_branch_noopt.rs @@ -13,7 +13,7 @@ fn noopt1(x: Option, y: Option) -> u32 { } } -// must not optimize as the types being matched on are not identical +// must not optimize as the tag encodings of the discriminant are not the same // EMIT_MIR early_otherwise_branch_noopt.noopt2.EarlyOtherwiseBranch.diff fn noopt2(x: Option, y: Option) -> u32 { match (x, y) { From 4a6b72835f73e0560c18b3177db176083e7c4252 Mon Sep 17 00:00:00 2001 From: Simon Vandel Sillesen Date: Thu, 24 Sep 2020 20:37:59 +0200 Subject: [PATCH 2/6] Recorder checks - from intuitively cheapest to most expensive --- .../src/transform/early_otherwise_branch.rs | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_mir/src/transform/early_otherwise_branch.rs b/compiler/rustc_mir/src/transform/early_otherwise_branch.rs index bdf759e0b956f..6f1d15e9e58c4 100644 --- a/compiler/rustc_mir/src/transform/early_otherwise_branch.rs +++ b/compiler/rustc_mir/src/transform/early_otherwise_branch.rs @@ -240,30 +240,14 @@ impl<'a, 'tcx> Helper<'a, 'tcx> { if is_switch(terminator) { let this_bb_discr_info = self.find_switch_discriminant_info(bb, terminator)?; - // The layouts of the two ADTs have to be equal for this optimization to apply - let layout_of_adt = - |ty: Ty<'tcx>| self.tcx.layout_of(self.param_env.and(ty)).ok().map(|x| x.layout); - let layout_lhs = layout_of_adt(discr_info.type_adt_matched_on); - let layout_rhs = layout_of_adt(this_bb_discr_info.type_adt_matched_on); - if layout_lhs != layout_rhs { - trace!("NO: Layouts do not match. LHS: {:?}, RHS: {:?}", layout_lhs, layout_rhs); - return None; - } - - // the otherwise branch of the two switches have to point to the same bb + // The otherwise branch of the two switches have to point to the same bb if discr_info.otherwise_bb != this_bb_discr_info.otherwise_bb { trace!("NO: otherwise target is not the same"); return None; } - // check that the value being matched on is the same. The - if this_bb_discr_info.targets_with_values.iter().find(|x| x.1 == value).is_none() { - trace!("NO: values being matched on are not the same"); - return None; - } - - // only allow optimization if the left and right of the tuple being matched are the same variants. - // so the following should not optimize + // Only allow optimization if the left and right of the tuple being matched + // are the same variants. So the following should not optimize // ```rust // let x: Option<()>; // let y: Option<()>; @@ -272,7 +256,8 @@ impl<'a, 'tcx> Helper<'a, 'tcx> { // _ => {} // } // ``` - // We check this by seeing that the value of the first discriminant is the only other discriminant value being used as a target in the second switch + // We check this by seeing that the value of the first discriminant is the only + // other discriminant value being used as a target in the second switch if !(this_bb_discr_info.targets_with_values.len() == 1 && this_bb_discr_info.targets_with_values[0].1 == value) { @@ -282,7 +267,23 @@ impl<'a, 'tcx> Helper<'a, 'tcx> { return None; } - // if we reach this point, the optimization applies, and we should be able to optimize this case + // check that the value being matched on is the same. The + if this_bb_discr_info.targets_with_values.iter().find(|x| x.1 == value).is_none() { + trace!("NO: values being matched on are not the same"); + return None; + } + + // The layouts of the two ADTs have to be equal for this optimization to apply + let layout_of_adt = + |ty: Ty<'tcx>| self.tcx.layout_of(self.param_env.and(ty)).ok().map(|x| x.layout); + let layout_lhs = layout_of_adt(discr_info.type_adt_matched_on); + let layout_rhs = layout_of_adt(this_bb_discr_info.type_adt_matched_on); + if layout_lhs != layout_rhs { + trace!("NO: Layouts do not match. LHS: {:?}, RHS: {:?}", layout_lhs, layout_rhs); + return None; + } + + // If we reach this point, the optimization applies, and we should be able to optimize this case // store the info that is needed to apply the optimization Some(OptimizationInfo { From 3d52e54ee89153f021d636308651117b3ffbee02 Mon Sep 17 00:00:00 2001 From: Simon Vandel Sillesen Date: Wed, 30 Sep 2020 20:16:38 +0200 Subject: [PATCH 3/6] Don't need to look at the layout of the types being matched on We only need to check that the discriminant value is the same --- .../src/transform/early_otherwise_branch.rs | 21 +---- ...wise_branch.opt4.EarlyOtherwiseBranch.diff | 64 +++++++++++++++ ...wise_branch.opt5.EarlyOtherwiseBranch.diff | 77 +++++++++++++++++++ src/test/mir-opt/early_otherwise_branch.rs | 22 +++++- ...nch_noopt.noopt2.EarlyOtherwiseBranch.diff | 60 --------------- .../mir-opt/early_otherwise_branch_noopt.rs | 10 --- 6 files changed, 164 insertions(+), 90 deletions(-) create mode 100644 src/test/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff create mode 100644 src/test/mir-opt/early_otherwise_branch.opt5.EarlyOtherwiseBranch.diff delete mode 100644 src/test/mir-opt/early_otherwise_branch_noopt.noopt2.EarlyOtherwiseBranch.diff diff --git a/compiler/rustc_mir/src/transform/early_otherwise_branch.rs b/compiler/rustc_mir/src/transform/early_otherwise_branch.rs index 6f1d15e9e58c4..898f65472c0a6 100644 --- a/compiler/rustc_mir/src/transform/early_otherwise_branch.rs +++ b/compiler/rustc_mir/src/transform/early_otherwise_branch.rs @@ -2,8 +2,8 @@ use crate::{ transform::{MirPass, MirSource}, util::patch::MirPatch, }; +use rustc_middle::mir::*; use rustc_middle::ty::{Ty, TyCtxt}; -use rustc_middle::{mir::*, ty::ParamEnv}; use std::{borrow::Cow, fmt::Debug}; use super::simplify::simplify_cfg; @@ -40,7 +40,7 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch { let opts_to_apply: Vec> = bbs_with_switch .flat_map(|(bb_idx, bb)| { let switch = bb.terminator(); - let helper = Helper { body, tcx, param_env: tcx.param_env(source.def_id()) }; + let helper = Helper { body, tcx }; let infos = helper.go(bb, switch)?; Some(OptimizationToApply { infos, basic_block_first_switch: bb_idx }) }) @@ -170,7 +170,6 @@ fn is_switch<'tcx>(terminator: &Terminator<'tcx>) -> bool { struct Helper<'a, 'tcx> { body: &'a Body<'tcx>, tcx: TyCtxt<'tcx>, - param_env: ParamEnv<'tcx>, } #[derive(Debug, Clone)] @@ -267,22 +266,6 @@ impl<'a, 'tcx> Helper<'a, 'tcx> { return None; } - // check that the value being matched on is the same. The - if this_bb_discr_info.targets_with_values.iter().find(|x| x.1 == value).is_none() { - trace!("NO: values being matched on are not the same"); - return None; - } - - // The layouts of the two ADTs have to be equal for this optimization to apply - let layout_of_adt = - |ty: Ty<'tcx>| self.tcx.layout_of(self.param_env.and(ty)).ok().map(|x| x.layout); - let layout_lhs = layout_of_adt(discr_info.type_adt_matched_on); - let layout_rhs = layout_of_adt(this_bb_discr_info.type_adt_matched_on); - if layout_lhs != layout_rhs { - trace!("NO: Layouts do not match. LHS: {:?}, RHS: {:?}", layout_lhs, layout_rhs); - return None; - } - // If we reach this point, the optimization applies, and we should be able to optimize this case // store the info that is needed to apply the optimization diff --git a/src/test/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff new file mode 100644 index 0000000000000..105d33bf2022f --- /dev/null +++ b/src/test/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff @@ -0,0 +1,64 @@ +- // MIR for `opt4` before EarlyOtherwiseBranch ++ // MIR for `opt4` after EarlyOtherwiseBranch + + fn opt4(_1: std::result::Result, _2: Option) -> u32 { + debug x => _1; // in scope 0 at $DIR/early_otherwise_branch.rs:40:9: 40:10 + debug y => _2; // in scope 0 at $DIR/early_otherwise_branch.rs:40:29: 40:30 + let mut _0: u32; // return place in scope 0 at $DIR/early_otherwise_branch.rs:40:48: 40:51 + let mut _3: (std::result::Result, std::option::Option); // in scope 0 at $DIR/early_otherwise_branch.rs:41:11: 41:17 + let mut _4: std::result::Result; // in scope 0 at $DIR/early_otherwise_branch.rs:41:12: 41:13 + let mut _5: std::option::Option; // in scope 0 at $DIR/early_otherwise_branch.rs:41:15: 41:16 + let mut _6: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:42:18: 42:25 + let mut _7: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 ++ let mut _8: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:42:18: 42:25 ++ let mut _9: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:42:18: 42:25 + + bb0: { + StorageLive(_3); // scope 0 at $DIR/early_otherwise_branch.rs:41:11: 41:17 + StorageLive(_4); // scope 0 at $DIR/early_otherwise_branch.rs:41:12: 41:13 + _4 = _1; // scope 0 at $DIR/early_otherwise_branch.rs:41:12: 41:13 + StorageLive(_5); // scope 0 at $DIR/early_otherwise_branch.rs:41:15: 41:16 + _5 = _2; // scope 0 at $DIR/early_otherwise_branch.rs:41:15: 41:16 + (_3.0: std::result::Result) = move _4; // scope 0 at $DIR/early_otherwise_branch.rs:41:11: 41:17 + (_3.1: std::option::Option) = move _5; // scope 0 at $DIR/early_otherwise_branch.rs:41:11: 41:17 + StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch.rs:41:16: 41:17 + StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch.rs:41:16: 41:17 + _7 = discriminant((_3.0: std::result::Result)); // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 +- switchInt(move _7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 ++ StorageLive(_8); // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 ++ _8 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 ++ StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 ++ _9 = Ne(_8, _7); // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 ++ StorageDead(_8); // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 ++ switchInt(move _9) -> [false: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 + } + + bb1: { ++ StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:43:14: 43:15 + _0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch.rs:43:14: 43:15 +- goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:41:5: 44:6 ++ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:41:5: 44:6 + } + + bb2: { +- _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:42:18: 42:25 +- switchInt(move _6) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:42:18: 42:25 ++ _0 = const 0_u32; // scope 0 at $DIR/early_otherwise_branch.rs:42:30: 42:31 ++ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:41:5: 44:6 + } + + bb3: { +- _0 = const 0_u32; // scope 0 at $DIR/early_otherwise_branch.rs:42:30: 42:31 +- goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:41:5: 44:6 ++ StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:45:1: 45:2 ++ return; // scope 0 at $DIR/early_otherwise_branch.rs:45:2: 45:2 + } + + bb4: { +- StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:45:1: 45:2 +- return; // scope 0 at $DIR/early_otherwise_branch.rs:45:2: 45:2 ++ StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:42:18: 42:25 ++ switchInt(_7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:42:18: 42:25 + } + } + diff --git a/src/test/mir-opt/early_otherwise_branch.opt5.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt5.EarlyOtherwiseBranch.diff new file mode 100644 index 0000000000000..78e1b2414d0ed --- /dev/null +++ b/src/test/mir-opt/early_otherwise_branch.opt5.EarlyOtherwiseBranch.diff @@ -0,0 +1,77 @@ +- // MIR for `opt5` before EarlyOtherwiseBranch ++ // MIR for `opt5` after EarlyOtherwiseBranch + + fn opt5(_1: Option, _2: Option) -> u32 { + debug x => _1; // in scope 0 at $DIR/early_otherwise_branch.rs:49:9: 49:10 + debug y => _2; // in scope 0 at $DIR/early_otherwise_branch.rs:49:25: 49:26 + let mut _0: u32; // return place in scope 0 at $DIR/early_otherwise_branch.rs:49:45: 49:48 + let mut _3: (std::option::Option, std::option::Option); // in scope 0 at $DIR/early_otherwise_branch.rs:50:11: 50:17 + let mut _4: std::option::Option; // in scope 0 at $DIR/early_otherwise_branch.rs:50:12: 50:13 + let mut _5: std::option::Option; // in scope 0 at $DIR/early_otherwise_branch.rs:50:15: 50:16 + let mut _6: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:51:19: 51:26 + let mut _7: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 + let _8: u32; // in scope 0 at $DIR/early_otherwise_branch.rs:51:15: 51:16 + let _9: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:51:24: 51:25 ++ let mut _10: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:51:19: 51:26 ++ let mut _11: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:51:19: 51:26 + scope 1 { + debug a => _8; // in scope 1 at $DIR/early_otherwise_branch.rs:51:15: 51:16 + debug b => _9; // in scope 1 at $DIR/early_otherwise_branch.rs:51:24: 51:25 + } + + bb0: { + StorageLive(_3); // scope 0 at $DIR/early_otherwise_branch.rs:50:11: 50:17 + StorageLive(_4); // scope 0 at $DIR/early_otherwise_branch.rs:50:12: 50:13 + _4 = _1; // scope 0 at $DIR/early_otherwise_branch.rs:50:12: 50:13 + StorageLive(_5); // scope 0 at $DIR/early_otherwise_branch.rs:50:15: 50:16 + _5 = _2; // scope 0 at $DIR/early_otherwise_branch.rs:50:15: 50:16 + (_3.0: std::option::Option) = move _4; // scope 0 at $DIR/early_otherwise_branch.rs:50:11: 50:17 + (_3.1: std::option::Option) = move _5; // scope 0 at $DIR/early_otherwise_branch.rs:50:11: 50:17 + StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch.rs:50:16: 50:17 + StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch.rs:50:16: 50:17 + _7 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 +- switchInt(move _7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 ++ StorageLive(_10); // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 ++ _10 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 ++ StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 ++ _11 = Ne(_10, _7); // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 ++ StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 ++ switchInt(move _11) -> [false: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 + } + + bb1: { ++ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:52:14: 52:15 + _0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch.rs:52:14: 52:15 +- goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:50:5: 53:6 ++ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:50:5: 53:6 + } + + bb2: { +- _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:51:19: 51:26 +- switchInt(move _6) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:51:19: 51:26 +- } +- +- bb3: { + StorageLive(_8); // scope 0 at $DIR/early_otherwise_branch.rs:51:15: 51:16 + _8 = (((_3.0: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:51:15: 51:16 + StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:51:24: 51:25 + _9 = (((_3.1: std::option::Option) as Some).0: bool); // scope 0 at $DIR/early_otherwise_branch.rs:51:24: 51:25 + _0 = const 0_u32; // scope 1 at $DIR/early_otherwise_branch.rs:51:31: 51:32 + StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:51:31: 51:32 + StorageDead(_8); // scope 0 at $DIR/early_otherwise_branch.rs:51:31: 51:32 +- goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:50:5: 53:6 ++ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:50:5: 53:6 + } + +- bb4: { ++ bb3: { + StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:54:1: 54:2 + return; // scope 0 at $DIR/early_otherwise_branch.rs:54:2: 54:2 ++ } ++ ++ bb4: { ++ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:51:19: 51:26 ++ switchInt(_7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:51:19: 51:26 + } + } + diff --git a/src/test/mir-opt/early_otherwise_branch.rs b/src/test/mir-opt/early_otherwise_branch.rs index 3c8e31c173aab..3892efe025da2 100644 --- a/src/test/mir-opt/early_otherwise_branch.rs +++ b/src/test/mir-opt/early_otherwise_branch.rs @@ -26,7 +26,7 @@ enum MyOption2 { None, } -// must optimize as the tag encoding of the discriminant are the same +// must optimize as the discriminant values are the same // EMIT_MIR early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff fn opt3(x: MyOption1, y: MyOption2) -> u32 { match (x, y) { @@ -35,8 +35,28 @@ fn opt3(x: MyOption1, y: MyOption2) -> u32 { } } +// must optimize as the discriminant values are the same +// EMIT_MIR early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff +fn opt4(x: Result, y: Option) -> u32 { + match (x, y) { + (Err(_), Some(_)) => 0, + _ => 1, + } +} + +// must optimize as the discriminant values are the same +// EMIT_MIR early_otherwise_branch.opt5.EarlyOtherwiseBranch.diff +fn opt5(x: Option, y: Option) -> u32 { + match (x, y) { + (Some(a), Some(b)) => 0, + _ => 1, + } +} + fn main() { opt1(None, Some(0)); opt2(None, Some(0)); opt3(MyOption1::None, MyOption2::Some(0)); + opt4(Ok(0), None); + opt5(None, Some(true)); } diff --git a/src/test/mir-opt/early_otherwise_branch_noopt.noopt2.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch_noopt.noopt2.EarlyOtherwiseBranch.diff deleted file mode 100644 index c3aecb4529351..0000000000000 --- a/src/test/mir-opt/early_otherwise_branch_noopt.noopt2.EarlyOtherwiseBranch.diff +++ /dev/null @@ -1,60 +0,0 @@ -- // MIR for `noopt2` before EarlyOtherwiseBranch -+ // MIR for `noopt2` after EarlyOtherwiseBranch - - fn noopt2(_1: Option, _2: Option) -> u32 { - debug x => _1; // in scope 0 at $DIR/early_otherwise_branch_noopt.rs:18:11: 18:12 - debug y => _2; // in scope 0 at $DIR/early_otherwise_branch_noopt.rs:18:27: 18:28 - let mut _0: u32; // return place in scope 0 at $DIR/early_otherwise_branch_noopt.rs:18:47: 18:50 - let mut _3: (std::option::Option, std::option::Option); // in scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:11: 19:17 - let mut _4: std::option::Option; // in scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:12: 19:13 - let mut _5: std::option::Option; // in scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:15: 19:16 - let mut _6: isize; // in scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:19: 20:26 - let mut _7: isize; // in scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:10: 20:17 - let _8: u32; // in scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:15: 20:16 - let _9: bool; // in scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:24: 20:25 - scope 1 { - debug a => _8; // in scope 1 at $DIR/early_otherwise_branch_noopt.rs:20:15: 20:16 - debug b => _9; // in scope 1 at $DIR/early_otherwise_branch_noopt.rs:20:24: 20:25 - } - - bb0: { - StorageLive(_3); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:11: 19:17 - StorageLive(_4); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:12: 19:13 - _4 = _1; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:12: 19:13 - StorageLive(_5); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:15: 19:16 - _5 = _2; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:15: 19:16 - (_3.0: std::option::Option) = move _4; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:11: 19:17 - (_3.1: std::option::Option) = move _5; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:11: 19:17 - StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:16: 19:17 - StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:16: 19:17 - _7 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:10: 20:17 - switchInt(move _7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:10: 20:17 - } - - bb1: { - _0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:21:14: 21:15 - goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:5: 22:6 - } - - bb2: { - _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:19: 20:26 - switchInt(move _6) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:19: 20:26 - } - - bb3: { - StorageLive(_8); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:15: 20:16 - _8 = (((_3.0: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:15: 20:16 - StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:24: 20:25 - _9 = (((_3.1: std::option::Option) as Some).0: bool); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:24: 20:25 - _0 = const 0_u32; // scope 1 at $DIR/early_otherwise_branch_noopt.rs:20:31: 20:32 - StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:31: 20:32 - StorageDead(_8); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:31: 20:32 - goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:5: 22:6 - } - - bb4: { - StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:23:1: 23:2 - return; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:23:2: 23:2 - } - } - diff --git a/src/test/mir-opt/early_otherwise_branch_noopt.rs b/src/test/mir-opt/early_otherwise_branch_noopt.rs index 2d1281b24b77b..585b4b3a833dc 100644 --- a/src/test/mir-opt/early_otherwise_branch_noopt.rs +++ b/src/test/mir-opt/early_otherwise_branch_noopt.rs @@ -13,16 +13,6 @@ fn noopt1(x: Option, y: Option) -> u32 { } } -// must not optimize as the tag encodings of the discriminant are not the same -// EMIT_MIR early_otherwise_branch_noopt.noopt2.EarlyOtherwiseBranch.diff -fn noopt2(x: Option, y: Option) -> u32 { - match (x, y) { - (Some(a), Some(b)) => 0, - _ => 1, - } -} - fn main() { noopt1(None, Some(0)); - noopt2(None, Some(true)); } From 930898bc8f334dcd300f68a1824df3cef8392fd8 Mon Sep 17 00:00:00 2001 From: Simon Vandel Sillesen Date: Wed, 30 Sep 2020 22:31:49 +0200 Subject: [PATCH 4/6] Do not invent new basic block - just jump to already existing bb Fixes a miscompilation and generally simplifies the MIR generated --- .../src/transform/early_otherwise_branch.rs | 37 ++-- ...wise_branch.opt1.EarlyOtherwiseBranch.diff | 8 +- ...wise_branch.opt2.EarlyOtherwiseBranch.diff | 36 ++-- ...wise_branch.opt3.EarlyOtherwiseBranch.diff | 8 +- ...wise_branch.opt4.EarlyOtherwiseBranch.diff | 25 +-- ...wise_branch.opt5.EarlyOtherwiseBranch.diff | 8 +- ...wise_branch.opt6.EarlyOtherwiseBranch.diff | 195 ++++++++++++++++++ src/test/mir-opt/early_otherwise_branch.rs | 11 + ...ement_tuple.opt1.EarlyOtherwiseBranch.diff | 9 +- ...implifyBranches-after-copy-prop.after.diff | 154 ++++---------- ...ch_68867.try_sum.EarlyOtherwiseBranch.diff | 134 ++++++------ 11 files changed, 358 insertions(+), 267 deletions(-) create mode 100644 src/test/mir-opt/early_otherwise_branch.opt6.EarlyOtherwiseBranch.diff diff --git a/compiler/rustc_mir/src/transform/early_otherwise_branch.rs b/compiler/rustc_mir/src/transform/early_otherwise_branch.rs index 898f65472c0a6..b1322d3cee6e0 100644 --- a/compiler/rustc_mir/src/transform/early_otherwise_branch.rs +++ b/compiler/rustc_mir/src/transform/early_otherwise_branch.rs @@ -4,7 +4,7 @@ use crate::{ }; use rustc_middle::mir::*; use rustc_middle::ty::{Ty, TyCtxt}; -use std::{borrow::Cow, fmt::Debug}; +use std::fmt::Debug; use super::simplify::simplify_cfg; @@ -98,33 +98,20 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch { StatementKind::Assign(box (Place::from(not_equal_temp), not_equal_rvalue)), ); - let (mut targets_to_jump_to, values_to_jump_to): (Vec<_>, Vec<_>) = opt_to_apply - .infos - .iter() - .flat_map(|x| x.second_switch_info.targets_with_values.iter()) - .cloned() - .unzip(); - - // add otherwise case in the end - targets_to_jump_to.push(opt_to_apply.infos[0].first_switch_info.otherwise_bb); - // new block that jumps to the correct discriminant case. This block is switched to if the discriminants are equal - let new_switch_data = BasicBlockData::new(Some(Terminator { - source_info: opt_to_apply.infos[0].second_switch_info.discr_source_info, - kind: TerminatorKind::SwitchInt { - // the first and second discriminants are equal, so just pick one - discr: Operand::Copy(first_descriminant_place), - switch_ty: discr_type, - values: Cow::from(values_to_jump_to), - targets: targets_to_jump_to, - }, - })); - - let new_switch_bb = patch.new_block(new_switch_data); - // switch on the NotEqual. If true, then jump to the `otherwise` case. // If false, then jump to a basic block that then jumps to the correct disciminant case let true_case = opt_to_apply.infos[0].first_switch_info.otherwise_bb; - let false_case = new_switch_bb; + let targets_second_switch = + &opt_to_apply.infos[0].second_switch_info.targets_with_values; + assert_eq!( + 1, + targets_second_switch.len(), + "We should only have one target besides the otherwise" + ); + + // Since we know that the two discriminant values are equal, + // we can jump directly to the target in the second switch + let false_case = targets_second_switch[0].0; patch.patch_terminator( opt_to_apply.basic_block_first_switch, TerminatorKind::if_( diff --git a/src/test/mir-opt/early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff index 386726bfddc74..733687c1b6854 100644 --- a/src/test/mir-opt/early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff @@ -36,7 +36,7 @@ + StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 + _11 = Ne(_10, _7); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 + StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 -+ switchInt(move _11) -> [false: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 ++ switchInt(move _11) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 } bb1: { @@ -52,6 +52,7 @@ - } - - bb3: { ++ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:5:15: 5:16 StorageLive(_8); // scope 0 at $DIR/early_otherwise_branch.rs:5:15: 5:16 _8 = (((_3.0: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:5:15: 5:16 StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:5:24: 5:25 @@ -67,11 +68,6 @@ + bb3: { StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:8:1: 8:2 return; // scope 0 at $DIR/early_otherwise_branch.rs:8:2: 8:2 -+ } -+ -+ bb4: { -+ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:5:19: 5:26 -+ switchInt(_7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:5:19: 5:26 } } diff --git a/src/test/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff index bc5934dec84e4..cd2bdc16d13b9 100644 --- a/src/test/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff @@ -37,7 +37,7 @@ + StorageLive(_12); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 + _12 = Ne(_11, _8); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 + StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 -+ switchInt(move _12) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 ++ switchInt(move _12) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 } bb1: { @@ -49,7 +49,7 @@ + StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch.rs:15:14: 15:15 _0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch.rs:15:14: 15:15 - goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 -+ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 ++ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 } - bb3: { @@ -58,34 +58,28 @@ - } - - bb4: { -+ bb2: { - StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:13:15: 13:16 - _9 = (((_3.0: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:13:15: 13:16 - StorageLive(_10); // scope 0 at $DIR/early_otherwise_branch.rs:13:24: 13:25 - _10 = (((_3.1: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:13:24: 13:25 - _0 = const 0_u32; // scope 1 at $DIR/early_otherwise_branch.rs:13:31: 13:32 - StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:13:31: 13:32 - StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:13:31: 13:32 +- StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:13:15: 13:16 +- _9 = (((_3.0: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:13:15: 13:16 +- StorageLive(_10); // scope 0 at $DIR/early_otherwise_branch.rs:13:24: 13:25 +- _10 = (((_3.1: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:13:24: 13:25 +- _0 = const 0_u32; // scope 1 at $DIR/early_otherwise_branch.rs:13:31: 13:32 +- StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:13:31: 13:32 +- StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:13:31: 13:32 - goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 -+ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 - } - +- } +- - bb5: { -+ bb3: { ++ bb2: { ++ StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch.rs:14:25: 14:26 _0 = const 0_u32; // scope 0 at $DIR/early_otherwise_branch.rs:14:25: 14:26 - goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 -+ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 ++ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 } - bb6: { -+ bb4: { ++ bb3: { StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:17:1: 17:2 return; // scope 0 at $DIR/early_otherwise_branch.rs:17:2: 17:2 -+ } -+ -+ bb5: { -+ StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch.rs:14:16: 14:20 -+ switchInt(_8) -> [0_isize: bb3, 1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:14:16: 14:20 } } diff --git a/src/test/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff index d2d1af19a77a7..7162bdb19dc95 100644 --- a/src/test/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff @@ -36,7 +36,7 @@ + StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 + _11 = Ne(_10, _7); // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 + StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 -+ switchInt(move _11) -> [false: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 ++ switchInt(move _11) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 } bb1: { @@ -53,6 +53,7 @@ - bb3: { + bb2: { ++ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:33:26: 33:27 StorageLive(_8); // scope 0 at $DIR/early_otherwise_branch.rs:33:26: 33:27 _8 = (((_3.0: MyOption1) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:33:26: 33:27 StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:33:46: 33:47 @@ -68,11 +69,6 @@ + bb3: { StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:36:1: 36:2 return; // scope 0 at $DIR/early_otherwise_branch.rs:36:2: 36:2 -+ } -+ -+ bb4: { -+ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:33:30: 33:48 -+ switchInt(_7) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:33:30: 33:48 } } diff --git a/src/test/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff index 105d33bf2022f..466f9e7aa5c5a 100644 --- a/src/test/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff @@ -30,7 +30,7 @@ + StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 + _9 = Ne(_8, _7); // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 + StorageDead(_8); // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 -+ switchInt(move _9) -> [false: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 ++ switchInt(move _9) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 } bb1: { @@ -43,22 +43,19 @@ bb2: { - _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:42:18: 42:25 - switchInt(move _6) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:42:18: 42:25 -+ _0 = const 0_u32; // scope 0 at $DIR/early_otherwise_branch.rs:42:30: 42:31 -+ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:41:5: 44:6 - } - - bb3: { -- _0 = const 0_u32; // scope 0 at $DIR/early_otherwise_branch.rs:42:30: 42:31 +- } +- +- bb3: { ++ StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:42:30: 42:31 + _0 = const 0_u32; // scope 0 at $DIR/early_otherwise_branch.rs:42:30: 42:31 - goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:41:5: 44:6 -+ StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:45:1: 45:2 -+ return; // scope 0 at $DIR/early_otherwise_branch.rs:45:2: 45:2 ++ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:41:5: 44:6 } - bb4: { -- StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:45:1: 45:2 -- return; // scope 0 at $DIR/early_otherwise_branch.rs:45:2: 45:2 -+ StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:42:18: 42:25 -+ switchInt(_7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:42:18: 42:25 +- bb4: { ++ bb3: { + StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:45:1: 45:2 + return; // scope 0 at $DIR/early_otherwise_branch.rs:45:2: 45:2 } } diff --git a/src/test/mir-opt/early_otherwise_branch.opt5.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt5.EarlyOtherwiseBranch.diff index 78e1b2414d0ed..f99913cba9275 100644 --- a/src/test/mir-opt/early_otherwise_branch.opt5.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch.opt5.EarlyOtherwiseBranch.diff @@ -36,7 +36,7 @@ + StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 + _11 = Ne(_10, _7); // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 + StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 -+ switchInt(move _11) -> [false: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 ++ switchInt(move _11) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 } bb1: { @@ -52,6 +52,7 @@ - } - - bb3: { ++ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:51:15: 51:16 StorageLive(_8); // scope 0 at $DIR/early_otherwise_branch.rs:51:15: 51:16 _8 = (((_3.0: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:51:15: 51:16 StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:51:24: 51:25 @@ -67,11 +68,6 @@ + bb3: { StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:54:1: 54:2 return; // scope 0 at $DIR/early_otherwise_branch.rs:54:2: 54:2 -+ } -+ -+ bb4: { -+ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:51:19: 51:26 -+ switchInt(_7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:51:19: 51:26 } } diff --git a/src/test/mir-opt/early_otherwise_branch.opt6.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt6.EarlyOtherwiseBranch.diff new file mode 100644 index 0000000000000..8169dba87bb9a --- /dev/null +++ b/src/test/mir-opt/early_otherwise_branch.opt6.EarlyOtherwiseBranch.diff @@ -0,0 +1,195 @@ +- // MIR for `opt6` before EarlyOtherwiseBranch ++ // MIR for `opt6` after EarlyOtherwiseBranch + + fn opt6(_1: Option, _2: Option<(u32, Option<(String, u32)>)>) -> u32 { + debug x => _1; // in scope 0 at $DIR/early_otherwise_branch.rs:58:13: 58:14 + debug y => _2; // in scope 0 at $DIR/early_otherwise_branch.rs:58:29: 58:30 + let mut _0: u32; // return place in scope 0 at $DIR/early_otherwise_branch.rs:58:73: 58:76 + let mut _3: (std::option::Option, std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>); // in scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 + let mut _4: std::option::Option; // in scope 0 at $DIR/early_otherwise_branch.rs:59:12: 59:13 + let mut _5: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>; // in scope 0 at $DIR/early_otherwise_branch.rs:59:15: 59:16 + let mut _6: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:60:28: 60:32 + let mut _7: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:60:19: 60:34 + let mut _8: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 + let _9: u32; // in scope 0 at $DIR/early_otherwise_branch.rs:61:25: 61:29 + let _10: std::string::String; // in scope 0 at $DIR/early_otherwise_branch.rs:61:37: 61:41 + let mut _11: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + let mut _12: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + let mut _13: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + let mut _14: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + let mut _15: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + let mut _16: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + let mut _17: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + let mut _18: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + let mut _19: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + let mut _20: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + let mut _21: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + let mut _22: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + let mut _23: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + let mut _24: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ let mut _25: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:60:19: 60:34 ++ let mut _26: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:60:19: 60:34 ++ let mut _27: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ let mut _28: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ let mut _29: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ let mut _30: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + scope 1 { + debug note => _9; // in scope 1 at $DIR/early_otherwise_branch.rs:61:25: 61:29 + debug sugg => _10; // in scope 1 at $DIR/early_otherwise_branch.rs:61:37: 61:41 + } + + bb0: { + _12 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 + _13 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 + _11 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 + StorageLive(_3); // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 + StorageLive(_4); // scope 0 at $DIR/early_otherwise_branch.rs:59:12: 59:13 + _4 = _1; // scope 0 at $DIR/early_otherwise_branch.rs:59:12: 59:13 + StorageLive(_5); // scope 0 at $DIR/early_otherwise_branch.rs:59:15: 59:16 + _5 = move _2; // scope 0 at $DIR/early_otherwise_branch.rs:59:15: 59:16 + _11 = const true; // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 + _12 = const true; // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 + _13 = const true; // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 + (_3.0: std::option::Option) = move _4; // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 + (_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) = move _5; // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 + StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch.rs:59:16: 59:17 + StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch.rs:59:16: 59:17 + _8 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 +- switchInt(move _8) -> [1_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 ++ StorageLive(_25); // scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 ++ _25 = discriminant((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>)); // scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 ++ StorageLive(_26); // scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 ++ _26 = Ne(_25, _8); // scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 ++ StorageDead(_25); // scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 ++ switchInt(move _26) -> [false: bb4, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 + } + + bb1 (cleanup): { ++ StorageDead(_28); // scope 0 at $DIR/early_otherwise_branch.rs:58:1: 64:2 + resume; // scope 0 at $DIR/early_otherwise_branch.rs:58:1: 64:2 + } + + bb2 (cleanup): { + _15 = discriminant((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>)); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 +- switchInt(move _15) -> [1_isize: bb9, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ StorageLive(_27); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ _27 = discriminant(((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>)); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ StorageLive(_28); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ _28 = Ne(_27, _15); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ StorageDead(_27); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ switchInt(move _28) -> [false: bb8, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + } + + bb3: { ++ StorageDead(_26); // scope 0 at $DIR/early_otherwise_branch.rs:62:14: 62:16 + _0 = const 99_u32; // scope 0 at $DIR/early_otherwise_branch.rs:62:14: 62:16 +- goto -> bb17; // scope 0 at $DIR/early_otherwise_branch.rs:59:5: 63:6 ++ goto -> bb14; // scope 0 at $DIR/early_otherwise_branch.rs:59:5: 63:6 + } + + bb4: { +- _7 = discriminant((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>)); // scope 0 at $DIR/early_otherwise_branch.rs:60:19: 60:34 +- switchInt(move _7) -> [1_isize: bb5, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch.rs:60:19: 60:34 +- } +- +- bb5: { ++ StorageDead(_26); // scope 0 at $DIR/early_otherwise_branch.rs:60:28: 60:32 + _6 = discriminant(((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>)); // scope 0 at $DIR/early_otherwise_branch.rs:60:28: 60:32 +- switchInt(move _6) -> [0_isize: bb6, 1_isize: bb7, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch.rs:60:28: 60:32 ++ switchInt(move _6) -> [0_isize: bb5, 1_isize: bb6, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch.rs:60:28: 60:32 + } + +- bb6: { ++ bb5: { + _0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch.rs:60:39: 60:40 +- goto -> bb17; // scope 0 at $DIR/early_otherwise_branch.rs:59:5: 63:6 ++ goto -> bb14; // scope 0 at $DIR/early_otherwise_branch.rs:59:5: 63:6 + } + +- bb7: { ++ bb6: { + StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:61:25: 61:29 + _9 = ((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:61:25: 61:29 + StorageLive(_10); // scope 0 at $DIR/early_otherwise_branch.rs:61:37: 61:41 + _13 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:61:37: 61:41 + _10 = move (((((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>) as Some).0: (std::string::String, u32)).0: std::string::String); // scope 0 at $DIR/early_otherwise_branch.rs:61:37: 61:41 + _0 = const 2_u32; // scope 1 at $DIR/early_otherwise_branch.rs:61:53: 61:54 +- drop(_10) -> [return: bb8, unwind: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:61:53: 61:54 ++ drop(_10) -> [return: bb7, unwind: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:61:53: 61:54 + } + +- bb8: { ++ bb7: { + StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:61:53: 61:54 + StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:61:53: 61:54 +- goto -> bb17; // scope 0 at $DIR/early_otherwise_branch.rs:59:5: 63:6 ++ goto -> bb14; // scope 0 at $DIR/early_otherwise_branch.rs:59:5: 63:6 + } + +- bb9 (cleanup): { +- _14 = discriminant(((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>)); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 +- switchInt(move _14) -> [1_isize: bb10, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 +- } +- +- bb10 (cleanup): { ++ bb8 (cleanup): { ++ StorageDead(_28); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + _12 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + goto -> bb1; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + } + +- bb11: { ++ bb9: { ++ StorageDead(_30); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + _11 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + _12 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + _13 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + return; // scope 0 at $DIR/early_otherwise_branch.rs:64:2: 64:2 + } + +- bb12: { +- _21 = discriminant(((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>)); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 +- switchInt(move _21) -> [1_isize: bb13, otherwise: bb11]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ bb10: { ++ StorageDead(_30); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ switchInt(_13) -> [false: bb11, otherwise: bb13]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + } + +- bb13: { +- switchInt(_13) -> [false: bb14, otherwise: bb16]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 +- } +- +- bb14: { ++ bb11: { + _12 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 +- goto -> bb11; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ goto -> bb9; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + } + +- bb15 (cleanup): { ++ bb12 (cleanup): { + _12 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + goto -> bb1; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + } + +- bb16: { ++ bb13: { + _13 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 +- drop((((((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>) as Some).0: (std::string::String, u32)).0: std::string::String)) -> [return: bb14, unwind: bb15]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ drop((((((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>) as Some).0: (std::string::String, u32)).0: std::string::String)) -> [return: bb11, unwind: bb12]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + } + +- bb17: { ++ bb14: { + _23 = discriminant((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>)); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 +- switchInt(move _23) -> [1_isize: bb12, otherwise: bb11]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ StorageLive(_29); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ _29 = discriminant(((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>)); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ StorageLive(_30); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ _30 = Ne(_29, _23); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ StorageDead(_29); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ switchInt(move _30) -> [false: bb10, otherwise: bb9]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + } + } + diff --git a/src/test/mir-opt/early_otherwise_branch.rs b/src/test/mir-opt/early_otherwise_branch.rs index 3892efe025da2..44ff05563a02f 100644 --- a/src/test/mir-opt/early_otherwise_branch.rs +++ b/src/test/mir-opt/early_otherwise_branch.rs @@ -53,10 +53,21 @@ fn opt5(x: Option, y: Option) -> u32 { } } +// This caused a miscompilation during development, so I included it here as a regression +// EMIT_MIR early_otherwise_branch.opt6.EarlyOtherwiseBranch.diff +pub fn opt6(x: Option, y: Option<(u32, Option<(String, u32)>)>) -> u32 { + match (x, y) { + (Some(_), Some((_, None))) => 1, + (Some(_), Some((note, Some((sugg, _))))) => 2, + _ => 99, + } +} + fn main() { opt1(None, Some(0)); opt2(None, Some(0)); opt3(MyOption1::None, MyOption2::Some(0)); opt4(Ok(0), None); opt5(None, Some(true)); + opt6(None, None); } diff --git a/src/test/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff index b0357f1aecd61..390ee5e862fbc 100644 --- a/src/test/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff @@ -47,7 +47,7 @@ + StorageLive(_15); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 + _15 = Ne(_14, _10); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 + StorageDead(_14); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 -+ switchInt(move _15) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 ++ switchInt(move _15) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 } bb1: { @@ -64,6 +64,7 @@ - } - - bb3: { ++ StorageDead(_15); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:28: 6:35 _8 = discriminant((_4.2: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:28: 6:35 - switchInt(move _8) -> [1_isize: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:28: 6:35 + switchInt(move _8) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:28: 6:35 @@ -71,6 +72,7 @@ - bb4: { + bb3: { ++ StorageDead(_17); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:15: 6:16 StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:15: 6:16 _11 = (((_4.0: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:15: 6:16 StorageLive(_12); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:24: 6:25 @@ -89,11 +91,6 @@ + bb4: { StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:9:1: 9:2 return; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:9:2: 9:2 -+ } -+ -+ bb5: { -+ StorageDead(_15); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:19: 6:26 -+ switchInt(_10) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:19: 6:26 } } diff --git a/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.before-SimplifyBranches-after-copy-prop.after.diff b/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.before-SimplifyBranches-after-copy-prop.after.diff index 2cf5dd49d6a91..0f613c4fc2e93 100644 --- a/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.before-SimplifyBranches-after-copy-prop.after.diff +++ b/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.before-SimplifyBranches-after-copy-prop.after.diff @@ -45,22 +45,16 @@ + debug other => _16; // in scope 1 at $DIR/early_otherwise_branch_68867.rs:23:24: 23:29 } scope 2 { -- debug one => _17; // in scope 2 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 -- debug other => _18; // in scope 2 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 -+ debug one => _20; // in scope 2 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 -+ debug other => _21; // in scope 2 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 + debug one => _17; // in scope 2 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 + debug other => _18; // in scope 2 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 } scope 3 { -- debug one => _22; // in scope 3 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 -- debug other => _23; // in scope 3 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 -+ debug one => _25; // in scope 3 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 -+ debug other => _26; // in scope 3 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 + debug one => _22; // in scope 3 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 + debug other => _23; // in scope 3 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 } scope 4 { -- debug one => _27; // in scope 4 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 -- debug other => _28; // in scope 4 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 -+ debug one => _30; // in scope 4 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 -+ debug other => _31; // in scope 4 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 + debug one => _27; // in scope 4 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 + debug other => _28; // in scope 4 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 } bb0: { @@ -91,7 +85,7 @@ + StorageLive(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 + _35 = Ne(_34, _11); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 + StorageDead(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 -+ switchInt(move _35) -> [false: bb7, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 ++ switchInt(move _35) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 } bb1: { @@ -112,97 +106,22 @@ return; // scope 0 at $DIR/early_otherwise_branch_68867.rs:27:14: 27:28 } -+ bb2: { -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 -+ _15 = (((*(_4.0: &ViewportPercentageLength)) as Vw).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:24: 23:29 -+ _16 = (((*(_4.1: &ViewportPercentageLength)) as Vw).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:24: 23:29 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:38: 23:49 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:38: 23:41 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:38: 23:41 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:44: 23:49 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:44: 23:49 -+ ((((_0 as Ok).0: ViewportPercentageLength) as Vw).0: f32) = Add(move _15, move _16); // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:38: 23:49 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:48: 23:49 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:48: 23:49 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:35: 23:50 -+ discriminant(((_0 as Ok).0: ViewportPercentageLength)) = 0; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:35: 23:50 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 -+ } -+ - bb3: { +- bb3: { - _8 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:21: 24:30 - switchInt(move _8) -> [1_isize: bb7, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:21: 24:30 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 -+ _20 = (((*(_4.0: &ViewportPercentageLength)) as Vh).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 -+ _21 = (((*(_4.1: &ViewportPercentageLength)) as Vh).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 -+ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:49 -+ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:41 -+ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:41 -+ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:44: 24:49 -+ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:44: 24:49 -+ ((((_0 as Ok).0: ViewportPercentageLength) as Vh).0: f32) = Add(move _20, move _21); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:49 -+ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:48: 24:49 -+ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:48: 24:49 -+ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:35: 24:50 -+ discriminant(((_0 as Ok).0: ViewportPercentageLength)) = 1; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:35: 24:50 -+ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 - } - - bb4: { +- } +- +- bb4: { - _9 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:23: 25:34 - switchInt(move _9) -> [2_isize: bb8, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:23: 25:34 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 -+ _25 = (((*(_4.0: &ViewportPercentageLength)) as Vmin).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 -+ _26 = (((*(_4.1: &ViewportPercentageLength)) as Vmin).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 -+ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:55 -+ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:47 -+ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:47 -+ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:50: 25:55 -+ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:50: 25:55 -+ ((((_0 as Ok).0: ViewportPercentageLength) as Vmin).0: f32) = Add(move _25, move _26); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:55 -+ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:54: 25:55 -+ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:54: 25:55 -+ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:39: 25:56 -+ discriminant(((_0 as Ok).0: ViewportPercentageLength)) = 2; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:39: 25:56 -+ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 - } - - bb5: { +- } +- +- bb5: { - _10 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:23: 26:34 - switchInt(move _10) -> [3_isize: bb9, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:23: 26:34 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 -+ _30 = (((*(_4.0: &ViewportPercentageLength)) as Vmax).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 -+ _31 = (((*(_4.1: &ViewportPercentageLength)) as Vmax).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 -+ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:55 -+ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:47 -+ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:47 -+ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:50: 26:55 -+ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:50: 26:55 -+ ((((_0 as Ok).0: ViewportPercentageLength) as Vmax).0: f32) = Add(move _30, move _31); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:55 -+ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:54: 26:55 -+ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:54: 26:55 -+ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:39: 26:56 -+ discriminant(((_0 as Ok).0: ViewportPercentageLength)) = 3; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:39: 26:56 -+ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 - } - - bb6: { +- } +- +- bb6: { - StorageLive(_12); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 - _12 = (((*(_4.0: &ViewportPercentageLength)) as Vw).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 - StorageLive(_13); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:24: 23:29 @@ -221,14 +140,9 @@ - StorageDead(_13); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 - StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 - goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:5: 28:7 -+ discriminant(_0) = 0; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:5: 28:7 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:28:6: 28:7 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:29:1: 29:2 -+ return; // scope 0 at $DIR/early_otherwise_branch_68867.rs:29:2: 29:2 - } - - bb7: { +- } +- +- bb7: { - StorageLive(_17); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 - _17 = (((*(_4.0: &ViewportPercentageLength)) as Vh).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 - StorageLive(_18); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 @@ -293,12 +207,32 @@ - - bb10: { - ((_0 as Ok).0: ViewportPercentageLength) = move _3; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:5: 28:7 -- discriminant(_0) = 0; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:5: 28:7 ++ bb2: { ++ StorageDead(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 ++ _15 = (((*(_4.0: &ViewportPercentageLength)) as Vw).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:24: 23:29 ++ _16 = (((*(_4.1: &ViewportPercentageLength)) as Vw).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:24: 23:29 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:38: 23:49 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:38: 23:41 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:38: 23:41 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:44: 23:49 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:44: 23:49 ++ ((((_0 as Ok).0: ViewportPercentageLength) as Vw).0: f32) = Add(move _15, move _16); // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:38: 23:49 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:48: 23:49 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:48: 23:49 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:35: 23:50 ++ discriminant(((_0 as Ok).0: ViewportPercentageLength)) = 0; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:35: 23:50 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:5: 28:7 + discriminant(_0) = 0; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:5: 28:7 - StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch_68867.rs:28:6: 28:7 - StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch_68867.rs:29:1: 29:2 -- return; // scope 0 at $DIR/early_otherwise_branch_68867.rs:29:2: 29:2 -+ StorageDead(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:21: 23:30 -+ switchInt(_11) -> [0_isize: bb2, 1_isize: bb3, 2_isize: bb4, 3_isize: bb5, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:21: 23:30 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:28:6: 28:7 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:29:1: 29:2 + return; // scope 0 at $DIR/early_otherwise_branch_68867.rs:29:2: 29:2 } } diff --git a/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff index a80bf2ac0179c..e92344c57c26f 100644 --- a/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff @@ -73,7 +73,7 @@ + StorageLive(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 + _35 = Ne(_34, _11); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 + StorageDead(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 -+ switchInt(move _35) -> [false: bb7, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 ++ switchInt(move _35) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 } bb1: { @@ -109,6 +109,7 @@ - - bb6: { + bb2: { ++ StorageDead(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 StorageLive(_12); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 _12 = (((*(_4.0: &ViewportPercentageLength)) as Vw).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 StorageLive(_13); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:24: 23:29 @@ -127,90 +128,77 @@ StorageDead(_13); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 - goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 - } - +- } +- - bb7: { -+ bb3: { - StorageLive(_17); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 - _17 = (((*(_4.0: &ViewportPercentageLength)) as Vh).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 - StorageLive(_18); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 - _18 = (((*(_4.1: &ViewportPercentageLength)) as Vh).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 - StorageLive(_19); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:49 - StorageLive(_20); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:41 - _20 = _17; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:41 - StorageLive(_21); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:44: 24:49 - _21 = _18; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:44: 24:49 - _19 = Add(move _20, move _21); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:49 - StorageDead(_21); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:48: 24:49 - StorageDead(_20); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:48: 24:49 - ((_3 as Vh).0: f32) = move _19; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:35: 24:50 - discriminant(_3) = 1; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:35: 24:50 - StorageDead(_19); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 - StorageDead(_18); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 - StorageDead(_17); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 +- StorageLive(_17); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 +- _17 = (((*(_4.0: &ViewportPercentageLength)) as Vh).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 +- StorageLive(_18); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 +- _18 = (((*(_4.1: &ViewportPercentageLength)) as Vh).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 +- StorageLive(_19); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:49 +- StorageLive(_20); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:41 +- _20 = _17; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:41 +- StorageLive(_21); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:44: 24:49 +- _21 = _18; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:44: 24:49 +- _19 = Add(move _20, move _21); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:49 +- StorageDead(_21); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:48: 24:49 +- StorageDead(_20); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:48: 24:49 +- ((_3 as Vh).0: f32) = move _19; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:35: 24:50 +- discriminant(_3) = 1; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:35: 24:50 +- StorageDead(_19); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 +- StorageDead(_18); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 +- StorageDead(_17); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 - goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 - } - +- } +- - bb8: { -+ bb4: { - StorageLive(_22); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 - _22 = (((*(_4.0: &ViewportPercentageLength)) as Vmin).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 - StorageLive(_23); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 - _23 = (((*(_4.1: &ViewportPercentageLength)) as Vmin).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 - StorageLive(_24); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:55 - StorageLive(_25); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:47 - _25 = _22; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:47 - StorageLive(_26); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:50: 25:55 - _26 = _23; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:50: 25:55 - _24 = Add(move _25, move _26); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:55 - StorageDead(_26); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:54: 25:55 - StorageDead(_25); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:54: 25:55 - ((_3 as Vmin).0: f32) = move _24; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:39: 25:56 - discriminant(_3) = 2; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:39: 25:56 - StorageDead(_24); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 - StorageDead(_23); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 - StorageDead(_22); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 +- StorageLive(_22); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 +- _22 = (((*(_4.0: &ViewportPercentageLength)) as Vmin).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 +- StorageLive(_23); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 +- _23 = (((*(_4.1: &ViewportPercentageLength)) as Vmin).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 +- StorageLive(_24); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:55 +- StorageLive(_25); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:47 +- _25 = _22; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:47 +- StorageLive(_26); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:50: 25:55 +- _26 = _23; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:50: 25:55 +- _24 = Add(move _25, move _26); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:55 +- StorageDead(_26); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:54: 25:55 +- StorageDead(_25); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:54: 25:55 +- ((_3 as Vmin).0: f32) = move _24; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:39: 25:56 +- discriminant(_3) = 2; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:39: 25:56 +- StorageDead(_24); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 +- StorageDead(_23); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 +- StorageDead(_22); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 - goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 - } - +- } +- - bb9: { -+ bb5: { - StorageLive(_27); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 - _27 = (((*(_4.0: &ViewportPercentageLength)) as Vmax).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 - StorageLive(_28); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 - _28 = (((*(_4.1: &ViewportPercentageLength)) as Vmax).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 - StorageLive(_29); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:55 - StorageLive(_30); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:47 - _30 = _27; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:47 - StorageLive(_31); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:50: 26:55 - _31 = _28; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:50: 26:55 - _29 = Add(move _30, move _31); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:55 - StorageDead(_31); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:54: 26:55 - StorageDead(_30); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:54: 26:55 - ((_3 as Vmax).0: f32) = move _29; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:39: 26:56 - discriminant(_3) = 3; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:39: 26:56 - StorageDead(_29); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 - StorageDead(_28); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 - StorageDead(_27); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 +- StorageLive(_27); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 +- _27 = (((*(_4.0: &ViewportPercentageLength)) as Vmax).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 +- StorageLive(_28); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 +- _28 = (((*(_4.1: &ViewportPercentageLength)) as Vmax).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 +- StorageLive(_29); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:55 +- StorageLive(_30); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:47 +- _30 = _27; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:47 +- StorageLive(_31); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:50: 26:55 +- _31 = _28; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:50: 26:55 +- _29 = Add(move _30, move _31); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:55 +- StorageDead(_31); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:54: 26:55 +- StorageDead(_30); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:54: 26:55 +- ((_3 as Vmax).0: f32) = move _29; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:39: 26:56 +- discriminant(_3) = 3; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:39: 26:56 +- StorageDead(_29); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 +- StorageDead(_28); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 +- StorageDead(_27); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 - goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 - } - +- } +- - bb10: { -+ bb6: { ((_0 as Ok).0: ViewportPercentageLength) = move _3; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:5: 28:7 discriminant(_0) = 0; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:5: 28:7 StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch_68867.rs:28:6: 28:7 StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch_68867.rs:29:1: 29:2 return; // scope 0 at $DIR/early_otherwise_branch_68867.rs:29:2: 29:2 -+ } -+ -+ bb7: { -+ StorageDead(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:21: 23:30 -+ switchInt(_11) -> [0_isize: bb2, 1_isize: bb3, 2_isize: bb4, 3_isize: bb5, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:21: 23:30 } } From 03e18145330fa7b7092723a99fc3cc90483b2d7b Mon Sep 17 00:00:00 2001 From: Simon Vandel Sillesen Date: Wed, 30 Sep 2020 22:34:53 +0200 Subject: [PATCH 5/6] remove unused fields --- .../rustc_mir/src/transform/early_otherwise_branch.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/compiler/rustc_mir/src/transform/early_otherwise_branch.rs b/compiler/rustc_mir/src/transform/early_otherwise_branch.rs index b1322d3cee6e0..3515309171cf5 100644 --- a/compiler/rustc_mir/src/transform/early_otherwise_branch.rs +++ b/compiler/rustc_mir/src/transform/early_otherwise_branch.rs @@ -40,7 +40,7 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch { let opts_to_apply: Vec> = bbs_with_switch .flat_map(|(bb_idx, bb)| { let switch = bb.terminator(); - let helper = Helper { body, tcx }; + let helper = Helper { body }; let infos = helper.go(bb, switch)?; Some(OptimizationToApply { infos, basic_block_first_switch: bb_idx }) }) @@ -156,7 +156,6 @@ fn is_switch<'tcx>(terminator: &Terminator<'tcx>) -> bool { struct Helper<'a, 'tcx> { body: &'a Body<'tcx>, - tcx: TyCtxt<'tcx>, } #[derive(Debug, Clone)] @@ -172,8 +171,6 @@ struct SwitchDiscriminantInfo<'tcx> { discr_used_in_switch: Place<'tcx>, /// The place of the adt that has its discriminant read place_of_adt_discr_read: Place<'tcx>, - /// The type of the adt that has its discriminant read - type_adt_matched_on: Ty<'tcx>, } #[derive(Debug)] @@ -293,8 +290,6 @@ impl<'a, 'tcx> Helper<'a, 'tcx> { _ => None, }?; - let type_adt_matched_on = place_of_adt_discr_read.ty(self.body, self.tcx).ty; - Some(SwitchDiscriminantInfo { discr_used_in_switch: discr.place()?, discr_ty, @@ -302,7 +297,6 @@ impl<'a, 'tcx> Helper<'a, 'tcx> { targets_with_values, discr_source_info: discr_decl.source_info, place_of_adt_discr_read, - type_adt_matched_on, }) } _ => unreachable!("must only be passed terminator that is a switch"), From 67a701374e7e84adfbfa4cfab3ba7b0e311bbd04 Mon Sep 17 00:00:00 2001 From: Simon Vandel Sillesen Date: Thu, 1 Oct 2020 22:53:55 +0200 Subject: [PATCH 6/6] Add back basic block to disambiguate where to go --- .../src/transform/early_otherwise_branch.rs | 73 ++++- ...wise_branch.opt1.EarlyOtherwiseBranch.diff | 8 +- ...wise_branch.opt2.EarlyOtherwiseBranch.diff | 36 ++- ...wise_branch.opt3.EarlyOtherwiseBranch.diff | 8 +- ...wise_branch.opt4.EarlyOtherwiseBranch.diff | 25 +- ...wise_branch.opt5.EarlyOtherwiseBranch.diff | 8 +- ...wise_branch.opt6.EarlyOtherwiseBranch.diff | 258 +++++++++--------- src/test/mir-opt/early_otherwise_branch.rs | 4 +- ...ement_tuple.opt1.EarlyOtherwiseBranch.diff | 9 +- ...implifyBranches-after-copy-prop.after.diff | 154 ++++++++--- ...ch_68867.try_sum.EarlyOtherwiseBranch.diff | 134 ++++----- 11 files changed, 439 insertions(+), 278 deletions(-) diff --git a/compiler/rustc_mir/src/transform/early_otherwise_branch.rs b/compiler/rustc_mir/src/transform/early_otherwise_branch.rs index 3515309171cf5..ca5ab225312d6 100644 --- a/compiler/rustc_mir/src/transform/early_otherwise_branch.rs +++ b/compiler/rustc_mir/src/transform/early_otherwise_branch.rs @@ -4,7 +4,7 @@ use crate::{ }; use rustc_middle::mir::*; use rustc_middle::ty::{Ty, TyCtxt}; -use std::fmt::Debug; +use std::{borrow::Cow, fmt::Debug}; use super::simplify::simplify_cfg; @@ -98,22 +98,67 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch { StatementKind::Assign(box (Place::from(not_equal_temp), not_equal_rvalue)), ); - // switch on the NotEqual. If true, then jump to the `otherwise` case. - // If false, then jump to a basic block that then jumps to the correct disciminant case + // Switch on the NotEqual. If true, then jump to the `otherwise` case, + // since we know the discriminant values are not the same. let true_case = opt_to_apply.infos[0].first_switch_info.otherwise_bb; - let targets_second_switch = - &opt_to_apply.infos[0].second_switch_info.targets_with_values; - assert_eq!( - 1, - targets_second_switch.len(), - "We should only have one target besides the otherwise" - ); - // Since we know that the two discriminant values are equal, - // we can jump directly to the target in the second switch - let false_case = targets_second_switch[0].0; + // In the false case we know that the two discriminant values are equal, + // however we still need to account for the following scenario: + // ```rust + // match (x, y) { + // (Some(_), Some(_)) => 0, + // _ => 2 + // } + // ``` + // + // Here, the two match arms have the same discriminant values, but + // we need to make sure that we did not reach a `(None, None)` pattern. + // We therefore construct a new basic block that can disambiguate where to go. + + let mut targets_and_values_to_jump_to = vec![]; + for info in opt_to_apply.infos.iter() { + for (_, value) in info.first_switch_info.targets_with_values.iter() { + // Find corresponding value in second switch info - + // this is where we want to jump to + if let Some((target_to_jump_to, _)) = info + .second_switch_info + .targets_with_values + .iter() + .find(|(_, second_value)| value == second_value) + { + targets_and_values_to_jump_to.push((target_to_jump_to, value)); + } + } + } + + let (mut targets_to_jump_to, values_to_jump_to): (Vec<_>, Vec<_>) = + targets_and_values_to_jump_to.iter().cloned().unzip(); + + // add otherwise case in the end + targets_to_jump_to.push(opt_to_apply.infos[0].first_switch_info.otherwise_bb); + + // new block that jumps to the correct discriminant case. This block is switched to if the discriminants are equal + let mut new_switch_data = BasicBlockData::new(Some(Terminator { + source_info: opt_to_apply.infos[0].second_switch_info.discr_source_info, + kind: TerminatorKind::SwitchInt { + // the first and second discriminants are equal, so just pick one + discr: Operand::Copy(first_descriminant_place), + switch_ty: discr_type, + values: Cow::from(values_to_jump_to), + targets: targets_to_jump_to, + }, + })); + + let basic_block_first_switch = opt_to_apply.basic_block_first_switch; + + // Inherit the is_cleanup from the bb we are jumping from, which is where the first switch is + new_switch_data.is_cleanup = body.basic_blocks()[basic_block_first_switch].is_cleanup; + + let new_switch_bb = patch.new_block(new_switch_data); + let false_case = new_switch_bb; + patch.patch_terminator( - opt_to_apply.basic_block_first_switch, + basic_block_first_switch, TerminatorKind::if_( tcx, Operand::Move(Place::from(not_equal_temp)), diff --git a/src/test/mir-opt/early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff index 733687c1b6854..386726bfddc74 100644 --- a/src/test/mir-opt/early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff @@ -36,7 +36,7 @@ + StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 + _11 = Ne(_10, _7); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 + StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 -+ switchInt(move _11) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 ++ switchInt(move _11) -> [false: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 } bb1: { @@ -52,7 +52,6 @@ - } - - bb3: { -+ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:5:15: 5:16 StorageLive(_8); // scope 0 at $DIR/early_otherwise_branch.rs:5:15: 5:16 _8 = (((_3.0: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:5:15: 5:16 StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:5:24: 5:25 @@ -68,6 +67,11 @@ + bb3: { StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:8:1: 8:2 return; // scope 0 at $DIR/early_otherwise_branch.rs:8:2: 8:2 ++ } ++ ++ bb4: { ++ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:5:19: 5:26 ++ switchInt(_7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:5:19: 5:26 } } diff --git a/src/test/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff index cd2bdc16d13b9..bc5934dec84e4 100644 --- a/src/test/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff @@ -37,7 +37,7 @@ + StorageLive(_12); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 + _12 = Ne(_11, _8); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 + StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 -+ switchInt(move _12) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 ++ switchInt(move _12) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 } bb1: { @@ -49,7 +49,7 @@ + StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch.rs:15:14: 15:15 _0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch.rs:15:14: 15:15 - goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 -+ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 ++ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 } - bb3: { @@ -58,28 +58,34 @@ - } - - bb4: { -- StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:13:15: 13:16 -- _9 = (((_3.0: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:13:15: 13:16 -- StorageLive(_10); // scope 0 at $DIR/early_otherwise_branch.rs:13:24: 13:25 -- _10 = (((_3.1: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:13:24: 13:25 -- _0 = const 0_u32; // scope 1 at $DIR/early_otherwise_branch.rs:13:31: 13:32 -- StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:13:31: 13:32 -- StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:13:31: 13:32 ++ bb2: { + StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:13:15: 13:16 + _9 = (((_3.0: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:13:15: 13:16 + StorageLive(_10); // scope 0 at $DIR/early_otherwise_branch.rs:13:24: 13:25 + _10 = (((_3.1: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:13:24: 13:25 + _0 = const 0_u32; // scope 1 at $DIR/early_otherwise_branch.rs:13:31: 13:32 + StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:13:31: 13:32 + StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:13:31: 13:32 - goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 -- } -- ++ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 + } + - bb5: { -+ bb2: { -+ StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch.rs:14:25: 14:26 ++ bb3: { _0 = const 0_u32; // scope 0 at $DIR/early_otherwise_branch.rs:14:25: 14:26 - goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 -+ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 ++ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 } - bb6: { -+ bb3: { ++ bb4: { StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:17:1: 17:2 return; // scope 0 at $DIR/early_otherwise_branch.rs:17:2: 17:2 ++ } ++ ++ bb5: { ++ StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch.rs:14:16: 14:20 ++ switchInt(_8) -> [0_isize: bb3, 1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:14:16: 14:20 } } diff --git a/src/test/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff index 7162bdb19dc95..d2d1af19a77a7 100644 --- a/src/test/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff @@ -36,7 +36,7 @@ + StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 + _11 = Ne(_10, _7); // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 + StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 -+ switchInt(move _11) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 ++ switchInt(move _11) -> [false: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:33:10: 33:28 } bb1: { @@ -53,7 +53,6 @@ - bb3: { + bb2: { -+ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:33:26: 33:27 StorageLive(_8); // scope 0 at $DIR/early_otherwise_branch.rs:33:26: 33:27 _8 = (((_3.0: MyOption1) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:33:26: 33:27 StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:33:46: 33:47 @@ -69,6 +68,11 @@ + bb3: { StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:36:1: 36:2 return; // scope 0 at $DIR/early_otherwise_branch.rs:36:2: 36:2 ++ } ++ ++ bb4: { ++ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:33:30: 33:48 ++ switchInt(_7) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:33:30: 33:48 } } diff --git a/src/test/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff index 466f9e7aa5c5a..105d33bf2022f 100644 --- a/src/test/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff @@ -30,7 +30,7 @@ + StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 + _9 = Ne(_8, _7); // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 + StorageDead(_8); // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 -+ switchInt(move _9) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 ++ switchInt(move _9) -> [false: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:42:10: 42:16 } bb1: { @@ -43,19 +43,22 @@ bb2: { - _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:42:18: 42:25 - switchInt(move _6) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:42:18: 42:25 -- } -- -- bb3: { -+ StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:42:30: 42:31 - _0 = const 0_u32; // scope 0 at $DIR/early_otherwise_branch.rs:42:30: 42:31 -- goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:41:5: 44:6 ++ _0 = const 0_u32; // scope 0 at $DIR/early_otherwise_branch.rs:42:30: 42:31 + goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:41:5: 44:6 } -- bb4: { -+ bb3: { - StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:45:1: 45:2 - return; // scope 0 at $DIR/early_otherwise_branch.rs:45:2: 45:2 + bb3: { +- _0 = const 0_u32; // scope 0 at $DIR/early_otherwise_branch.rs:42:30: 42:31 +- goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:41:5: 44:6 ++ StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:45:1: 45:2 ++ return; // scope 0 at $DIR/early_otherwise_branch.rs:45:2: 45:2 + } + + bb4: { +- StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:45:1: 45:2 +- return; // scope 0 at $DIR/early_otherwise_branch.rs:45:2: 45:2 ++ StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:42:18: 42:25 ++ switchInt(_7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:42:18: 42:25 } } diff --git a/src/test/mir-opt/early_otherwise_branch.opt5.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt5.EarlyOtherwiseBranch.diff index f99913cba9275..78e1b2414d0ed 100644 --- a/src/test/mir-opt/early_otherwise_branch.opt5.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch.opt5.EarlyOtherwiseBranch.diff @@ -36,7 +36,7 @@ + StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 + _11 = Ne(_10, _7); // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 + StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 -+ switchInt(move _11) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 ++ switchInt(move _11) -> [false: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:51:10: 51:17 } bb1: { @@ -52,7 +52,6 @@ - } - - bb3: { -+ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:51:15: 51:16 StorageLive(_8); // scope 0 at $DIR/early_otherwise_branch.rs:51:15: 51:16 _8 = (((_3.0: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:51:15: 51:16 StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:51:24: 51:25 @@ -68,6 +67,11 @@ + bb3: { StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:54:1: 54:2 return; // scope 0 at $DIR/early_otherwise_branch.rs:54:2: 54:2 ++ } ++ ++ bb4: { ++ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:51:19: 51:26 ++ switchInt(_7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:51:19: 51:26 } } diff --git a/src/test/mir-opt/early_otherwise_branch.opt6.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt6.EarlyOtherwiseBranch.diff index 8169dba87bb9a..78e6ebe20d0df 100644 --- a/src/test/mir-opt/early_otherwise_branch.opt6.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch.opt6.EarlyOtherwiseBranch.diff @@ -2,194 +2,206 @@ + // MIR for `opt6` after EarlyOtherwiseBranch fn opt6(_1: Option, _2: Option<(u32, Option<(String, u32)>)>) -> u32 { - debug x => _1; // in scope 0 at $DIR/early_otherwise_branch.rs:58:13: 58:14 - debug y => _2; // in scope 0 at $DIR/early_otherwise_branch.rs:58:29: 58:30 - let mut _0: u32; // return place in scope 0 at $DIR/early_otherwise_branch.rs:58:73: 58:76 - let mut _3: (std::option::Option, std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>); // in scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 - let mut _4: std::option::Option; // in scope 0 at $DIR/early_otherwise_branch.rs:59:12: 59:13 - let mut _5: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>; // in scope 0 at $DIR/early_otherwise_branch.rs:59:15: 59:16 - let mut _6: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:60:28: 60:32 - let mut _7: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:60:19: 60:34 - let mut _8: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 - let _9: u32; // in scope 0 at $DIR/early_otherwise_branch.rs:61:25: 61:29 - let _10: std::string::String; // in scope 0 at $DIR/early_otherwise_branch.rs:61:37: 61:41 - let mut _11: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - let mut _12: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - let mut _13: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - let mut _14: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - let mut _15: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - let mut _16: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - let mut _17: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - let mut _18: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - let mut _19: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - let mut _20: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - let mut _21: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - let mut _22: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - let mut _23: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - let mut _24: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ let mut _25: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:60:19: 60:34 -+ let mut _26: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:60:19: 60:34 -+ let mut _27: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ let mut _28: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ let mut _29: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ let mut _30: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + debug x => _1; // in scope 0 at $DIR/early_otherwise_branch.rs:60:13: 60:14 + debug y => _2; // in scope 0 at $DIR/early_otherwise_branch.rs:60:29: 60:30 + let mut _0: u32; // return place in scope 0 at $DIR/early_otherwise_branch.rs:60:73: 60:76 + let mut _3: (std::option::Option, std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>); // in scope 0 at $DIR/early_otherwise_branch.rs:61:11: 61:17 + let mut _4: std::option::Option; // in scope 0 at $DIR/early_otherwise_branch.rs:61:12: 61:13 + let mut _5: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>; // in scope 0 at $DIR/early_otherwise_branch.rs:61:15: 61:16 + let mut _6: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:62:28: 62:32 + let mut _7: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:62:19: 62:34 + let mut _8: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:62:10: 62:17 + let _9: u32; // in scope 0 at $DIR/early_otherwise_branch.rs:63:25: 63:29 + let _10: std::string::String; // in scope 0 at $DIR/early_otherwise_branch.rs:63:37: 63:41 + let mut _11: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + let mut _12: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + let mut _13: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + let mut _14: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + let mut _15: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + let mut _16: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + let mut _17: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + let mut _18: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + let mut _19: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + let mut _20: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + let mut _21: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + let mut _22: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + let mut _23: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + let mut _24: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ let mut _25: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:62:19: 62:34 ++ let mut _26: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:62:19: 62:34 ++ let mut _27: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ let mut _28: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ let mut _29: isize; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ let mut _30: bool; // in scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 scope 1 { - debug note => _9; // in scope 1 at $DIR/early_otherwise_branch.rs:61:25: 61:29 - debug sugg => _10; // in scope 1 at $DIR/early_otherwise_branch.rs:61:37: 61:41 + debug note => _9; // in scope 1 at $DIR/early_otherwise_branch.rs:63:25: 63:29 + debug sugg => _10; // in scope 1 at $DIR/early_otherwise_branch.rs:63:37: 63:41 } bb0: { - _12 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 - _13 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 - _11 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 - StorageLive(_3); // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 - StorageLive(_4); // scope 0 at $DIR/early_otherwise_branch.rs:59:12: 59:13 - _4 = _1; // scope 0 at $DIR/early_otherwise_branch.rs:59:12: 59:13 - StorageLive(_5); // scope 0 at $DIR/early_otherwise_branch.rs:59:15: 59:16 - _5 = move _2; // scope 0 at $DIR/early_otherwise_branch.rs:59:15: 59:16 - _11 = const true; // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 - _12 = const true; // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 - _13 = const true; // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 - (_3.0: std::option::Option) = move _4; // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 - (_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) = move _5; // scope 0 at $DIR/early_otherwise_branch.rs:59:11: 59:17 - StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch.rs:59:16: 59:17 - StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch.rs:59:16: 59:17 - _8 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 -- switchInt(move _8) -> [1_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 -+ StorageLive(_25); // scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 -+ _25 = discriminant((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>)); // scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 -+ StorageLive(_26); // scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 -+ _26 = Ne(_25, _8); // scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 -+ StorageDead(_25); // scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 -+ switchInt(move _26) -> [false: bb4, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch.rs:60:10: 60:17 + _12 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:61:11: 61:17 + _13 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:61:11: 61:17 + _11 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:61:11: 61:17 + StorageLive(_3); // scope 0 at $DIR/early_otherwise_branch.rs:61:11: 61:17 + StorageLive(_4); // scope 0 at $DIR/early_otherwise_branch.rs:61:12: 61:13 + _4 = _1; // scope 0 at $DIR/early_otherwise_branch.rs:61:12: 61:13 + StorageLive(_5); // scope 0 at $DIR/early_otherwise_branch.rs:61:15: 61:16 + _5 = move _2; // scope 0 at $DIR/early_otherwise_branch.rs:61:15: 61:16 + _11 = const true; // scope 0 at $DIR/early_otherwise_branch.rs:61:11: 61:17 + _12 = const true; // scope 0 at $DIR/early_otherwise_branch.rs:61:11: 61:17 + _13 = const true; // scope 0 at $DIR/early_otherwise_branch.rs:61:11: 61:17 + (_3.0: std::option::Option) = move _4; // scope 0 at $DIR/early_otherwise_branch.rs:61:11: 61:17 + (_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) = move _5; // scope 0 at $DIR/early_otherwise_branch.rs:61:11: 61:17 + StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch.rs:61:16: 61:17 + StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch.rs:61:16: 61:17 + _8 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:62:10: 62:17 +- switchInt(move _8) -> [1_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch.rs:62:10: 62:17 ++ StorageLive(_25); // scope 0 at $DIR/early_otherwise_branch.rs:62:10: 62:17 ++ _25 = discriminant((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>)); // scope 0 at $DIR/early_otherwise_branch.rs:62:10: 62:17 ++ StorageLive(_26); // scope 0 at $DIR/early_otherwise_branch.rs:62:10: 62:17 ++ _26 = Ne(_25, _8); // scope 0 at $DIR/early_otherwise_branch.rs:62:10: 62:17 ++ StorageDead(_25); // scope 0 at $DIR/early_otherwise_branch.rs:62:10: 62:17 ++ switchInt(move _26) -> [false: bb15, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch.rs:62:10: 62:17 } bb1 (cleanup): { -+ StorageDead(_28); // scope 0 at $DIR/early_otherwise_branch.rs:58:1: 64:2 - resume; // scope 0 at $DIR/early_otherwise_branch.rs:58:1: 64:2 ++ StorageDead(_28); // scope 0 at $DIR/early_otherwise_branch.rs:60:1: 66:2 + resume; // scope 0 at $DIR/early_otherwise_branch.rs:60:1: 66:2 } bb2 (cleanup): { - _15 = discriminant((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>)); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -- switchInt(move _15) -> [1_isize: bb9, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ StorageLive(_27); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ _27 = discriminant(((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>)); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ StorageLive(_28); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ _28 = Ne(_27, _15); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ StorageDead(_27); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ switchInt(move _28) -> [false: bb8, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + _15 = discriminant((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>)); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 +- switchInt(move _15) -> [1_isize: bb9, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ StorageLive(_27); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ _27 = discriminant(((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>)); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ StorageLive(_28); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ _28 = Ne(_27, _15); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ StorageDead(_27); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ switchInt(move _28) -> [false: bb16, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 } bb3: { -+ StorageDead(_26); // scope 0 at $DIR/early_otherwise_branch.rs:62:14: 62:16 - _0 = const 99_u32; // scope 0 at $DIR/early_otherwise_branch.rs:62:14: 62:16 -- goto -> bb17; // scope 0 at $DIR/early_otherwise_branch.rs:59:5: 63:6 -+ goto -> bb14; // scope 0 at $DIR/early_otherwise_branch.rs:59:5: 63:6 ++ StorageDead(_26); // scope 0 at $DIR/early_otherwise_branch.rs:64:14: 64:16 + _0 = const 99_u32; // scope 0 at $DIR/early_otherwise_branch.rs:64:14: 64:16 +- goto -> bb17; // scope 0 at $DIR/early_otherwise_branch.rs:61:5: 65:6 ++ goto -> bb14; // scope 0 at $DIR/early_otherwise_branch.rs:61:5: 65:6 } bb4: { -- _7 = discriminant((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>)); // scope 0 at $DIR/early_otherwise_branch.rs:60:19: 60:34 -- switchInt(move _7) -> [1_isize: bb5, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch.rs:60:19: 60:34 +- _7 = discriminant((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>)); // scope 0 at $DIR/early_otherwise_branch.rs:62:19: 62:34 +- switchInt(move _7) -> [1_isize: bb5, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch.rs:62:19: 62:34 - } - - bb5: { -+ StorageDead(_26); // scope 0 at $DIR/early_otherwise_branch.rs:60:28: 60:32 - _6 = discriminant(((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>)); // scope 0 at $DIR/early_otherwise_branch.rs:60:28: 60:32 -- switchInt(move _6) -> [0_isize: bb6, 1_isize: bb7, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch.rs:60:28: 60:32 -+ switchInt(move _6) -> [0_isize: bb5, 1_isize: bb6, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch.rs:60:28: 60:32 + _6 = discriminant(((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>)); // scope 0 at $DIR/early_otherwise_branch.rs:62:28: 62:32 +- switchInt(move _6) -> [0_isize: bb6, 1_isize: bb7, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch.rs:62:28: 62:32 ++ switchInt(move _6) -> [0_isize: bb5, 1_isize: bb6, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch.rs:62:28: 62:32 } - bb6: { + bb5: { - _0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch.rs:60:39: 60:40 -- goto -> bb17; // scope 0 at $DIR/early_otherwise_branch.rs:59:5: 63:6 -+ goto -> bb14; // scope 0 at $DIR/early_otherwise_branch.rs:59:5: 63:6 + _0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch.rs:62:39: 62:40 +- goto -> bb17; // scope 0 at $DIR/early_otherwise_branch.rs:61:5: 65:6 ++ goto -> bb14; // scope 0 at $DIR/early_otherwise_branch.rs:61:5: 65:6 } - bb7: { + bb6: { - StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:61:25: 61:29 - _9 = ((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:61:25: 61:29 - StorageLive(_10); // scope 0 at $DIR/early_otherwise_branch.rs:61:37: 61:41 - _13 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:61:37: 61:41 - _10 = move (((((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>) as Some).0: (std::string::String, u32)).0: std::string::String); // scope 0 at $DIR/early_otherwise_branch.rs:61:37: 61:41 - _0 = const 2_u32; // scope 1 at $DIR/early_otherwise_branch.rs:61:53: 61:54 -- drop(_10) -> [return: bb8, unwind: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:61:53: 61:54 -+ drop(_10) -> [return: bb7, unwind: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:61:53: 61:54 + StorageLive(_9); // scope 0 at $DIR/early_otherwise_branch.rs:63:25: 63:29 + _9 = ((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).0: u32); // scope 0 at $DIR/early_otherwise_branch.rs:63:25: 63:29 + StorageLive(_10); // scope 0 at $DIR/early_otherwise_branch.rs:63:37: 63:41 + _13 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:63:37: 63:41 + _10 = move (((((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>) as Some).0: (std::string::String, u32)).0: std::string::String); // scope 0 at $DIR/early_otherwise_branch.rs:63:37: 63:41 + _0 = const 2_u32; // scope 1 at $DIR/early_otherwise_branch.rs:63:53: 63:54 +- drop(_10) -> [return: bb8, unwind: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:63:53: 63:54 ++ drop(_10) -> [return: bb7, unwind: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:63:53: 63:54 } - bb8: { + bb7: { - StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:61:53: 61:54 - StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:61:53: 61:54 -- goto -> bb17; // scope 0 at $DIR/early_otherwise_branch.rs:59:5: 63:6 -+ goto -> bb14; // scope 0 at $DIR/early_otherwise_branch.rs:59:5: 63:6 + StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:63:53: 63:54 + StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:63:53: 63:54 +- goto -> bb17; // scope 0 at $DIR/early_otherwise_branch.rs:61:5: 65:6 ++ goto -> bb14; // scope 0 at $DIR/early_otherwise_branch.rs:61:5: 65:6 } - bb9 (cleanup): { -- _14 = discriminant(((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>)); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -- switchInt(move _14) -> [1_isize: bb10, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 +- _14 = discriminant(((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>)); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 +- switchInt(move _14) -> [1_isize: bb10, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 - } - - bb10 (cleanup): { + bb8 (cleanup): { -+ StorageDead(_28); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - _12 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - goto -> bb1; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + _12 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + goto -> bb1; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 } - bb11: { + bb9: { -+ StorageDead(_30); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - _11 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - _12 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - _13 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - return; // scope 0 at $DIR/early_otherwise_branch.rs:64:2: 64:2 ++ StorageDead(_30); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + _11 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + _12 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + _13 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + return; // scope 0 at $DIR/early_otherwise_branch.rs:66:2: 66:2 } - bb12: { -- _21 = discriminant(((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>)); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -- switchInt(move _21) -> [1_isize: bb13, otherwise: bb11]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 +- _21 = discriminant(((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>)); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 +- switchInt(move _21) -> [1_isize: bb13, otherwise: bb11]; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + bb10: { -+ StorageDead(_30); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ switchInt(_13) -> [false: bb11, otherwise: bb13]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 ++ switchInt(_13) -> [false: bb11, otherwise: bb13]; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 } - bb13: { -- switchInt(_13) -> [false: bb14, otherwise: bb16]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 +- switchInt(_13) -> [false: bb14, otherwise: bb16]; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 - } - - bb14: { + bb11: { - _12 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -- goto -> bb11; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ goto -> bb9; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + _12 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 +- goto -> bb11; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ goto -> bb9; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 } - bb15 (cleanup): { + bb12 (cleanup): { - _12 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 - goto -> bb1; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + _12 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 + goto -> bb1; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 } - bb16: { + bb13: { - _13 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -- drop((((((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>) as Some).0: (std::string::String, u32)).0: std::string::String)) -> [return: bb14, unwind: bb15]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ drop((((((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>) as Some).0: (std::string::String, u32)).0: std::string::String)) -> [return: bb11, unwind: bb12]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + _13 = const false; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 +- drop((((((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>) as Some).0: (std::string::String, u32)).0: std::string::String)) -> [return: bb14, unwind: bb15]; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ drop((((((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>) as Some).0: (std::string::String, u32)).0: std::string::String)) -> [return: bb11, unwind: bb12]; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 } - bb17: { + bb14: { - _23 = discriminant((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>)); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -- switchInt(move _23) -> [1_isize: bb12, otherwise: bb11]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ StorageLive(_29); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ _29 = discriminant(((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>)); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ StorageLive(_30); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ _30 = Ne(_29, _23); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ StorageDead(_29); // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 -+ switchInt(move _30) -> [false: bb10, otherwise: bb9]; // scope 0 at $DIR/early_otherwise_branch.rs:64:1: 64:2 + _23 = discriminant((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>)); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 +- switchInt(move _23) -> [1_isize: bb12, otherwise: bb11]; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ StorageLive(_29); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ _29 = discriminant(((((_3.1: std::option::Option<(u32, std::option::Option<(std::string::String, u32)>)>) as Some).0: (u32, std::option::Option<(std::string::String, u32)>)).1: std::option::Option<(std::string::String, u32)>)); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ StorageLive(_30); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ _30 = Ne(_29, _23); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ StorageDead(_29); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ switchInt(move _30) -> [false: bb17, otherwise: bb9]; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ } ++ ++ bb15: { ++ StorageDead(_26); // scope 0 at $DIR/early_otherwise_branch.rs:62:19: 62:34 ++ switchInt(_8) -> [1_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch.rs:62:19: 62:34 ++ } ++ ++ bb16 (cleanup): { ++ StorageDead(_28); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ switchInt(_15) -> [1_isize: bb8, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ } ++ ++ bb17: { ++ StorageDead(_30); // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 ++ switchInt(_23) -> [1_isize: bb10, otherwise: bb9]; // scope 0 at $DIR/early_otherwise_branch.rs:66:1: 66:2 } } diff --git a/src/test/mir-opt/early_otherwise_branch.rs b/src/test/mir-opt/early_otherwise_branch.rs index 44ff05563a02f..cc5c761e6ff89 100644 --- a/src/test/mir-opt/early_otherwise_branch.rs +++ b/src/test/mir-opt/early_otherwise_branch.rs @@ -53,7 +53,9 @@ fn opt5(x: Option, y: Option) -> u32 { } } -// This caused a miscompilation during development, so I included it here as a regression +// This caused a MIR validation during development, +// as is_cleanup was not properly assigned to new basic blocks created +// so I included it here as a regression // EMIT_MIR early_otherwise_branch.opt6.EarlyOtherwiseBranch.diff pub fn opt6(x: Option, y: Option<(u32, Option<(String, u32)>)>) -> u32 { match (x, y) { diff --git a/src/test/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff index 390ee5e862fbc..b0357f1aecd61 100644 --- a/src/test/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff @@ -47,7 +47,7 @@ + StorageLive(_15); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 + _15 = Ne(_14, _10); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 + StorageDead(_14); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 -+ switchInt(move _15) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 ++ switchInt(move _15) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 } bb1: { @@ -64,7 +64,6 @@ - } - - bb3: { -+ StorageDead(_15); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:28: 6:35 _8 = discriminant((_4.2: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:28: 6:35 - switchInt(move _8) -> [1_isize: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:28: 6:35 + switchInt(move _8) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:28: 6:35 @@ -72,7 +71,6 @@ - bb4: { + bb3: { -+ StorageDead(_17); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:15: 6:16 StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:15: 6:16 _11 = (((_4.0: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:15: 6:16 StorageLive(_12); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:24: 6:25 @@ -91,6 +89,11 @@ + bb4: { StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:9:1: 9:2 return; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:9:2: 9:2 ++ } ++ ++ bb5: { ++ StorageDead(_15); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:19: 6:26 ++ switchInt(_10) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:19: 6:26 } } diff --git a/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.before-SimplifyBranches-after-copy-prop.after.diff b/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.before-SimplifyBranches-after-copy-prop.after.diff index 0f613c4fc2e93..2cf5dd49d6a91 100644 --- a/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.before-SimplifyBranches-after-copy-prop.after.diff +++ b/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.before-SimplifyBranches-after-copy-prop.after.diff @@ -45,16 +45,22 @@ + debug other => _16; // in scope 1 at $DIR/early_otherwise_branch_68867.rs:23:24: 23:29 } scope 2 { - debug one => _17; // in scope 2 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 - debug other => _18; // in scope 2 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 +- debug one => _17; // in scope 2 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 +- debug other => _18; // in scope 2 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 ++ debug one => _20; // in scope 2 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 ++ debug other => _21; // in scope 2 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 } scope 3 { - debug one => _22; // in scope 3 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 - debug other => _23; // in scope 3 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 +- debug one => _22; // in scope 3 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 +- debug other => _23; // in scope 3 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 ++ debug one => _25; // in scope 3 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 ++ debug other => _26; // in scope 3 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 } scope 4 { - debug one => _27; // in scope 4 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 - debug other => _28; // in scope 4 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 +- debug one => _27; // in scope 4 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 +- debug other => _28; // in scope 4 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 ++ debug one => _30; // in scope 4 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 ++ debug other => _31; // in scope 4 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 } bb0: { @@ -85,7 +91,7 @@ + StorageLive(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 + _35 = Ne(_34, _11); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 + StorageDead(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 -+ switchInt(move _35) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 ++ switchInt(move _35) -> [false: bb7, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 } bb1: { @@ -106,22 +112,97 @@ return; // scope 0 at $DIR/early_otherwise_branch_68867.rs:27:14: 27:28 } -- bb3: { ++ bb2: { ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 ++ _15 = (((*(_4.0: &ViewportPercentageLength)) as Vw).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:24: 23:29 ++ _16 = (((*(_4.1: &ViewportPercentageLength)) as Vw).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:24: 23:29 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:38: 23:49 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:38: 23:41 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:38: 23:41 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:44: 23:49 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:44: 23:49 ++ ((((_0 as Ok).0: ViewportPercentageLength) as Vw).0: f32) = Add(move _15, move _16); // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:38: 23:49 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:48: 23:49 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:48: 23:49 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:35: 23:50 ++ discriminant(((_0 as Ok).0: ViewportPercentageLength)) = 0; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:35: 23:50 ++ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 ++ } ++ + bb3: { - _8 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:21: 24:30 - switchInt(move _8) -> [1_isize: bb7, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:21: 24:30 -- } -- -- bb4: { ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 ++ _20 = (((*(_4.0: &ViewportPercentageLength)) as Vh).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 ++ _21 = (((*(_4.1: &ViewportPercentageLength)) as Vh).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 ++ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:49 ++ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:41 ++ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:41 ++ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:44: 24:49 ++ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:44: 24:49 ++ ((((_0 as Ok).0: ViewportPercentageLength) as Vh).0: f32) = Add(move _20, move _21); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:49 ++ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:48: 24:49 ++ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:48: 24:49 ++ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:35: 24:50 ++ discriminant(((_0 as Ok).0: ViewportPercentageLength)) = 1; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:35: 24:50 ++ nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 + } + + bb4: { - _9 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:23: 25:34 - switchInt(move _9) -> [2_isize: bb8, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:23: 25:34 -- } -- -- bb5: { ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 ++ _25 = (((*(_4.0: &ViewportPercentageLength)) as Vmin).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 ++ _26 = (((*(_4.1: &ViewportPercentageLength)) as Vmin).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 ++ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:55 ++ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:47 ++ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:47 ++ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:50: 25:55 ++ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:50: 25:55 ++ ((((_0 as Ok).0: ViewportPercentageLength) as Vmin).0: f32) = Add(move _25, move _26); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:55 ++ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:54: 25:55 ++ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:54: 25:55 ++ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:39: 25:56 ++ discriminant(((_0 as Ok).0: ViewportPercentageLength)) = 2; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:39: 25:56 ++ nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 + } + + bb5: { - _10 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:23: 26:34 - switchInt(move _10) -> [3_isize: bb9, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:23: 26:34 -- } -- -- bb6: { ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 ++ _30 = (((*(_4.0: &ViewportPercentageLength)) as Vmax).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 ++ _31 = (((*(_4.1: &ViewportPercentageLength)) as Vmax).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 ++ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:55 ++ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:47 ++ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:47 ++ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:50: 26:55 ++ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:50: 26:55 ++ ((((_0 as Ok).0: ViewportPercentageLength) as Vmax).0: f32) = Add(move _30, move _31); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:55 ++ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:54: 26:55 ++ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:54: 26:55 ++ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:39: 26:56 ++ discriminant(((_0 as Ok).0: ViewportPercentageLength)) = 3; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:39: 26:56 ++ nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 + } + + bb6: { - StorageLive(_12); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 - _12 = (((*(_4.0: &ViewportPercentageLength)) as Vw).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 - StorageLive(_13); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:24: 23:29 @@ -140,9 +221,14 @@ - StorageDead(_13); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 - StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 - goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 -- } -- -- bb7: { ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:5: 28:7 ++ discriminant(_0) = 0; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:5: 28:7 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:28:6: 28:7 ++ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:29:1: 29:2 ++ return; // scope 0 at $DIR/early_otherwise_branch_68867.rs:29:2: 29:2 + } + + bb7: { - StorageLive(_17); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 - _17 = (((*(_4.0: &ViewportPercentageLength)) as Vh).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 - StorageLive(_18); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 @@ -207,32 +293,12 @@ - - bb10: { - ((_0 as Ok).0: ViewportPercentageLength) = move _3; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:5: 28:7 -+ bb2: { -+ StorageDead(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 -+ _15 = (((*(_4.0: &ViewportPercentageLength)) as Vw).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:24: 23:29 -+ _16 = (((*(_4.1: &ViewportPercentageLength)) as Vw).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:24: 23:29 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:38: 23:49 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:38: 23:41 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:38: 23:41 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:44: 23:49 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:44: 23:49 -+ ((((_0 as Ok).0: ViewportPercentageLength) as Vw).0: f32) = Add(move _15, move _16); // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:38: 23:49 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:48: 23:49 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:48: 23:49 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:35: 23:50 -+ discriminant(((_0 as Ok).0: ViewportPercentageLength)) = 0; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:35: 23:50 -+ nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:5: 28:7 - discriminant(_0) = 0; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:5: 28:7 +- discriminant(_0) = 0; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:5: 28:7 - StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch_68867.rs:28:6: 28:7 - StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch_68867.rs:29:1: 29:2 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:28:6: 28:7 -+ nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:29:1: 29:2 - return; // scope 0 at $DIR/early_otherwise_branch_68867.rs:29:2: 29:2 +- return; // scope 0 at $DIR/early_otherwise_branch_68867.rs:29:2: 29:2 ++ StorageDead(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:21: 23:30 ++ switchInt(_11) -> [0_isize: bb2, 1_isize: bb3, 2_isize: bb4, 3_isize: bb5, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:21: 23:30 } } diff --git a/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff index e92344c57c26f..a80bf2ac0179c 100644 --- a/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff @@ -73,7 +73,7 @@ + StorageLive(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 + _35 = Ne(_34, _11); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 + StorageDead(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 -+ switchInt(move _35) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 ++ switchInt(move _35) -> [false: bb7, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:11: 23:18 } bb1: { @@ -109,7 +109,6 @@ - - bb6: { + bb2: { -+ StorageDead(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 StorageLive(_12); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 _12 = (((*(_4.0: &ViewportPercentageLength)) as Vw).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 StorageLive(_13); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:24: 23:29 @@ -128,77 +127,90 @@ StorageDead(_13); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 - goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 -- } -- ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 + } + - bb7: { -- StorageLive(_17); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 -- _17 = (((*(_4.0: &ViewportPercentageLength)) as Vh).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 -- StorageLive(_18); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 -- _18 = (((*(_4.1: &ViewportPercentageLength)) as Vh).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 -- StorageLive(_19); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:49 -- StorageLive(_20); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:41 -- _20 = _17; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:41 -- StorageLive(_21); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:44: 24:49 -- _21 = _18; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:44: 24:49 -- _19 = Add(move _20, move _21); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:49 -- StorageDead(_21); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:48: 24:49 -- StorageDead(_20); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:48: 24:49 -- ((_3 as Vh).0: f32) = move _19; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:35: 24:50 -- discriminant(_3) = 1; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:35: 24:50 -- StorageDead(_19); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 -- StorageDead(_18); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 -- StorageDead(_17); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 ++ bb3: { + StorageLive(_17); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 + _17 = (((*(_4.0: &ViewportPercentageLength)) as Vh).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:14: 24:17 + StorageLive(_18); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 + _18 = (((*(_4.1: &ViewportPercentageLength)) as Vh).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:24: 24:29 + StorageLive(_19); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:49 + StorageLive(_20); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:41 + _20 = _17; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:41 + StorageLive(_21); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:44: 24:49 + _21 = _18; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:44: 24:49 + _19 = Add(move _20, move _21); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:38: 24:49 + StorageDead(_21); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:48: 24:49 + StorageDead(_20); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:48: 24:49 + ((_3 as Vh).0: f32) = move _19; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:35: 24:50 + discriminant(_3) = 1; // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:35: 24:50 + StorageDead(_19); // scope 2 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 + StorageDead(_18); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 + StorageDead(_17); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:49: 24:50 - goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 -- } -- ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 + } + - bb8: { -- StorageLive(_22); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 -- _22 = (((*(_4.0: &ViewportPercentageLength)) as Vmin).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 -- StorageLive(_23); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 -- _23 = (((*(_4.1: &ViewportPercentageLength)) as Vmin).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 -- StorageLive(_24); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:55 -- StorageLive(_25); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:47 -- _25 = _22; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:47 -- StorageLive(_26); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:50: 25:55 -- _26 = _23; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:50: 25:55 -- _24 = Add(move _25, move _26); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:55 -- StorageDead(_26); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:54: 25:55 -- StorageDead(_25); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:54: 25:55 -- ((_3 as Vmin).0: f32) = move _24; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:39: 25:56 -- discriminant(_3) = 2; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:39: 25:56 -- StorageDead(_24); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 -- StorageDead(_23); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 -- StorageDead(_22); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 ++ bb4: { + StorageLive(_22); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 + _22 = (((*(_4.0: &ViewportPercentageLength)) as Vmin).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 + StorageLive(_23); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 + _23 = (((*(_4.1: &ViewportPercentageLength)) as Vmin).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 + StorageLive(_24); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:55 + StorageLive(_25); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:47 + _25 = _22; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:47 + StorageLive(_26); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:50: 25:55 + _26 = _23; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:50: 25:55 + _24 = Add(move _25, move _26); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:44: 25:55 + StorageDead(_26); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:54: 25:55 + StorageDead(_25); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:54: 25:55 + ((_3 as Vmin).0: f32) = move _24; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:39: 25:56 + discriminant(_3) = 2; // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:39: 25:56 + StorageDead(_24); // scope 3 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 + StorageDead(_23); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 + StorageDead(_22); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 - goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 -- } -- ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 + } + - bb9: { -- StorageLive(_27); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 -- _27 = (((*(_4.0: &ViewportPercentageLength)) as Vmax).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 -- StorageLive(_28); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 -- _28 = (((*(_4.1: &ViewportPercentageLength)) as Vmax).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 -- StorageLive(_29); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:55 -- StorageLive(_30); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:47 -- _30 = _27; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:47 -- StorageLive(_31); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:50: 26:55 -- _31 = _28; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:50: 26:55 -- _29 = Add(move _30, move _31); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:55 -- StorageDead(_31); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:54: 26:55 -- StorageDead(_30); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:54: 26:55 -- ((_3 as Vmax).0: f32) = move _29; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:39: 26:56 -- discriminant(_3) = 3; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:39: 26:56 -- StorageDead(_29); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 -- StorageDead(_28); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 -- StorageDead(_27); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 ++ bb5: { + StorageLive(_27); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 + _27 = (((*(_4.0: &ViewportPercentageLength)) as Vmax).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:16: 26:19 + StorageLive(_28); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 + _28 = (((*(_4.1: &ViewportPercentageLength)) as Vmax).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:28: 26:33 + StorageLive(_29); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:55 + StorageLive(_30); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:47 + _30 = _27; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:47 + StorageLive(_31); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:50: 26:55 + _31 = _28; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:50: 26:55 + _29 = Add(move _30, move _31); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:44: 26:55 + StorageDead(_31); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:54: 26:55 + StorageDead(_30); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:54: 26:55 + ((_3 as Vmax).0: f32) = move _29; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:39: 26:56 + discriminant(_3) = 3; // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:39: 26:56 + StorageDead(_29); // scope 4 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 + StorageDead(_28); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 + StorageDead(_27); // scope 0 at $DIR/early_otherwise_branch_68867.rs:26:55: 26:56 - goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 -- } -- ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:8: 28:6 + } + - bb10: { ++ bb6: { ((_0 as Ok).0: ViewportPercentageLength) = move _3; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:5: 28:7 discriminant(_0) = 0; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:5: 28:7 StorageDead(_3); // scope 0 at $DIR/early_otherwise_branch_68867.rs:28:6: 28:7 StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch_68867.rs:29:1: 29:2 return; // scope 0 at $DIR/early_otherwise_branch_68867.rs:29:2: 29:2 ++ } ++ ++ bb7: { ++ StorageDead(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:21: 23:30 ++ switchInt(_11) -> [0_isize: bb2, 1_isize: bb3, 2_isize: bb4, 3_isize: bb5, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:21: 23:30 } }