diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 328a4b23c1751..a4ef0469fa886 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -193,7 +193,6 @@ declare_passes! { AfterConstProp, Final }; - mod simplify_comparison_integral : SimplifyComparisonIntegral; mod single_use_consts : SingleUseConsts; mod sroa : ScalarReplacementOfAggregates; mod strip_debuginfo : StripDebugInfo; @@ -749,7 +748,6 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<' &o1(simplify_branches::SimplifyConstCondition::AfterConstProp), &jump_threading::JumpThreading, &early_otherwise_branch::EarlyOtherwiseBranch, - &simplify_comparison_integral::SimplifyComparisonIntegral, &o1(simplify_branches::SimplifyConstCondition::Final), &o1(remove_noop_landing_pads::RemoveNoopLandingPads), &o1(simplify::SimplifyCfg::Final), diff --git a/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs b/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs deleted file mode 100644 index 58b5e45672a2f..0000000000000 --- a/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs +++ /dev/null @@ -1,256 +0,0 @@ -use std::iter; - -use rustc_middle::bug; -use rustc_middle::mir::interpret::Scalar; -use rustc_middle::mir::{ - BasicBlock, BinOp, Body, Operand, Place, Rvalue, Statement, StatementKind, SwitchTargets, - TerminatorKind, -}; -use rustc_middle::ty::{Ty, TyCtxt}; -use tracing::trace; - -use crate::ssa::SsaLocals; - -/// Pass to convert `if` conditions on integrals into switches on the integral. -/// For an example, it turns something like -/// -/// ```ignore (MIR) -/// _3 = Eq(move _4, const 43i32); -/// StorageDead(_4); -/// switchInt(_3) -> [false: bb2, otherwise: bb3]; -/// ``` -/// -/// into: -/// -/// ```ignore (MIR) -/// switchInt(_4) -> [43i32: bb3, otherwise: bb2]; -/// ``` -pub(super) struct SimplifyComparisonIntegral; - -impl<'tcx> crate::MirPass<'tcx> for SimplifyComparisonIntegral { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() > 1 - } - - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - trace!("Running SimplifyComparisonIntegral on {:?}", body.source); - - let typing_env = body.typing_env(tcx); - let ssa = SsaLocals::new(tcx, body, typing_env); - let helper = OptimizationFinder { body }; - let opts = helper.find_optimizations(&ssa); - let mut storage_deads_to_insert = vec![]; - let mut storage_deads_to_remove: Vec<(usize, BasicBlock)> = vec![]; - for opt in opts { - trace!("SUCCESS: Applying {:?}", opt); - // replace terminator with a switchInt that switches on the integer directly - let bbs = &mut body.basic_blocks_mut(); - let bb = &mut bbs[opt.bb_idx]; - let new_value = match opt.branch_value_scalar { - Scalar::Int(int) => { - let layout = tcx - .layout_of(typing_env.as_query_input(opt.branch_value_ty)) - .expect("if we have an evaluated constant we must know the layout"); - int.to_bits(layout.size) - } - Scalar::Ptr(..) => continue, - }; - const FALSE: u128 = 0; - - let mut new_targets = opt.targets; - let first_value = new_targets.iter().next().unwrap().0; - let first_is_false_target = first_value == FALSE; - match opt.op { - BinOp::Eq => { - // if the assignment was Eq we want the true case to be first - if first_is_false_target { - new_targets.all_targets_mut().swap(0, 1); - } - } - BinOp::Ne => { - // if the assignment was Ne we want the false case to be first - if !first_is_false_target { - new_targets.all_targets_mut().swap(0, 1); - } - } - _ => unreachable!(), - } - - // delete comparison statement if it the value being switched on was moved, which means - // it can not be used later on - if opt.can_remove_bin_op_stmt { - bb.statements[opt.bin_op_stmt_idx].make_nop(true); - } else { - // if the integer being compared to a const integral is being moved into the - // comparison, e.g `_2 = Eq(move _3, const 'x');` - // we want to avoid making a double move later on in the switchInt on _3. - // So to avoid `switchInt(move _3) -> ['x': bb2, otherwise: bb1];`, - // we convert the move in the comparison statement to a copy. - - // unwrap is safe as we know this statement is an assign - let (_, rhs) = bb.statements[opt.bin_op_stmt_idx].kind.as_assign_mut().unwrap(); - - use Operand::*; - match rhs { - Rvalue::BinaryOp(_, box (left @ Move(_), Constant(_))) => { - *left = Copy(opt.to_switch_on); - } - Rvalue::BinaryOp(_, box (Constant(_), right @ Move(_))) => { - *right = Copy(opt.to_switch_on); - } - _ => (), - } - } - - let terminator = bb.terminator(); - - // remove StorageDead (if it exists) being used in the assign of the comparison - for (stmt_idx, stmt) in bb.statements.iter().enumerate() { - if !matches!( - stmt.kind, - StatementKind::StorageDead(local) if local == opt.to_switch_on.local - ) { - continue; - } - storage_deads_to_remove.push((stmt_idx, opt.bb_idx)); - // if we have StorageDeads to remove then make sure to insert them at the top of - // each target - for bb_idx in new_targets.all_targets() { - storage_deads_to_insert.push(( - *bb_idx, - Statement::new( - terminator.source_info, - StatementKind::StorageDead(opt.to_switch_on.local), - ), - )); - } - } - - let [bb_cond, bb_otherwise] = match new_targets.all_targets() { - [a, b] => [*a, *b], - e => bug!("expected 2 switch targets, got: {:?}", e), - }; - - let targets = SwitchTargets::new(iter::once((new_value, bb_cond)), bb_otherwise); - - let terminator = bb.terminator_mut(); - terminator.kind = - TerminatorKind::SwitchInt { discr: Operand::Copy(opt.to_switch_on), targets }; - } - - for (idx, bb_idx) in storage_deads_to_remove { - body.basic_blocks_mut()[bb_idx].statements[idx].make_nop(true); - } - - for (idx, stmt) in storage_deads_to_insert { - body.basic_blocks_mut()[idx].statements.insert(0, stmt); - } - } - - fn is_required(&self) -> bool { - false - } -} - -struct OptimizationFinder<'a, 'tcx> { - body: &'a Body<'tcx>, -} - -impl<'tcx> OptimizationFinder<'_, 'tcx> { - fn find_optimizations(&self, ssa: &SsaLocals) -> Vec> { - self.body - .basic_blocks - .iter_enumerated() - .filter_map(|(bb_idx, bb)| { - // find switch - let (discr, targets) = bb.terminator().kind.as_switch()?; - let place_switched_on = discr.place()?; - // Make sure that the place is not modified. - if !ssa.is_ssa(place_switched_on.local) || !place_switched_on.is_stable_offset() { - return None; - } - - // find the statement that assigns the place being switched on - bb.statements.iter().enumerate().rev().find_map(|(stmt_idx, stmt)| { - match &stmt.kind { - rustc_middle::mir::StatementKind::Assign(box (lhs, rhs)) - if *lhs == place_switched_on => - { - match rhs { - Rvalue::BinaryOp( - op @ (BinOp::Eq | BinOp::Ne), - box (left, right), - ) => { - let (branch_value_scalar, branch_value_ty, to_switch_on) = - find_branch_value_info(left, right, ssa)?; - - Some(OptimizationInfo { - bin_op_stmt_idx: stmt_idx, - bb_idx, - can_remove_bin_op_stmt: discr.is_move(), - to_switch_on, - branch_value_scalar, - branch_value_ty, - op: *op, - targets: targets.clone(), - }) - } - _ => None, - } - } - _ => None, - } - }) - }) - .collect() - } -} - -fn find_branch_value_info<'tcx>( - left: &Operand<'tcx>, - right: &Operand<'tcx>, - ssa: &SsaLocals, -) -> Option<(Scalar, Ty<'tcx>, Place<'tcx>)> { - // check that either left or right is a constant. - // if any are, we can use the other to switch on, and the constant as a value in a switch - use Operand::*; - match (left, right) { - (Constant(branch_value), Copy(to_switch_on) | Move(to_switch_on)) - | (Copy(to_switch_on) | Move(to_switch_on), Constant(branch_value)) => { - // Make sure that the place is not modified. - if !ssa.is_ssa(to_switch_on.local) || !to_switch_on.is_stable_offset() { - return None; - } - let branch_value_ty = branch_value.const_.ty(); - // we only want to apply this optimization if we are matching on integrals (and chars), - // as it is not possible to switch on floats - if !branch_value_ty.is_integral() && !branch_value_ty.is_char() { - return None; - }; - let branch_value_scalar = branch_value.const_.try_to_scalar()?; - Some((branch_value_scalar, branch_value_ty, *to_switch_on)) - } - _ => None, - } -} - -#[derive(Debug)] -struct OptimizationInfo<'tcx> { - /// Basic block to apply the optimization - bb_idx: BasicBlock, - /// Statement index of Eq/Ne assignment that can be removed. None if the assignment can not be - /// removed - i.e the statement is used later on - bin_op_stmt_idx: usize, - /// Can remove Eq/Ne assignment - can_remove_bin_op_stmt: bool, - /// Place that needs to be switched on. This place is of type integral - to_switch_on: Place<'tcx>, - /// Constant to use in switch target value - branch_value_scalar: Scalar, - /// Type of the constant value - branch_value_ty: Ty<'tcx>, - /// Either Eq or Ne - op: BinOp, - /// Current targets used in the switch - targets: SwitchTargets, -} diff --git a/tests/codegen-llvm/hint/likely.rs b/tests/codegen-llvm/hint/likely.rs index 75f9e7aae367d..70d0d20a572d5 100644 --- a/tests/codegen-llvm/hint/likely.rs +++ b/tests/codegen-llvm/hint/likely.rs @@ -70,7 +70,7 @@ pub fn test4(x: u64) { } // CHECK-LABEL: @test4( - // CHECK: br i1 %0, label %bb3, label %bb2, !prof ![[NUM2:[0-9]+]] + // CHECK: br i1 {{.*}}, label %bb3, label %bb2, !prof ![[NUM2:[0-9]+]] // CHECK: bb3: // CHECK: path_a // CHECK: bb2: diff --git a/tests/codegen-llvm/hint/unlikely.rs b/tests/codegen-llvm/hint/unlikely.rs index 248b1e2537e96..05923e8728387 100644 --- a/tests/codegen-llvm/hint/unlikely.rs +++ b/tests/codegen-llvm/hint/unlikely.rs @@ -70,7 +70,7 @@ pub fn test4(x: u64) { } // CHECK-LABEL: @test4( - // CHECK: br i1 %0, label %bb4, label %bb2, !prof ![[NUM2:[0-9]+]] + // CHECK: br i1 {{.*}}, label %bb4, label %bb2, !prof ![[NUM2:[0-9]+]] // CHECK: bb4: // CHECK: path_a // CHECK: bb2: diff --git a/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-abort.diff b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-abort.diff index 2b77aa380a0fe..519be6e1e93e1 100644 --- a/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-abort.diff @@ -29,10 +29,11 @@ debug precision => _8; let _8: usize; scope 5 (inlined Formatter::<'_>::precision) { - let mut _22: u32; + let mut _22: bool; let mut _23: u32; - let mut _24: usize; - let mut _25: u16; + let mut _24: u32; + let mut _25: usize; + let mut _26: u16; } } } @@ -71,10 +72,12 @@ StorageLive(_6); StorageLive(_22); StorageLive(_23); - _23 = copy (((*_1).0: std::fmt::FormattingOptions).0: u32); - _22 = BitAnd(move _23, const core::fmt::flags::PRECISION_FLAG); - StorageDead(_23); - switchInt(copy _22) -> [0: bb10, otherwise: bb11]; + StorageLive(_24); + _24 = copy (((*_1).0: std::fmt::FormattingOptions).0: u32); + _23 = BitAnd(move _24, const core::fmt::flags::PRECISION_FLAG); + StorageDead(_24); + _22 = Eq(move _23, const 0_u32); + switchInt(move _22) -> [0: bb10, otherwise: bb9]; } bb4: { @@ -142,26 +145,27 @@ } bb9: { - _7 = discriminant(_6); - switchInt(move _7) -> [1: bb4, 0: bb6, otherwise: bb12]; + StorageDead(_23); + _6 = const Option::::None; + goto -> bb11; } bb10: { - StorageDead(_22); - _6 = const Option::::None; - goto -> bb9; + StorageDead(_23); + StorageLive(_25); + StorageLive(_26); + _26 = copy (((*_1).0: std::fmt::FormattingOptions).2: u16); + _25 = move _26 as usize (IntToInt); + StorageDead(_26); + _6 = Option::::Some(move _25); + StorageDead(_25); + goto -> bb11; } bb11: { StorageDead(_22); - StorageLive(_24); - StorageLive(_25); - _25 = copy (((*_1).0: std::fmt::FormattingOptions).2: u16); - _24 = move _25 as usize (IntToInt); - StorageDead(_25); - _6 = Option::::Some(move _24); - StorageDead(_24); - goto -> bb9; + _7 = discriminant(_6); + switchInt(move _7) -> [1: bb4, 0: bb6, otherwise: bb12]; } bb12: { diff --git a/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-unwind.diff b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-unwind.diff index ba6d2f3e155c8..3d97e19218dd7 100644 --- a/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-unwind.diff +++ b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-unwind.diff @@ -29,10 +29,11 @@ debug precision => _8; let _8: usize; scope 5 (inlined Formatter::<'_>::precision) { - let mut _22: u32; + let mut _22: bool; let mut _23: u32; - let mut _24: usize; - let mut _25: u16; + let mut _24: u32; + let mut _25: usize; + let mut _26: u16; } } } @@ -71,10 +72,12 @@ StorageLive(_6); StorageLive(_22); StorageLive(_23); - _23 = copy (((*_1).0: std::fmt::FormattingOptions).0: u32); - _22 = BitAnd(move _23, const core::fmt::flags::PRECISION_FLAG); - StorageDead(_23); - switchInt(copy _22) -> [0: bb10, otherwise: bb11]; + StorageLive(_24); + _24 = copy (((*_1).0: std::fmt::FormattingOptions).0: u32); + _23 = BitAnd(move _24, const core::fmt::flags::PRECISION_FLAG); + StorageDead(_24); + _22 = Eq(move _23, const 0_u32); + switchInt(move _22) -> [0: bb10, otherwise: bb9]; } bb4: { @@ -142,26 +145,27 @@ } bb9: { - _7 = discriminant(_6); - switchInt(move _7) -> [1: bb4, 0: bb6, otherwise: bb12]; + StorageDead(_23); + _6 = const Option::::None; + goto -> bb11; } bb10: { - StorageDead(_22); - _6 = const Option::::None; - goto -> bb9; + StorageDead(_23); + StorageLive(_25); + StorageLive(_26); + _26 = copy (((*_1).0: std::fmt::FormattingOptions).2: u16); + _25 = move _26 as usize (IntToInt); + StorageDead(_26); + _6 = Option::::Some(move _25); + StorageDead(_25); + goto -> bb11; } bb11: { StorageDead(_22); - StorageLive(_24); - StorageLive(_25); - _25 = copy (((*_1).0: std::fmt::FormattingOptions).2: u16); - _24 = move _25 as usize (IntToInt); - StorageDead(_25); - _6 = Option::::Some(move _24); - StorageDead(_24); - goto -> bb9; + _7 = discriminant(_6); + switchInt(move _7) -> [1: bb4, 0: bb6, otherwise: bb12]; } bb12: { diff --git a/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-abort.diff b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-abort.diff index bf6d9d864d578..c6477f0e055c7 100644 --- a/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-abort.diff @@ -29,10 +29,11 @@ debug precision => _8; let _8: usize; scope 5 (inlined Formatter::<'_>::precision) { - let mut _22: u32; + let mut _22: bool; let mut _23: u32; - let mut _24: usize; - let mut _25: u16; + let mut _24: u32; + let mut _25: usize; + let mut _26: u16; } } } @@ -71,10 +72,12 @@ StorageLive(_6); StorageLive(_22); StorageLive(_23); - _23 = copy (((*_1).0: std::fmt::FormattingOptions).0: u32); - _22 = BitAnd(move _23, const core::fmt::flags::PRECISION_FLAG); - StorageDead(_23); - switchInt(copy _22) -> [0: bb10, otherwise: bb11]; + StorageLive(_24); + _24 = copy (((*_1).0: std::fmt::FormattingOptions).0: u32); + _23 = BitAnd(move _24, const core::fmt::flags::PRECISION_FLAG); + StorageDead(_24); + _22 = Eq(move _23, const 0_u32); + switchInt(move _22) -> [0: bb10, otherwise: bb9]; } bb4: { @@ -142,26 +145,27 @@ } bb9: { - _7 = discriminant(_6); - switchInt(move _7) -> [1: bb4, 0: bb6, otherwise: bb12]; + StorageDead(_23); + _6 = const Option::::None; + goto -> bb11; } bb10: { - StorageDead(_22); - _6 = const Option::::None; - goto -> bb9; + StorageDead(_23); + StorageLive(_25); + StorageLive(_26); + _26 = copy (((*_1).0: std::fmt::FormattingOptions).2: u16); + _25 = move _26 as usize (IntToInt); + StorageDead(_26); + _6 = Option::::Some(move _25); + StorageDead(_25); + goto -> bb11; } bb11: { StorageDead(_22); - StorageLive(_24); - StorageLive(_25); - _25 = copy (((*_1).0: std::fmt::FormattingOptions).2: u16); - _24 = move _25 as usize (IntToInt); - StorageDead(_25); - _6 = Option::::Some(move _24); - StorageDead(_24); - goto -> bb9; + _7 = discriminant(_6); + switchInt(move _7) -> [1: bb4, 0: bb6, otherwise: bb12]; } bb12: { diff --git a/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-unwind.diff b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-unwind.diff index 01c87fd5317a9..d491e2a5e4c73 100644 --- a/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-unwind.diff +++ b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-unwind.diff @@ -29,10 +29,11 @@ debug precision => _8; let _8: usize; scope 5 (inlined Formatter::<'_>::precision) { - let mut _22: u32; + let mut _22: bool; let mut _23: u32; - let mut _24: usize; - let mut _25: u16; + let mut _24: u32; + let mut _25: usize; + let mut _26: u16; } } } @@ -71,10 +72,12 @@ StorageLive(_6); StorageLive(_22); StorageLive(_23); - _23 = copy (((*_1).0: std::fmt::FormattingOptions).0: u32); - _22 = BitAnd(move _23, const core::fmt::flags::PRECISION_FLAG); - StorageDead(_23); - switchInt(copy _22) -> [0: bb10, otherwise: bb11]; + StorageLive(_24); + _24 = copy (((*_1).0: std::fmt::FormattingOptions).0: u32); + _23 = BitAnd(move _24, const core::fmt::flags::PRECISION_FLAG); + StorageDead(_24); + _22 = Eq(move _23, const 0_u32); + switchInt(move _22) -> [0: bb10, otherwise: bb9]; } bb4: { @@ -142,26 +145,27 @@ } bb9: { - _7 = discriminant(_6); - switchInt(move _7) -> [1: bb4, 0: bb6, otherwise: bb12]; + StorageDead(_23); + _6 = const Option::::None; + goto -> bb11; } bb10: { - StorageDead(_22); - _6 = const Option::::None; - goto -> bb9; + StorageDead(_23); + StorageLive(_25); + StorageLive(_26); + _26 = copy (((*_1).0: std::fmt::FormattingOptions).2: u16); + _25 = move _26 as usize (IntToInt); + StorageDead(_26); + _6 = Option::::Some(move _25); + StorageDead(_25); + goto -> bb11; } bb11: { StorageDead(_22); - StorageLive(_24); - StorageLive(_25); - _25 = copy (((*_1).0: std::fmt::FormattingOptions).2: u16); - _24 = move _25 as usize (IntToInt); - StorageDead(_25); - _6 = Option::::Some(move _24); - StorageDead(_24); - goto -> bb9; + _7 = discriminant(_6); + switchInt(move _7) -> [1: bb4, 0: bb6, otherwise: bb12]; } bb12: { diff --git a/tests/mir-opt/if_condition_int.dont_opt_bool.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.dont_opt_bool.SimplifyComparisonIntegral.diff deleted file mode 100644 index f2d527326592e..0000000000000 --- a/tests/mir-opt/if_condition_int.dont_opt_bool.SimplifyComparisonIntegral.diff +++ /dev/null @@ -1,30 +0,0 @@ -- // MIR for `dont_opt_bool` before SimplifyComparisonIntegral -+ // MIR for `dont_opt_bool` after SimplifyComparisonIntegral - - fn dont_opt_bool(_1: bool) -> u32 { - debug x => _1; - let mut _0: u32; - let mut _2: bool; - - bb0: { - StorageLive(_2); - _2 = copy _1; - switchInt(copy _1) -> [0: bb2, otherwise: bb1]; - } - - bb1: { - _0 = const 0_u32; - goto -> bb3; - } - - bb2: { - _0 = const 1_u32; - goto -> bb3; - } - - bb3: { - StorageDead(_2); - return; - } - } - diff --git a/tests/mir-opt/if_condition_int.dont_opt_floats.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.dont_opt_floats.SimplifyComparisonIntegral.diff deleted file mode 100644 index c72a58a145f4e..0000000000000 --- a/tests/mir-opt/if_condition_int.dont_opt_floats.SimplifyComparisonIntegral.diff +++ /dev/null @@ -1,35 +0,0 @@ -- // MIR for `dont_opt_floats` before SimplifyComparisonIntegral -+ // MIR for `dont_opt_floats` after SimplifyComparisonIntegral - - fn dont_opt_floats(_1: f32) -> i32 { - debug a => _1; - let mut _0: i32; - let mut _2: bool; - let mut _3: f32; - - bb0: { - StorageLive(_2); - StorageLive(_3); - _3 = copy _1; - _2 = Eq(copy _1, const -42f32); - switchInt(move _2) -> [0: bb2, otherwise: bb1]; - } - - bb1: { - StorageDead(_3); - _0 = const 0_i32; - goto -> bb3; - } - - bb2: { - StorageDead(_3); - _0 = const 1_i32; - goto -> bb3; - } - - bb3: { - StorageDead(_2); - return; - } - } - diff --git a/tests/mir-opt/if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff deleted file mode 100644 index f5f2e0317ead1..0000000000000 --- a/tests/mir-opt/if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff +++ /dev/null @@ -1,54 +0,0 @@ -- // MIR for `dont_remove_comparison` before SimplifyComparisonIntegral -+ // MIR for `dont_remove_comparison` after SimplifyComparisonIntegral - - fn dont_remove_comparison(_1: i8) -> i32 { - debug a => _1; - let mut _0: i32; - let _2: bool; - let mut _3: i8; - let mut _4: i32; - let mut _5: bool; - let mut _6: i32; - let mut _7: bool; - scope 1 { - debug b => _2; - } - - bb0: { - nop; - StorageLive(_3); - _3 = copy _1; - _2 = Eq(copy _1, const 17_i8); - StorageDead(_3); -- switchInt(copy _2) -> [0: bb2, otherwise: bb1]; -+ switchInt(copy _1) -> [17: bb1, otherwise: bb2]; - } - - bb1: { - StorageLive(_6); - StorageLive(_7); - _7 = copy _2; - _6 = copy _2 as i32 (IntToInt); - StorageDead(_7); - _0 = Add(const 100_i32, move _6); - StorageDead(_6); - goto -> bb3; - } - - bb2: { - StorageLive(_4); - StorageLive(_5); - _5 = copy _2; - _4 = copy _2 as i32 (IntToInt); - StorageDead(_5); - _0 = Add(const 10_i32, move _4); - StorageDead(_4); - goto -> bb3; - } - - bb3: { - nop; - return; - } - } - diff --git a/tests/mir-opt/if_condition_int.on_non_ssa_cmp.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.on_non_ssa_cmp.SimplifyComparisonIntegral.diff deleted file mode 100644 index ce5a2bf172a97..0000000000000 --- a/tests/mir-opt/if_condition_int.on_non_ssa_cmp.SimplifyComparisonIntegral.diff +++ /dev/null @@ -1,24 +0,0 @@ -- // MIR for `on_non_ssa_cmp` before SimplifyComparisonIntegral -+ // MIR for `on_non_ssa_cmp` after SimplifyComparisonIntegral - - fn on_non_ssa_cmp(_1: u64) -> i32 { - let mut _0: i32; - let mut _2: bool; - - bb0: { - _2 = Eq(copy _1, const 42_u64); - _1 = const 43_u64; - switchInt(copy _2) -> [1: bb1, otherwise: bb2]; - } - - bb1: { - _0 = const 0_i32; - return; - } - - bb2: { - _0 = const 1_i32; - return; - } - } - diff --git a/tests/mir-opt/if_condition_int.on_non_ssa_place.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.on_non_ssa_place.SimplifyComparisonIntegral.diff deleted file mode 100644 index 7ad0a87f1cdd9..0000000000000 --- a/tests/mir-opt/if_condition_int.on_non_ssa_place.SimplifyComparisonIntegral.diff +++ /dev/null @@ -1,24 +0,0 @@ -- // MIR for `on_non_ssa_place` before SimplifyComparisonIntegral -+ // MIR for `on_non_ssa_place` after SimplifyComparisonIntegral - - fn on_non_ssa_place(_1: [u64; 10], _2: usize) -> i32 { - let mut _0: i32; - let mut _3: bool; - - bb0: { - _3 = Eq(copy _1[_2], const 42_u64); - _2 = const 10_usize; - switchInt(copy _3) -> [1: bb1, otherwise: bb2]; - } - - bb1: { - _0 = const 0_i32; - return; - } - - bb2: { - _0 = const 1_i32; - return; - } - } - diff --git a/tests/mir-opt/if_condition_int.on_non_ssa_switch.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.on_non_ssa_switch.SimplifyComparisonIntegral.diff deleted file mode 100644 index e2dc97f76b5c8..0000000000000 --- a/tests/mir-opt/if_condition_int.on_non_ssa_switch.SimplifyComparisonIntegral.diff +++ /dev/null @@ -1,24 +0,0 @@ -- // MIR for `on_non_ssa_switch` before SimplifyComparisonIntegral -+ // MIR for `on_non_ssa_switch` after SimplifyComparisonIntegral - - fn on_non_ssa_switch(_1: u64) -> i32 { - let mut _0: i32; - let mut _2: bool; - - bb0: { - _2 = Eq(copy _1, const 42_u64); - _2 = const false; - switchInt(copy _2) -> [1: bb1, otherwise: bb2]; - } - - bb1: { - _0 = const 0_i32; - return; - } - - bb2: { - _0 = const 1_i32; - return; - } - } - diff --git a/tests/mir-opt/if_condition_int.opt_char.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.opt_char.SimplifyComparisonIntegral.diff deleted file mode 100644 index 22f6443a6c0f9..0000000000000 --- a/tests/mir-opt/if_condition_int.opt_char.SimplifyComparisonIntegral.diff +++ /dev/null @@ -1,37 +0,0 @@ -- // MIR for `opt_char` before SimplifyComparisonIntegral -+ // MIR for `opt_char` after SimplifyComparisonIntegral - - fn opt_char(_1: char) -> u32 { - debug x => _1; - let mut _0: u32; - let mut _2: bool; - let mut _3: char; - - bb0: { - StorageLive(_2); - StorageLive(_3); - _3 = copy _1; -- _2 = Eq(copy _1, const 'x'); -- switchInt(move _2) -> [0: bb2, otherwise: bb1]; -+ nop; -+ switchInt(copy _1) -> [120: bb1, otherwise: bb2]; - } - - bb1: { - StorageDead(_3); - _0 = const 0_u32; - goto -> bb3; - } - - bb2: { - StorageDead(_3); - _0 = const 1_u32; - goto -> bb3; - } - - bb3: { - StorageDead(_2); - return; - } - } - diff --git a/tests/mir-opt/if_condition_int.opt_i8.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.opt_i8.SimplifyComparisonIntegral.diff deleted file mode 100644 index d5c48fd04ca60..0000000000000 --- a/tests/mir-opt/if_condition_int.opt_i8.SimplifyComparisonIntegral.diff +++ /dev/null @@ -1,37 +0,0 @@ -- // MIR for `opt_i8` before SimplifyComparisonIntegral -+ // MIR for `opt_i8` after SimplifyComparisonIntegral - - fn opt_i8(_1: i8) -> u32 { - debug x => _1; - let mut _0: u32; - let mut _2: bool; - let mut _3: i8; - - bb0: { - StorageLive(_2); - StorageLive(_3); - _3 = copy _1; -- _2 = Eq(copy _1, const 42_i8); -- switchInt(move _2) -> [0: bb2, otherwise: bb1]; -+ nop; -+ switchInt(copy _1) -> [42: bb1, otherwise: bb2]; - } - - bb1: { - StorageDead(_3); - _0 = const 0_u32; - goto -> bb3; - } - - bb2: { - StorageDead(_3); - _0 = const 1_u32; - goto -> bb3; - } - - bb3: { - StorageDead(_2); - return; - } - } - diff --git a/tests/mir-opt/if_condition_int.opt_multiple_ifs.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.opt_multiple_ifs.SimplifyComparisonIntegral.diff deleted file mode 100644 index 84d62b8136078..0000000000000 --- a/tests/mir-opt/if_condition_int.opt_multiple_ifs.SimplifyComparisonIntegral.diff +++ /dev/null @@ -1,61 +0,0 @@ -- // MIR for `opt_multiple_ifs` before SimplifyComparisonIntegral -+ // MIR for `opt_multiple_ifs` after SimplifyComparisonIntegral - - fn opt_multiple_ifs(_1: u32) -> u32 { - debug x => _1; - let mut _0: u32; - let mut _2: bool; - let mut _3: u32; - let mut _4: bool; - let mut _5: u32; - - bb0: { - StorageLive(_2); - StorageLive(_3); - _3 = copy _1; -- _2 = Eq(copy _1, const 42_u32); -- switchInt(move _2) -> [0: bb2, otherwise: bb1]; -+ nop; -+ switchInt(copy _1) -> [42: bb1, otherwise: bb2]; - } - - bb1: { - StorageDead(_3); - _0 = const 0_u32; - goto -> bb6; - } - - bb2: { - StorageDead(_3); - StorageLive(_4); - StorageLive(_5); - _5 = copy _1; -- _4 = Ne(copy _1, const 21_u32); -- switchInt(move _4) -> [0: bb4, otherwise: bb3]; -+ nop; -+ switchInt(copy _1) -> [21: bb4, otherwise: bb3]; - } - - bb3: { - StorageDead(_5); - _0 = const 1_u32; - goto -> bb5; - } - - bb4: { - StorageDead(_5); - _0 = const 2_u32; - goto -> bb5; - } - - bb5: { - StorageDead(_4); - goto -> bb6; - } - - bb6: { - StorageDead(_2); - return; - } - } - diff --git a/tests/mir-opt/if_condition_int.opt_negative.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.opt_negative.SimplifyComparisonIntegral.diff deleted file mode 100644 index a1cbaff796b35..0000000000000 --- a/tests/mir-opt/if_condition_int.opt_negative.SimplifyComparisonIntegral.diff +++ /dev/null @@ -1,37 +0,0 @@ -- // MIR for `opt_negative` before SimplifyComparisonIntegral -+ // MIR for `opt_negative` after SimplifyComparisonIntegral - - fn opt_negative(_1: i32) -> u32 { - debug x => _1; - let mut _0: u32; - let mut _2: bool; - let mut _3: i32; - - bb0: { - StorageLive(_2); - StorageLive(_3); - _3 = copy _1; -- _2 = Eq(copy _1, const -42_i32); -- switchInt(move _2) -> [0: bb2, otherwise: bb1]; -+ nop; -+ switchInt(copy _1) -> [4294967254: bb1, otherwise: bb2]; - } - - bb1: { - StorageDead(_3); - _0 = const 0_u32; - goto -> bb3; - } - - bb2: { - StorageDead(_3); - _0 = const 1_u32; - goto -> bb3; - } - - bb3: { - StorageDead(_2); - return; - } - } - diff --git a/tests/mir-opt/if_condition_int.opt_u32.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.opt_u32.SimplifyComparisonIntegral.diff deleted file mode 100644 index 8101de8cbf381..0000000000000 --- a/tests/mir-opt/if_condition_int.opt_u32.SimplifyComparisonIntegral.diff +++ /dev/null @@ -1,37 +0,0 @@ -- // MIR for `opt_u32` before SimplifyComparisonIntegral -+ // MIR for `opt_u32` after SimplifyComparisonIntegral - - fn opt_u32(_1: u32) -> u32 { - debug x => _1; - let mut _0: u32; - let mut _2: bool; - let mut _3: u32; - - bb0: { - StorageLive(_2); - StorageLive(_3); - _3 = copy _1; -- _2 = Eq(copy _1, const 42_u32); -- switchInt(move _2) -> [0: bb2, otherwise: bb1]; -+ nop; -+ switchInt(copy _1) -> [42: bb1, otherwise: bb2]; - } - - bb1: { - StorageDead(_3); - _0 = const 0_u32; - goto -> bb3; - } - - bb2: { - StorageDead(_3); - _0 = const 1_u32; - goto -> bb3; - } - - bb3: { - StorageDead(_2); - return; - } - } - diff --git a/tests/mir-opt/if_condition_int.rs b/tests/mir-opt/if_condition_int.rs deleted file mode 100644 index 5e0961da3ccea..0000000000000 --- a/tests/mir-opt/if_condition_int.rs +++ /dev/null @@ -1,228 +0,0 @@ -//@ test-mir-pass: SimplifyComparisonIntegral -// GVN simplifies FileCheck. -//@ compile-flags: -Zmir-enable-passes=+GVN - -#![feature(custom_mir, core_intrinsics)] - -extern crate core; -use core::intrinsics::mir::*; - -// EMIT_MIR if_condition_int.opt_u32.SimplifyComparisonIntegral.diff -fn opt_u32(x: u32) -> u32 { - // CHECK-LABEL: fn opt_u32( - // CHECK: switchInt(copy _1) -> [42: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]]; - // CHECK: [[BB1]]: - // CHECK: _0 = const 0_u32; - // CHECK: [[BB2]]: - // CHECK: _0 = const 1_u32; - if x == 42 { 0 } else { 1 } -} - -// EMIT_MIR if_condition_int.dont_opt_bool.SimplifyComparisonIntegral.diff -// don't opt: it is already optimal to switch on the bool -fn dont_opt_bool(x: bool) -> u32 { - // CHECK-LABEL: fn dont_opt_bool( - // CHECK: switchInt(copy _1) -> [0: [[BB2:bb.*]], otherwise: [[BB1:bb.*]]]; - // CHECK: [[BB1]]: - // CHECK: _0 = const 0_u32; - // CHECK: [[BB2]]: - // CHECK: _0 = const 1_u32; - if x { 0 } else { 1 } -} - -// EMIT_MIR if_condition_int.opt_char.SimplifyComparisonIntegral.diff -fn opt_char(x: char) -> u32 { - // CHECK-LABEL: fn opt_char( - // CHECK: switchInt(copy _1) -> [120: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]]; - // CHECK: [[BB1]]: - // CHECK: _0 = const 0_u32; - // CHECK: [[BB2]]: - // CHECK: _0 = const 1_u32; - if x == 'x' { 0 } else { 1 } -} - -// EMIT_MIR if_condition_int.opt_i8.SimplifyComparisonIntegral.diff -fn opt_i8(x: i8) -> u32 { - // CHECK-LABEL: fn opt_i8( - // CHECK: switchInt(copy _1) -> [42: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]]; - // CHECK: [[BB1]]: - // CHECK: _0 = const 0_u32; - // CHECK: [[BB2]]: - // CHECK: _0 = const 1_u32; - if x == 42 { 0 } else { 1 } -} - -// EMIT_MIR if_condition_int.opt_negative.SimplifyComparisonIntegral.diff -fn opt_negative(x: i32) -> u32 { - // CHECK-LABEL: fn opt_negative( - // CHECK: switchInt(copy _1) -> [4294967254: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]]; - // CHECK: [[BB1]]: - // CHECK: _0 = const 0_u32; - // CHECK: [[BB2]]: - // CHECK: _0 = const 1_u32; - if x == -42 { 0 } else { 1 } -} - -// EMIT_MIR if_condition_int.opt_multiple_ifs.SimplifyComparisonIntegral.diff -fn opt_multiple_ifs(x: u32) -> u32 { - // CHECK-LABEL: fn opt_multiple_ifs( - // CHECK: switchInt(copy _1) -> [42: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]]; - // CHECK: [[BB1]]: - // CHECK: _0 = const 0_u32; - // CHECK: [[BB2]]: - // CHECK: switchInt(copy _1) -> [21: [[BB4:bb.*]], otherwise: [[BB3:bb.*]]]; - // CHECK: [[BB3]]: - // CHECK: _0 = const 1_u32; - // CHECK: [[BB4]]: - // CHECK: _0 = const 2_u32; - if x == 42 { - 0 - } else if x != 21 { - 1 - } else { - 2 - } -} - -// EMIT_MIR if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff -// test that we optimize, but do not remove the b statement, as that is used later on -fn dont_remove_comparison(a: i8) -> i32 { - // CHECK-LABEL: fn dont_remove_comparison( - // CHECK: [[b:_.*]] = Eq(copy _1, const 17_i8); - // CHECK: switchInt(copy _1) -> [17: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]]; - // CHECK: [[BB1]]: - // CHECK: [[cast_1:_.*]] = copy [[b]] as i32 (IntToInt); - // CHECK: _0 = Add(const 100_i32, move [[cast_1]]); - // CHECK: [[BB2]]: - // CHECK: [[cast_2:_.*]] = copy [[b]] as i32 (IntToInt); - // CHECK: _0 = Add(const 10_i32, move [[cast_2]]); - let b = a == 17; - match b { - false => 10 + b as i32, - true => 100 + b as i32, - } -} - -// EMIT_MIR if_condition_int.dont_opt_floats.SimplifyComparisonIntegral.diff -// test that we do not optimize on floats -fn dont_opt_floats(a: f32) -> i32 { - // CHECK-LABEL: fn dont_opt_floats( - // CHECK: [[cmp:_.*]] = Eq(copy _1, const -42f32); - // CHECK: switchInt(move [[cmp]]) -> [0: [[BB2:bb.*]], otherwise: [[BB1:bb.*]]]; - // CHECK: [[BB1]]: - // CHECK: _0 = const 0_i32; - // CHECK: [[BB2]]: - // CHECK: _0 = const 1_i32; - if a == -42.0 { 0 } else { 1 } -} - -// EMIT_MIR if_condition_int.on_non_ssa_switch.SimplifyComparisonIntegral.diff -#[custom_mir(dialect = "runtime")] -pub fn on_non_ssa_switch(mut v: u64) -> i32 { - // CHECK-LABEL: fn on_non_ssa_switch( - // CHECK: [[cmp:_.*]] = Eq(copy _1, const 42_u64); - // CHECK: [[cmp]] = const false; - // CHECK: switchInt(copy [[cmp]]) -> [1: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]]; - // CHECK: [[BB1]]: - // CHECK: _0 = const 0_i32; - // CHECK: [[BB2]]: - // CHECK: _0 = const 1_i32; - mir! { - let a: bool; - { - a = v == 42; - a = false; - match a { - true => bb1, - _ => bb2, - } - - } - bb1 = { - RET = 0; - Return() - } - bb2 = { - RET = 1; - Return() - } - } -} - -// EMIT_MIR if_condition_int.on_non_ssa_cmp.SimplifyComparisonIntegral.diff -#[custom_mir(dialect = "runtime")] -pub fn on_non_ssa_cmp(mut v: u64) -> i32 { - // CHECK-LABEL: fn on_non_ssa_cmp( - // CHECK: [[cmp:_.*]] = Eq(copy _1, const 42_u64); - // CHECK: _1 = const 43_u64; - // CHECK: switchInt(copy [[cmp]]) -> [1: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]]; - // CHECK: [[BB1]]: - // CHECK: _0 = const 0_i32; - // CHECK: [[BB2]]: - // CHECK: _0 = const 1_i32; - mir! { - let a: bool; - { - a = v == 42; - v = 43; - match a { - true => bb1, - _ => bb2, - } - - } - bb1 = { - RET = 0; - Return() - } - bb2 = { - RET = 1; - Return() - } - } -} - -// EMIT_MIR if_condition_int.on_non_ssa_place.SimplifyComparisonIntegral.diff -#[custom_mir(dialect = "runtime")] -pub fn on_non_ssa_place(mut v: [u64; 10], mut i: usize) -> i32 { - // CHECK-LABEL: fn on_non_ssa_place( - // CHECK: [[cmp:_.*]] = Eq(copy _1[_2], const 42_u64); - // CHECK: _2 = const 10_usize; - // CHECK: switchInt(copy [[cmp]]) -> [1: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]]; - // CHECK: [[BB1]]: - // CHECK: _0 = const 0_i32; - // CHECK: [[BB2]]: - // CHECK: _0 = const 1_i32; - mir! { - let a: bool; - { - a = v[i] == 42; - i = 10; - match a { - true => bb1, - _ => bb2, - } - - } - bb1 = { - RET = 0; - Return() - } - bb2 = { - RET = 1; - Return() - } - } -} - -fn main() { - opt_u32(0); - opt_char('0'); - opt_i8(22); - dont_opt_bool(false); - opt_negative(0); - opt_multiple_ifs(0); - dont_remove_comparison(11); - dont_opt_floats(1.0); - on_non_ssa_switch(42); -} diff --git a/tests/mir-opt/issue_76432.rs b/tests/mir-opt/issue_76432.rs deleted file mode 100644 index 6d884063caafb..0000000000000 --- a/tests/mir-opt/issue_76432.rs +++ /dev/null @@ -1,18 +0,0 @@ -// skip-filecheck -// EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// Check that we do not insert StorageDead at each target if StorageDead was never seen - -use std::fmt::Debug; - -// EMIT_MIR issue_76432.test.SimplifyComparisonIntegral.diff -fn test(x: T) { - let v: &[T] = &[x, x, x]; - match v { - [ref v1, ref v2, ref v3] => [v1 as *const _, v2 as *const _, v3 as *const _], - _ => unreachable!(), - }; -} - -fn main() { - test(0u32); -} diff --git a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff deleted file mode 100644 index 614d9ad440d20..0000000000000 --- a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff +++ /dev/null @@ -1,49 +0,0 @@ -- // MIR for `test` before SimplifyComparisonIntegral -+ // MIR for `test` after SimplifyComparisonIntegral - - fn test(_1: T) -> () { - debug x => _1; - let mut _0: (); - let _2: &[T]; - let _3: &[T; 3]; - let _4: [T; 3]; - let mut _8: !; - scope 1 { - debug v => _2; - let _5: &T; - let _6: &T; - let _7: &T; - scope 2 { - debug v1 => _5; - debug v2 => _6; - debug v3 => _7; - } - } - - bb0: { - StorageLive(_4); - _4 = [copy _1, copy _1, copy _1]; - _3 = &_4; - _2 = copy _3 as &[T] (PointerCoercion(Unsize, Implicit)); - goto -> bb2; - } - - bb1: { - _8 = core::panicking::panic(const "internal error: entered unreachable code") -> unwind unreachable; - } - - bb2: { - // DBG: _5 = &(*_2)[0 of 3]; - // DBG: _6 = &(*_2)[1 of 3]; - // DBG: _7 = &(*_2)[2 of 3]; - StorageDead(_4); - return; - } - } - - ALLOC0 (size: 40, align: 1) { - 0x00 │ 69 6e 74 65 72 6e 61 6c 20 65 72 72 6f 72 3a 20 │ internal error: - 0x10 │ 65 6e 74 65 72 65 64 20 75 6e 72 65 61 63 68 61 │ entered unreacha - 0x20 │ 62 6c 65 20 63 6f 64 65 │ ble code - } - diff --git a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff deleted file mode 100644 index 57a88cf898412..0000000000000 --- a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff +++ /dev/null @@ -1,49 +0,0 @@ -- // MIR for `test` before SimplifyComparisonIntegral -+ // MIR for `test` after SimplifyComparisonIntegral - - fn test(_1: T) -> () { - debug x => _1; - let mut _0: (); - let _2: &[T]; - let _3: &[T; 3]; - let _4: [T; 3]; - let mut _8: !; - scope 1 { - debug v => _2; - let _5: &T; - let _6: &T; - let _7: &T; - scope 2 { - debug v1 => _5; - debug v2 => _6; - debug v3 => _7; - } - } - - bb0: { - StorageLive(_4); - _4 = [copy _1, copy _1, copy _1]; - _3 = &_4; - _2 = copy _3 as &[T] (PointerCoercion(Unsize, Implicit)); - goto -> bb2; - } - - bb1: { - _8 = core::panicking::panic(const "internal error: entered unreachable code") -> unwind continue; - } - - bb2: { - // DBG: _5 = &(*_2)[0 of 3]; - // DBG: _6 = &(*_2)[1 of 3]; - // DBG: _7 = &(*_2)[2 of 3]; - StorageDead(_4); - return; - } - } - - ALLOC0 (size: 40, align: 1) { - 0x00 │ 69 6e 74 65 72 6e 61 6c 20 65 72 72 6f 72 3a 20 │ internal error: - 0x10 │ 65 6e 74 65 72 65 64 20 75 6e 72 65 61 63 68 61 │ entered unreacha - 0x20 │ 62 6c 65 20 63 6f 64 65 │ ble code - } - diff --git a/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.32bit.panic-abort.mir b/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.32bit.panic-abort.mir index f3c83f62edf61..cdb8ce66a77a4 100644 --- a/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.32bit.panic-abort.mir +++ b/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.32bit.panic-abort.mir @@ -3,7 +3,8 @@ fn num_to_digit(_1: char) -> u32 { debug num => _1; let mut _0: u32; - let mut _4: std::option::Option; + let mut _4: bool; + let mut _5: std::option::Option; scope 1 (inlined char::methods::::is_digit) { let _2: std::option::Option; scope 2 (inlined Option::::is_some) { @@ -13,13 +14,14 @@ fn num_to_digit(_1: char) -> u32 { } } scope 4 (inlined #[track_caller] Option::::unwrap) { - let mut _5: isize; - let mut _6: !; + let mut _6: isize; + let mut _7: !; scope 5 { } } bb0: { + StorageLive(_4); StorageLive(_2); _2 = char::methods::::to_digit(copy _1, const 8_u32) -> [return: bb1, unwind unreachable]; } @@ -27,44 +29,45 @@ fn num_to_digit(_1: char) -> u32 { bb1: { StorageLive(_3); _3 = discriminant(_2); + _4 = Eq(copy _3, const 1_isize); + StorageDead(_3); StorageDead(_2); - switchInt(copy _3) -> [1: bb2, otherwise: bb7]; + switchInt(move _4) -> [0: bb2, otherwise: bb3]; } bb2: { - StorageDead(_3); - StorageLive(_4); - _4 = char::methods::::to_digit(move _1, const 8_u32) -> [return: bb3, unwind unreachable]; + _0 = const 0_u32; + goto -> bb7; } bb3: { StorageLive(_5); - _5 = discriminant(_4); - switchInt(move _5) -> [0: bb4, 1: bb5, otherwise: bb6]; + _5 = char::methods::::to_digit(move _1, const 8_u32) -> [return: bb4, unwind unreachable]; } bb4: { - _6 = option::unwrap_failed() -> unwind unreachable; + StorageLive(_6); + _6 = discriminant(_5); + switchInt(move _6) -> [0: bb5, 1: bb6, otherwise: bb8]; } bb5: { - _0 = move ((_4 as Some).0: u32); - StorageDead(_5); - StorageDead(_4); - goto -> bb8; + _7 = option::unwrap_failed() -> unwind unreachable; } bb6: { - unreachable; + _0 = move ((_5 as Some).0: u32); + StorageDead(_6); + StorageDead(_5); + goto -> bb7; } bb7: { - StorageDead(_3); - _0 = const 0_u32; - goto -> bb8; + StorageDead(_4); + return; } bb8: { - return; + unreachable; } } diff --git a/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.32bit.panic-unwind.mir b/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.32bit.panic-unwind.mir index 0e55df24cc57b..ad0e4dfa0f33f 100644 --- a/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.32bit.panic-unwind.mir +++ b/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.32bit.panic-unwind.mir @@ -3,7 +3,8 @@ fn num_to_digit(_1: char) -> u32 { debug num => _1; let mut _0: u32; - let mut _4: std::option::Option; + let mut _4: bool; + let mut _5: std::option::Option; scope 1 (inlined char::methods::::is_digit) { let _2: std::option::Option; scope 2 (inlined Option::::is_some) { @@ -13,13 +14,14 @@ fn num_to_digit(_1: char) -> u32 { } } scope 4 (inlined #[track_caller] Option::::unwrap) { - let mut _5: isize; - let mut _6: !; + let mut _6: isize; + let mut _7: !; scope 5 { } } bb0: { + StorageLive(_4); StorageLive(_2); _2 = char::methods::::to_digit(copy _1, const 8_u32) -> [return: bb1, unwind continue]; } @@ -27,44 +29,45 @@ fn num_to_digit(_1: char) -> u32 { bb1: { StorageLive(_3); _3 = discriminant(_2); + _4 = Eq(copy _3, const 1_isize); + StorageDead(_3); StorageDead(_2); - switchInt(copy _3) -> [1: bb2, otherwise: bb7]; + switchInt(move _4) -> [0: bb2, otherwise: bb3]; } bb2: { - StorageDead(_3); - StorageLive(_4); - _4 = char::methods::::to_digit(move _1, const 8_u32) -> [return: bb3, unwind continue]; + _0 = const 0_u32; + goto -> bb7; } bb3: { StorageLive(_5); - _5 = discriminant(_4); - switchInt(move _5) -> [0: bb4, 1: bb5, otherwise: bb6]; + _5 = char::methods::::to_digit(move _1, const 8_u32) -> [return: bb4, unwind continue]; } bb4: { - _6 = option::unwrap_failed() -> unwind continue; + StorageLive(_6); + _6 = discriminant(_5); + switchInt(move _6) -> [0: bb5, 1: bb6, otherwise: bb8]; } bb5: { - _0 = move ((_4 as Some).0: u32); - StorageDead(_5); - StorageDead(_4); - goto -> bb8; + _7 = option::unwrap_failed() -> unwind continue; } bb6: { - unreachable; + _0 = move ((_5 as Some).0: u32); + StorageDead(_6); + StorageDead(_5); + goto -> bb7; } bb7: { - StorageDead(_3); - _0 = const 0_u32; - goto -> bb8; + StorageDead(_4); + return; } bb8: { - return; + unreachable; } } diff --git a/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.64bit.panic-abort.mir b/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.64bit.panic-abort.mir index f3c83f62edf61..cdb8ce66a77a4 100644 --- a/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.64bit.panic-abort.mir +++ b/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.64bit.panic-abort.mir @@ -3,7 +3,8 @@ fn num_to_digit(_1: char) -> u32 { debug num => _1; let mut _0: u32; - let mut _4: std::option::Option; + let mut _4: bool; + let mut _5: std::option::Option; scope 1 (inlined char::methods::::is_digit) { let _2: std::option::Option; scope 2 (inlined Option::::is_some) { @@ -13,13 +14,14 @@ fn num_to_digit(_1: char) -> u32 { } } scope 4 (inlined #[track_caller] Option::::unwrap) { - let mut _5: isize; - let mut _6: !; + let mut _6: isize; + let mut _7: !; scope 5 { } } bb0: { + StorageLive(_4); StorageLive(_2); _2 = char::methods::::to_digit(copy _1, const 8_u32) -> [return: bb1, unwind unreachable]; } @@ -27,44 +29,45 @@ fn num_to_digit(_1: char) -> u32 { bb1: { StorageLive(_3); _3 = discriminant(_2); + _4 = Eq(copy _3, const 1_isize); + StorageDead(_3); StorageDead(_2); - switchInt(copy _3) -> [1: bb2, otherwise: bb7]; + switchInt(move _4) -> [0: bb2, otherwise: bb3]; } bb2: { - StorageDead(_3); - StorageLive(_4); - _4 = char::methods::::to_digit(move _1, const 8_u32) -> [return: bb3, unwind unreachable]; + _0 = const 0_u32; + goto -> bb7; } bb3: { StorageLive(_5); - _5 = discriminant(_4); - switchInt(move _5) -> [0: bb4, 1: bb5, otherwise: bb6]; + _5 = char::methods::::to_digit(move _1, const 8_u32) -> [return: bb4, unwind unreachable]; } bb4: { - _6 = option::unwrap_failed() -> unwind unreachable; + StorageLive(_6); + _6 = discriminant(_5); + switchInt(move _6) -> [0: bb5, 1: bb6, otherwise: bb8]; } bb5: { - _0 = move ((_4 as Some).0: u32); - StorageDead(_5); - StorageDead(_4); - goto -> bb8; + _7 = option::unwrap_failed() -> unwind unreachable; } bb6: { - unreachable; + _0 = move ((_5 as Some).0: u32); + StorageDead(_6); + StorageDead(_5); + goto -> bb7; } bb7: { - StorageDead(_3); - _0 = const 0_u32; - goto -> bb8; + StorageDead(_4); + return; } bb8: { - return; + unreachable; } } diff --git a/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.64bit.panic-unwind.mir b/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.64bit.panic-unwind.mir index 0e55df24cc57b..ad0e4dfa0f33f 100644 --- a/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.64bit.panic-unwind.mir +++ b/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.64bit.panic-unwind.mir @@ -3,7 +3,8 @@ fn num_to_digit(_1: char) -> u32 { debug num => _1; let mut _0: u32; - let mut _4: std::option::Option; + let mut _4: bool; + let mut _5: std::option::Option; scope 1 (inlined char::methods::::is_digit) { let _2: std::option::Option; scope 2 (inlined Option::::is_some) { @@ -13,13 +14,14 @@ fn num_to_digit(_1: char) -> u32 { } } scope 4 (inlined #[track_caller] Option::::unwrap) { - let mut _5: isize; - let mut _6: !; + let mut _6: isize; + let mut _7: !; scope 5 { } } bb0: { + StorageLive(_4); StorageLive(_2); _2 = char::methods::::to_digit(copy _1, const 8_u32) -> [return: bb1, unwind continue]; } @@ -27,44 +29,45 @@ fn num_to_digit(_1: char) -> u32 { bb1: { StorageLive(_3); _3 = discriminant(_2); + _4 = Eq(copy _3, const 1_isize); + StorageDead(_3); StorageDead(_2); - switchInt(copy _3) -> [1: bb2, otherwise: bb7]; + switchInt(move _4) -> [0: bb2, otherwise: bb3]; } bb2: { - StorageDead(_3); - StorageLive(_4); - _4 = char::methods::::to_digit(move _1, const 8_u32) -> [return: bb3, unwind continue]; + _0 = const 0_u32; + goto -> bb7; } bb3: { StorageLive(_5); - _5 = discriminant(_4); - switchInt(move _5) -> [0: bb4, 1: bb5, otherwise: bb6]; + _5 = char::methods::::to_digit(move _1, const 8_u32) -> [return: bb4, unwind continue]; } bb4: { - _6 = option::unwrap_failed() -> unwind continue; + StorageLive(_6); + _6 = discriminant(_5); + switchInt(move _6) -> [0: bb5, 1: bb6, otherwise: bb8]; } bb5: { - _0 = move ((_4 as Some).0: u32); - StorageDead(_5); - StorageDead(_4); - goto -> bb8; + _7 = option::unwrap_failed() -> unwind continue; } bb6: { - unreachable; + _0 = move ((_5 as Some).0: u32); + StorageDead(_6); + StorageDead(_5); + goto -> bb7; } bb7: { - StorageDead(_3); - _0 = const 0_u32; - goto -> bb8; + StorageDead(_4); + return; } bb8: { - return; + unreachable; } } diff --git a/tests/mir-opt/pre-codegen/cmp_switch.rs b/tests/mir-opt/pre-codegen/cmp_switch.rs new file mode 100644 index 0000000000000..dd8e5bc173539 --- /dev/null +++ b/tests/mir-opt/pre-codegen/cmp_switch.rs @@ -0,0 +1,21 @@ +#![crate_type = "lib"] + +// Regression test for . + +// EMIT_MIR cmp_switch.run_my_check.PreCodegen.after.mir +#[inline(never)] +fn run_my_check(v0: u64, v1: u64) -> i32 { + // CHECK-LABEL: fn run_my_check + // CHECK: [[cmp:_.*]] = Eq(copy _1, const 42_u64); + // CHECK: [[eq:_.*]] = Eq(copy _2, const 0_u64); + // CHECK: [[cmp]] = BitAnd(copy _3, move _4); + // CHECK: switchInt(move [[cmp]]) + if do_check(v0, v1) { 1 } else { 0 } +} + +#[inline(always)] +fn do_check(v0: u64, v1: u64) -> bool { + let mut ok = v0 == 42; + ok &= v1 == 0; + ok +} diff --git a/tests/mir-opt/pre-codegen/cmp_switch.run_my_check.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/cmp_switch.run_my_check.PreCodegen.after.mir new file mode 100644 index 0000000000000..cb08f7e34c6e8 --- /dev/null +++ b/tests/mir-opt/pre-codegen/cmp_switch.run_my_check.PreCodegen.after.mir @@ -0,0 +1,38 @@ +// MIR for `run_my_check` after PreCodegen + +fn run_my_check(_1: u64, _2: u64) -> i32 { + debug v0 => _1; + debug v1 => _2; + let mut _0: i32; + let mut _3: bool; + scope 1 (inlined do_check) { + let mut _4: bool; + scope 2 { + } + } + + bb0: { + StorageLive(_3); + _3 = Eq(copy _1, const 42_u64); + StorageLive(_4); + _4 = Eq(copy _2, const 0_u64); + _3 = BitAnd(copy _3, move _4); + StorageDead(_4); + switchInt(move _3) -> [0: bb1, otherwise: bb2]; + } + + bb1: { + _0 = const 0_i32; + goto -> bb3; + } + + bb2: { + _0 = const 1_i32; + goto -> bb3; + } + + bb3: { + StorageDead(_3); + return; + } +} diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir index 013361d1d2fb8..872eb08e19027 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir @@ -8,7 +8,8 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { let _2: std::ptr::NonNull<[T]>; let mut _3: *mut [T]; let mut _4: *const [T]; - let _11: (); + let mut _9: bool; + let _12: (); scope 3 { let _8: std::ptr::alignment::AlignmentEnum; scope 4 { @@ -27,13 +28,13 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { scope 18 (inlined ::deallocate) { scope 19 (inlined std::alloc::Global::deallocate_impl) { scope 20 (inlined std::alloc::Global::deallocate_impl_runtime) { - let mut _9: *mut u8; + let mut _10: *mut u8; scope 21 (inlined Layout::size) { } scope 22 (inlined NonNull::::as_ptr) { } scope 23 (inlined std::alloc::dealloc) { - let mut _10: usize; + let mut _11: usize; scope 24 (inlined Layout::size) { } scope 25 (inlined Layout::align) { @@ -84,20 +85,21 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { StorageDead(_7); StorageDead(_6); StorageDead(_4); - switchInt(copy _5) -> [0: bb4, otherwise: bb2]; + _9 = Ne(copy _5, const 0_usize); + switchInt(copy _9) -> [0: bb4, otherwise: bb2]; } bb2: { - StorageLive(_9); - _9 = copy _3 as *mut u8 (PtrToPtr); StorageLive(_10); - _10 = discriminant(_8); - _11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable]; + _10 = copy _3 as *mut u8 (PtrToPtr); + StorageLive(_11); + _11 = discriminant(_8); + _12 = alloc::alloc::__rust_dealloc(move _10, move _5, move _11) -> [return: bb3, unwind unreachable]; } bb3: { + StorageDead(_11); StorageDead(_10); - StorageDead(_9); goto -> bb4; } diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir index 013361d1d2fb8..872eb08e19027 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir @@ -8,7 +8,8 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { let _2: std::ptr::NonNull<[T]>; let mut _3: *mut [T]; let mut _4: *const [T]; - let _11: (); + let mut _9: bool; + let _12: (); scope 3 { let _8: std::ptr::alignment::AlignmentEnum; scope 4 { @@ -27,13 +28,13 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { scope 18 (inlined ::deallocate) { scope 19 (inlined std::alloc::Global::deallocate_impl) { scope 20 (inlined std::alloc::Global::deallocate_impl_runtime) { - let mut _9: *mut u8; + let mut _10: *mut u8; scope 21 (inlined Layout::size) { } scope 22 (inlined NonNull::::as_ptr) { } scope 23 (inlined std::alloc::dealloc) { - let mut _10: usize; + let mut _11: usize; scope 24 (inlined Layout::size) { } scope 25 (inlined Layout::align) { @@ -84,20 +85,21 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { StorageDead(_7); StorageDead(_6); StorageDead(_4); - switchInt(copy _5) -> [0: bb4, otherwise: bb2]; + _9 = Ne(copy _5, const 0_usize); + switchInt(copy _9) -> [0: bb4, otherwise: bb2]; } bb2: { - StorageLive(_9); - _9 = copy _3 as *mut u8 (PtrToPtr); StorageLive(_10); - _10 = discriminant(_8); - _11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable]; + _10 = copy _3 as *mut u8 (PtrToPtr); + StorageLive(_11); + _11 = discriminant(_8); + _12 = alloc::alloc::__rust_dealloc(move _10, move _5, move _11) -> [return: bb3, unwind unreachable]; } bb3: { + StorageDead(_11); StorageDead(_10); - StorageDead(_9); goto -> bb4; } diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir index 013361d1d2fb8..872eb08e19027 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir @@ -8,7 +8,8 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { let _2: std::ptr::NonNull<[T]>; let mut _3: *mut [T]; let mut _4: *const [T]; - let _11: (); + let mut _9: bool; + let _12: (); scope 3 { let _8: std::ptr::alignment::AlignmentEnum; scope 4 { @@ -27,13 +28,13 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { scope 18 (inlined ::deallocate) { scope 19 (inlined std::alloc::Global::deallocate_impl) { scope 20 (inlined std::alloc::Global::deallocate_impl_runtime) { - let mut _9: *mut u8; + let mut _10: *mut u8; scope 21 (inlined Layout::size) { } scope 22 (inlined NonNull::::as_ptr) { } scope 23 (inlined std::alloc::dealloc) { - let mut _10: usize; + let mut _11: usize; scope 24 (inlined Layout::size) { } scope 25 (inlined Layout::align) { @@ -84,20 +85,21 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { StorageDead(_7); StorageDead(_6); StorageDead(_4); - switchInt(copy _5) -> [0: bb4, otherwise: bb2]; + _9 = Ne(copy _5, const 0_usize); + switchInt(copy _9) -> [0: bb4, otherwise: bb2]; } bb2: { - StorageLive(_9); - _9 = copy _3 as *mut u8 (PtrToPtr); StorageLive(_10); - _10 = discriminant(_8); - _11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable]; + _10 = copy _3 as *mut u8 (PtrToPtr); + StorageLive(_11); + _11 = discriminant(_8); + _12 = alloc::alloc::__rust_dealloc(move _10, move _5, move _11) -> [return: bb3, unwind unreachable]; } bb3: { + StorageDead(_11); StorageDead(_10); - StorageDead(_9); goto -> bb4; } diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir index 013361d1d2fb8..872eb08e19027 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir @@ -8,7 +8,8 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { let _2: std::ptr::NonNull<[T]>; let mut _3: *mut [T]; let mut _4: *const [T]; - let _11: (); + let mut _9: bool; + let _12: (); scope 3 { let _8: std::ptr::alignment::AlignmentEnum; scope 4 { @@ -27,13 +28,13 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { scope 18 (inlined ::deallocate) { scope 19 (inlined std::alloc::Global::deallocate_impl) { scope 20 (inlined std::alloc::Global::deallocate_impl_runtime) { - let mut _9: *mut u8; + let mut _10: *mut u8; scope 21 (inlined Layout::size) { } scope 22 (inlined NonNull::::as_ptr) { } scope 23 (inlined std::alloc::dealloc) { - let mut _10: usize; + let mut _11: usize; scope 24 (inlined Layout::size) { } scope 25 (inlined Layout::align) { @@ -84,20 +85,21 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { StorageDead(_7); StorageDead(_6); StorageDead(_4); - switchInt(copy _5) -> [0: bb4, otherwise: bb2]; + _9 = Ne(copy _5, const 0_usize); + switchInt(copy _9) -> [0: bb4, otherwise: bb2]; } bb2: { - StorageLive(_9); - _9 = copy _3 as *mut u8 (PtrToPtr); StorageLive(_10); - _10 = discriminant(_8); - _11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable]; + _10 = copy _3 as *mut u8 (PtrToPtr); + StorageLive(_11); + _11 = discriminant(_8); + _12 = alloc::alloc::__rust_dealloc(move _10, move _5, move _11) -> [return: bb3, unwind unreachable]; } bb3: { + StorageDead(_11); StorageDead(_10); - StorageDead(_9); goto -> bb4; } diff --git a/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir index 6ab4b77123069..e537dd6a28ef8 100644 --- a/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir @@ -3,334 +3,72 @@ fn vec_move(_1: Vec) -> () { debug v => _1; let mut _0: (); - let mut _22: std::vec::IntoIter; - let mut _23: std::vec::IntoIter; - let mut _24: &mut std::vec::IntoIter; - let mut _25: std::option::Option; - let mut _26: isize; - let _28: (); + let mut _2: std::vec::IntoIter; + let mut _3: std::vec::IntoIter; + let mut _4: &mut std::vec::IntoIter; + let mut _5: std::option::Option; + let mut _6: isize; + let _8: (); scope 1 { - debug iter => _23; - let _27: impl Sized; + debug iter => _3; + let _7: impl Sized; scope 2 { - debug x => _27; - } - } - scope 3 (inlined as IntoIterator>::into_iter) { - debug self => _1; - let _3: std::mem::ManuallyDrop>; - let mut _4: *const std::alloc::Global; - let mut _9: usize; - let mut _11: *mut impl Sized; - let mut _12: *const impl Sized; - let mut _13: usize; - let _29: &std::vec::Vec; - let mut _30: &std::mem::ManuallyDrop>; - let mut _31: &alloc::raw_vec::RawVec; - let mut _32: &std::mem::ManuallyDrop>; - let _33: &std::vec::Vec; - let mut _34: &std::mem::ManuallyDrop>; - let _35: &std::vec::Vec; - let mut _36: &std::mem::ManuallyDrop>; - let mut _37: &alloc::raw_vec::RawVec; - let mut _38: &std::mem::ManuallyDrop>; - scope 4 { - debug me => _3; - scope 5 { - debug alloc => const ManuallyDrop:: {{ value: MaybeDangling::(std::alloc::Global) }}; - let _7: std::ptr::NonNull; - scope 6 { - debug buf => _7; - let _8: *mut impl Sized; - scope 7 { - debug begin => _8; - scope 8 { - debug end => _12; - let _20: usize; - scope 9 { - debug cap => _20; - } - scope 45 (inlined > as Deref>::deref) { - debug self => _38; - scope 46 (inlined MaybeDangling::>::as_ref) { - } - } - scope 47 (inlined alloc::raw_vec::RawVec::::capacity) { - debug self => _37; - let mut _39: &alloc::raw_vec::RawVecInner; - scope 48 (inlined std::mem::size_of::) { - } - scope 49 (inlined alloc::raw_vec::RawVecInner::capacity) { - debug self => _39; - debug elem_size => const ::SIZE; - let mut _21: core::num::niche_types::UsizeNoHighBit; - scope 50 (inlined core::num::niche_types::UsizeNoHighBit::as_inner) { - debug self => _21; - } - } - } - } - scope 29 (inlined > as Deref>::deref) { - debug self => _34; - scope 30 (inlined MaybeDangling::>::as_ref) { - } - } - scope 31 (inlined Vec::::len) { - debug self => _33; - let mut _14: bool; - scope 32 { - } - } - scope 33 (inlined std::ptr::mut_ptr::::wrapping_byte_add) { - debug self => _8; - debug count => _13; - let mut _15: *mut u8; - let mut _19: *mut u8; - scope 34 (inlined std::ptr::mut_ptr::::cast::) { - debug self => _8; - } - scope 35 (inlined std::ptr::mut_ptr::::wrapping_add) { - debug self => _15; - debug count => _13; - let mut _16: isize; - scope 36 (inlined std::ptr::mut_ptr::::wrapping_offset) { - debug self => _15; - debug count => _16; - let mut _17: *const u8; - let mut _18: *const u8; - } - } - scope 37 (inlined std::ptr::mut_ptr::::with_metadata_of::) { - debug self => _19; - debug meta => _6; - scope 38 (inlined std::ptr::metadata::) { - debug ptr => _6; - } - scope 39 (inlined std::ptr::from_raw_parts_mut::) { - } - } - } - scope 40 (inlined > as Deref>::deref) { - debug self => _36; - scope 41 (inlined MaybeDangling::>::as_ref) { - } - } - scope 42 (inlined Vec::::len) { - debug self => _35; - let mut _10: bool; - scope 43 { - } - } - scope 44 (inlined #[track_caller] std::ptr::mut_ptr::::add) { - debug self => _8; - debug count => _9; - } - } - scope 28 (inlined NonNull::::as_ptr) { - debug self => _7; - } - } - scope 20 (inlined > as Deref>::deref) { - debug self => _32; - scope 21 (inlined MaybeDangling::>::as_ref) { - } - } - scope 22 (inlined alloc::raw_vec::RawVec::::non_null) { - debug self => _31; - scope 23 (inlined alloc::raw_vec::RawVecInner::non_null::) { - let mut _5: std::ptr::NonNull; - scope 24 (inlined Unique::::cast::) { - scope 25 (inlined NonNull::::cast::) { - let mut _6: *const impl Sized; - scope 26 (inlined NonNull::::as_ptr) { - } - } - } - scope 27 (inlined Unique::::as_non_null_ptr) { - } - } - } - } - scope 12 (inlined > as Deref>::deref) { - debug self => _30; - scope 13 (inlined MaybeDangling::>::as_ref) { - } - } - scope 14 (inlined Vec::::allocator) { - debug self => _29; - scope 15 (inlined alloc::raw_vec::RawVec::::allocator) { - scope 16 (inlined alloc::raw_vec::RawVecInner::allocator) { - } - } - } - scope 17 (inlined #[track_caller] std::ptr::read::) { - debug src => _4; - } - scope 18 (inlined ManuallyDrop::::new) { - debug value => const std::alloc::Global; - scope 19 (inlined MaybeDangling::::new) { - } - } - } - scope 10 (inlined ManuallyDrop::>::new) { - debug value => _1; - let mut _2: std::mem::MaybeDangling>; - scope 11 (inlined MaybeDangling::>::new) { - } + debug x => _7; } } bb0: { - StorageLive(_22); - StorageLive(_7); - StorageLive(_8); - StorageLive(_12); - StorageLive(_20); - StorageLive(_6); - StorageLive(_5); - StorageLive(_18); - StorageLive(_3); StorageLive(_2); - _2 = MaybeDangling::>(copy _1); - _3 = ManuallyDrop::> { value: move _2 }; - StorageDead(_2); - StorageLive(_4); - // DBG: _30 = &_3; - // DBG: _29 = &((_3.0: std::mem::MaybeDangling>).0: std::vec::Vec); - _4 = &raw const (((((_3.0: std::mem::MaybeDangling>).0: std::vec::Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).2: std::alloc::Global); - StorageDead(_4); - // DBG: _32 = &_3; - // DBG: _31 = &(((_3.0: std::mem::MaybeDangling>).0: std::vec::Vec).0: alloc::raw_vec::RawVec); - _5 = copy ((((((_3.0: std::mem::MaybeDangling>).0: std::vec::Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull); - _6 = copy _5 as *const impl Sized (Transmute); - _7 = NonNull:: { pointer: copy _6 }; - _8 = copy _5 as *mut impl Sized (Transmute); - switchInt(const ::IS_ZST) -> [0: bb1, otherwise: bb2]; + _2 = as IntoIterator>::into_iter(move _1) -> [return: bb1, unwind continue]; } bb1: { - StorageLive(_11); - StorageLive(_9); - // DBG: _36 = &_3; - // DBG: _35 = &((_3.0: std::mem::MaybeDangling>).0: std::vec::Vec); - _9 = copy (((_3.0: std::mem::MaybeDangling>).0: std::vec::Vec).1: usize); - StorageLive(_10); - _10 = Le(copy _9, const ::MAX_SLICE_LEN); - assume(move _10); - StorageDead(_10); - _11 = Offset(copy _8, copy _9); - _12 = copy _11 as *const impl Sized (PtrToPtr); - StorageDead(_9); - StorageDead(_11); - goto -> bb4; + StorageLive(_3); + _3 = move _2; + goto -> bb2; } bb2: { - StorageLive(_13); - // DBG: _34 = &_3; - // DBG: _33 = &((_3.0: std::mem::MaybeDangling>).0: std::vec::Vec); - _13 = copy (((_3.0: std::mem::MaybeDangling>).0: std::vec::Vec).1: usize); - StorageLive(_14); - _14 = Le(copy _13, const ::MAX_SLICE_LEN); - assume(move _14); - StorageDead(_14); - StorageLive(_19); - StorageLive(_15); - _15 = copy _5 as *mut u8 (Transmute); - StorageLive(_16); - _16 = copy _13 as isize (IntToInt); - StorageLive(_17); - _17 = copy _5 as *const u8 (Transmute); - _18 = arith_offset::(move _17, move _16) -> [return: bb3, unwind unreachable]; + StorageLive(_5); + _4 = &mut _3; + _5 = as Iterator>::next(move _4) -> [return: bb3, unwind: bb9]; } bb3: { - StorageDead(_17); - _19 = copy _18 as *mut u8 (PtrToPtr); - StorageDead(_16); - StorageDead(_15); - StorageDead(_19); - StorageDead(_13); - _12 = copy _18 as *const impl Sized (PtrToPtr); - goto -> bb4; + _6 = discriminant(_5); + switchInt(move _6) -> [0: bb4, 1: bb6, otherwise: bb8]; } bb4: { - // DBG: _38 = &_3; - // DBG: _37 = &(((_3.0: std::mem::MaybeDangling>).0: std::vec::Vec).0: alloc::raw_vec::RawVec); - // DBG: _39 = &((((_3.0: std::mem::MaybeDangling>).0: std::vec::Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner); - switchInt(const ::SIZE) -> [0: bb5, otherwise: bb6]; + StorageDead(_5); + drop(_3) -> [return: bb5, unwind continue]; } bb5: { - _20 = const usize::MAX; - goto -> bb7; + StorageDead(_3); + StorageDead(_2); + return; } bb6: { - StorageLive(_21); - _21 = copy (((((_3.0: std::mem::MaybeDangling>).0: std::vec::Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).1: core::num::niche_types::UsizeNoHighBit); - _20 = copy _21 as usize (Transmute); - StorageDead(_21); - goto -> bb7; + _7 = move ((_5 as Some).0: impl Sized); + _8 = opaque::(move _7) -> [return: bb7, unwind: bb9]; } bb7: { - _22 = std::vec::IntoIter:: { buf: copy _7, phantom: const ZeroSized: PhantomData, cap: move _20, alloc: const ManuallyDrop:: {{ value: MaybeDangling::(std::alloc::Global) }}, ptr: copy _7, end: copy _12 }; - StorageDead(_3); - StorageDead(_18); StorageDead(_5); - StorageDead(_6); - StorageDead(_20); - StorageDead(_12); - StorageDead(_8); - StorageDead(_7); - StorageLive(_23); - _23 = move _22; - goto -> bb8; + goto -> bb2; } bb8: { - StorageLive(_25); - _24 = &mut _23; - _25 = as Iterator>::next(move _24) -> [return: bb9, unwind: bb15]; - } - - bb9: { - _26 = discriminant(_25); - switchInt(move _26) -> [0: bb10, 1: bb12, otherwise: bb14]; - } - - bb10: { - StorageDead(_25); - drop(_23) -> [return: bb11, unwind continue]; - } - - bb11: { - StorageDead(_23); - StorageDead(_22); - return; - } - - bb12: { - _27 = move ((_25 as Some).0: impl Sized); - _28 = opaque::(move _27) -> [return: bb13, unwind: bb15]; - } - - bb13: { - StorageDead(_25); - goto -> bb8; - } - - bb14: { unreachable; } - bb15 (cleanup): { - drop(_23) -> [return: bb16, unwind terminate(cleanup)]; + bb9 (cleanup): { + drop(_3) -> [return: bb10, unwind terminate(cleanup)]; } - bb16 (cleanup): { + bb10 (cleanup): { resume; } } diff --git a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir index f72611b7cb8e3..fffd39c0c4ab2 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir @@ -5,27 +5,27 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { debug f => _2; let mut _0: (); let mut _10: usize; - let mut _28: std::option::Option<(usize, &T)>; - let mut _31: &impl Fn(usize, &T); - let mut _32: (usize, &T); - let _33: (); + let mut _29: std::option::Option<(usize, &T)>; + let mut _32: &impl Fn(usize, &T); + let mut _33: (usize, &T); + let _34: (); scope 1 { debug (((iter: Enumerate>).0: std::slice::Iter<'_, T>).0: std::ptr::NonNull) => _6; debug (((iter: Enumerate>).0: std::slice::Iter<'_, T>).1: *const T) => _9; debug (((iter: Enumerate>).0: std::slice::Iter<'_, T>).2: std::marker::PhantomData<&T>) => const ZeroSized: PhantomData<&T>; debug ((iter: Enumerate>).1: usize) => _10; - let _29: usize; - let _30: &T; + let _30: usize; + let _31: &T; scope 2 { - debug i => _29; - debug x => _30; + debug i => _30; + debug x => _31; } scope 18 (inlined > as Iterator>::next) { - let mut _23: std::option::Option<&T>; - let mut _26: (usize, bool); - let mut _27: (usize, &T); + let mut _24: std::option::Option<&T>; + let mut _27: (usize, bool); + let mut _28: (usize, &T); scope 19 { - let _25: usize; + let _26: usize; scope 24 { } } @@ -40,7 +40,7 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } } scope 25 (inlined as Try>::branch) { - let _24: &T; + let _25: &T; scope 26 { } } @@ -49,8 +49,9 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { let _11: std::ptr::NonNull; let _13: std::ptr::NonNull; let mut _16: bool; - let mut _20: usize; - let _22: &T; + let mut _20: bool; + let mut _21: usize; + let _23: &T; scope 29 { let _12: *const T; scope 30 { @@ -84,7 +85,7 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } } scope 43 (inlined NonNull::::as_ref::<'_>) { - let _21: *const T; + let _22: *const T; scope 44 (inlined NonNull::::as_ptr) { } scope 45 (inlined std::ptr::mut_ptr::::cast_const) { @@ -169,16 +170,16 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } bb4: { - StorageLive(_28); - StorageLive(_25); + StorageLive(_29); StorageLive(_26); - StorageLive(_23); + StorageLive(_27); + StorageLive(_24); StorageLive(_11); StorageLive(_12); StorageLive(_19); - StorageLive(_20); + StorageLive(_21); StorageLive(_13); - StorageLive(_22); + StorageLive(_23); _11 = copy _6; _12 = copy _9; switchInt(const ::IS_ZST) -> [0: bb5, otherwise: bb8]; @@ -206,88 +207,92 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { StorageDead(_17); _6 = NonNull:: { pointer: copy _18 }; StorageDead(_18); - goto -> bb13; + goto -> bb10; } bb7: { StorageDead(_16); - goto -> bb10; + goto -> bb14; } bb8: { _19 = copy _12 as usize (Transmute); - switchInt(copy _19) -> [0: bb9, otherwise: bb12]; + StorageLive(_20); + _20 = Eq(copy _19, const 0_usize); + switchInt(move _20) -> [0: bb9, otherwise: bb13]; } bb9: { + StorageDead(_20); + _21 = SubUnchecked(copy _19, const 1_usize); + _9 = copy _21 as *const T (Transmute); goto -> bb10; } bb10: { + StorageLive(_22); + _22 = copy _11 as *const T (Transmute); + _23 = &(*_22); StorageDead(_22); + _24 = Option::<&T>::Some(copy _23); + StorageDead(_23); StorageDead(_13); - StorageDead(_20); + StorageDead(_21); StorageDead(_19); StorageDead(_12); StorageDead(_11); - StorageDead(_23); - StorageDead(_26); - StorageDead(_25); - StorageDead(_28); - StorageDead(_10); - drop(_2) -> [return: bb11, unwind unreachable]; + _25 = copy ((_24 as Some).0: &T); + StorageDead(_24); + _26 = copy _10; + _27 = AddWithOverflow(copy _10, const 1_usize); + assert(!move (_27.1: bool), "attempt to compute `{} + {}`, which would overflow", copy _10, const 1_usize) -> [success: bb11, unwind unreachable]; } bb11: { - return; + _10 = move (_27.0: usize); + StorageLive(_28); + _28 = (copy _26, copy _25); + _29 = Option::<(usize, &T)>::Some(move _28); + StorageDead(_28); + StorageDead(_27); + StorageDead(_26); + _30 = copy (((_29 as Some).0: (usize, &T)).0: usize); + _31 = copy (((_29 as Some).0: (usize, &T)).1: &T); + StorageLive(_32); + _32 = &_2; + StorageLive(_33); + _33 = (copy _30, copy _31); + _34 = >::call(move _32, move _33) -> [return: bb12, unwind unreachable]; } bb12: { - _20 = SubUnchecked(copy _19, const 1_usize); - _9 = copy _20 as *const T (Transmute); - goto -> bb13; + StorageDead(_33); + StorageDead(_32); + StorageDead(_29); + goto -> bb4; } bb13: { - StorageLive(_21); - _21 = copy _11 as *const T (Transmute); - _22 = &(*_21); - StorageDead(_21); - _23 = Option::<&T>::Some(copy _22); - StorageDead(_22); - StorageDead(_13); StorageDead(_20); - StorageDead(_19); - StorageDead(_12); - StorageDead(_11); - _24 = copy ((_23 as Some).0: &T); - StorageDead(_23); - _25 = copy _10; - _26 = AddWithOverflow(copy _10, const 1_usize); - assert(!move (_26.1: bool), "attempt to compute `{} + {}`, which would overflow", copy _10, const 1_usize) -> [success: bb14, unwind unreachable]; + goto -> bb14; } bb14: { - _10 = move (_26.0: usize); - StorageLive(_27); - _27 = (copy _25, copy _24); - _28 = Option::<(usize, &T)>::Some(move _27); + StorageDead(_23); + StorageDead(_13); + StorageDead(_21); + StorageDead(_19); + StorageDead(_12); + StorageDead(_11); + StorageDead(_24); StorageDead(_27); StorageDead(_26); - StorageDead(_25); - _29 = copy (((_28 as Some).0: (usize, &T)).0: usize); - _30 = copy (((_28 as Some).0: (usize, &T)).1: &T); - StorageLive(_31); - _31 = &_2; - StorageLive(_32); - _32 = (copy _29, copy _30); - _33 = >::call(move _31, move _32) -> [return: bb15, unwind unreachable]; + StorageDead(_29); + StorageDead(_10); + drop(_2) -> [return: bb15, unwind unreachable]; } bb15: { - StorageDead(_32); - StorageDead(_31); - StorageDead(_28); - goto -> bb4; + return; } } diff --git a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir index b210efb1f46c2..208739042172a 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir @@ -4,25 +4,26 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { debug slice => _1; debug f => _2; let mut _0: (); - let mut _22: std::option::Option<&T>; - let mut _24: &impl Fn(&T); - let mut _25: (&T,); - let _26: (); + let mut _23: std::option::Option<&T>; + let mut _25: &impl Fn(&T); + let mut _26: (&T,); + let _27: (); scope 1 { debug ((iter: std::slice::Iter<'_, T>).0: std::ptr::NonNull) => _6; debug ((iter: std::slice::Iter<'_, T>).1: *const T) => _9; debug ((iter: std::slice::Iter<'_, T>).2: std::marker::PhantomData<&T>) => const ZeroSized: PhantomData<&T>; - let _23: &T; + let _24: &T; scope 2 { - debug x => _23; + debug x => _24; } scope 16 (inlined as Iterator>::next) { let mut _6: std::ptr::NonNull; let _10: std::ptr::NonNull; let _12: std::ptr::NonNull; let mut _15: bool; - let mut _19: usize; - let _21: &T; + let mut _19: bool; + let mut _20: usize; + let _22: &T; scope 17 { let _11: *const T; scope 18 { @@ -56,7 +57,7 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } scope 31 (inlined NonNull::::as_ref::<'_>) { - let _20: *const T; + let _21: *const T; scope 32 (inlined NonNull::::as_ptr) { } scope 33 (inlined std::ptr::mut_ptr::::cast_const) { @@ -134,13 +135,13 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb4: { - StorageLive(_22); + StorageLive(_23); StorageLive(_10); StorageLive(_11); StorageLive(_18); - StorageLive(_19); + StorageLive(_20); StorageLive(_12); - StorageLive(_21); + StorageLive(_22); _10 = copy _6; _11 = copy _9; switchInt(const ::IS_ZST) -> [0: bb5, otherwise: bb8]; @@ -168,68 +169,72 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { StorageDead(_16); _6 = NonNull:: { pointer: copy _17 }; StorageDead(_17); - goto -> bb13; + goto -> bb10; } bb7: { StorageDead(_15); - goto -> bb10; + goto -> bb13; } bb8: { _18 = copy _11 as usize (Transmute); - switchInt(copy _18) -> [0: bb9, otherwise: bb12]; + StorageLive(_19); + _19 = Eq(copy _18, const 0_usize); + switchInt(move _19) -> [0: bb9, otherwise: bb12]; } bb9: { + StorageDead(_19); + _20 = SubUnchecked(copy _18, const 1_usize); + _9 = copy _20 as *const T (Transmute); goto -> bb10; } bb10: { + StorageLive(_21); + _21 = copy _10 as *const T (Transmute); + _22 = &(*_21); StorageDead(_21); + _23 = Option::<&T>::Some(copy _22); + StorageDead(_22); StorageDead(_12); - StorageDead(_19); + StorageDead(_20); StorageDead(_18); StorageDead(_11); StorageDead(_10); - StorageDead(_22); - drop(_2) -> [return: bb11, unwind unreachable]; + _24 = copy ((_23 as Some).0: &T); + StorageLive(_25); + _25 = &_2; + StorageLive(_26); + _26 = (copy _24,); + _27 = >::call(move _25, move _26) -> [return: bb11, unwind unreachable]; } bb11: { - return; + StorageDead(_26); + StorageDead(_25); + StorageDead(_23); + goto -> bb4; } bb12: { - _19 = SubUnchecked(copy _18, const 1_usize); - _9 = copy _19 as *const T (Transmute); + StorageDead(_19); goto -> bb13; } bb13: { - StorageLive(_20); - _20 = copy _10 as *const T (Transmute); - _21 = &(*_20); - StorageDead(_20); - _22 = Option::<&T>::Some(copy _21); - StorageDead(_21); + StorageDead(_22); StorageDead(_12); - StorageDead(_19); + StorageDead(_20); StorageDead(_18); StorageDead(_11); StorageDead(_10); - _23 = copy ((_22 as Some).0: &T); - StorageLive(_24); - _24 = &_2; - StorageLive(_25); - _25 = (copy _23,); - _26 = >::call(move _24, move _25) -> [return: bb14, unwind unreachable]; + StorageDead(_23); + drop(_2) -> [return: bb14, unwind unreachable]; } bb14: { - StorageDead(_25); - StorageDead(_24); - StorageDead(_22); - goto -> bb4; + return; } } diff --git a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir index ab6e2bf0b36b3..3f8ed2c47c0ea 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir @@ -4,25 +4,26 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { debug slice => _1; debug f => _2; let mut _0: (); - let mut _22: std::option::Option<&T>; - let mut _24: &impl Fn(&T); - let mut _25: (&T,); - let _26: (); + let mut _23: std::option::Option<&T>; + let mut _25: &impl Fn(&T); + let mut _26: (&T,); + let _27: (); scope 1 { debug ((iter: std::slice::Iter<'_, T>).0: std::ptr::NonNull) => _6; debug ((iter: std::slice::Iter<'_, T>).1: *const T) => _9; debug ((iter: std::slice::Iter<'_, T>).2: std::marker::PhantomData<&T>) => const ZeroSized: PhantomData<&T>; - let _23: &T; + let _24: &T; scope 2 { - debug x => _23; + debug x => _24; } scope 16 (inlined as Iterator>::next) { let mut _6: std::ptr::NonNull; let _10: std::ptr::NonNull; let _12: std::ptr::NonNull; let mut _15: bool; - let mut _19: usize; - let _21: &T; + let mut _19: bool; + let mut _20: usize; + let _22: &T; scope 17 { let _11: *const T; scope 18 { @@ -56,7 +57,7 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } scope 31 (inlined NonNull::::as_ref::<'_>) { - let _20: *const T; + let _21: *const T; scope 32 (inlined NonNull::::as_ptr) { } scope 33 (inlined std::ptr::mut_ptr::::cast_const) { @@ -134,13 +135,13 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb4: { - StorageLive(_22); + StorageLive(_23); StorageLive(_10); StorageLive(_11); StorageLive(_18); - StorageLive(_19); + StorageLive(_20); StorageLive(_12); - StorageLive(_21); + StorageLive(_22); _10 = copy _6; _11 = copy _9; switchInt(const ::IS_ZST) -> [0: bb5, otherwise: bb8]; @@ -168,76 +169,80 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { StorageDead(_16); _6 = NonNull:: { pointer: copy _17 }; StorageDead(_17); - goto -> bb13; + goto -> bb10; } bb7: { StorageDead(_15); - goto -> bb10; + goto -> bb15; } bb8: { _18 = copy _11 as usize (Transmute); - switchInt(copy _18) -> [0: bb9, otherwise: bb12]; + StorageLive(_19); + _19 = Eq(copy _18, const 0_usize); + switchInt(move _19) -> [0: bb9, otherwise: bb14]; } bb9: { + StorageDead(_19); + _20 = SubUnchecked(copy _18, const 1_usize); + _9 = copy _20 as *const T (Transmute); goto -> bb10; } bb10: { + StorageLive(_21); + _21 = copy _10 as *const T (Transmute); + _22 = &(*_21); StorageDead(_21); + _23 = Option::<&T>::Some(copy _22); + StorageDead(_22); StorageDead(_12); - StorageDead(_19); + StorageDead(_20); StorageDead(_18); StorageDead(_11); StorageDead(_10); - StorageDead(_22); - drop(_2) -> [return: bb11, unwind continue]; + _24 = copy ((_23 as Some).0: &T); + StorageLive(_25); + _25 = &_2; + StorageLive(_26); + _26 = (copy _24,); + _27 = >::call(move _25, move _26) -> [return: bb11, unwind: bb12]; } bb11: { - return; + StorageDead(_26); + StorageDead(_25); + StorageDead(_23); + goto -> bb4; } - bb12: { - _19 = SubUnchecked(copy _18, const 1_usize); - _9 = copy _19 as *const T (Transmute); - goto -> bb13; + bb12 (cleanup): { + drop(_2) -> [return: bb13, unwind terminate(cleanup)]; } - bb13: { - StorageLive(_20); - _20 = copy _10 as *const T (Transmute); - _21 = &(*_20); - StorageDead(_20); - _22 = Option::<&T>::Some(copy _21); - StorageDead(_21); - StorageDead(_12); - StorageDead(_19); - StorageDead(_18); - StorageDead(_11); - StorageDead(_10); - _23 = copy ((_22 as Some).0: &T); - StorageLive(_24); - _24 = &_2; - StorageLive(_25); - _25 = (copy _23,); - _26 = >::call(move _24, move _25) -> [return: bb14, unwind: bb15]; + bb13 (cleanup): { + resume; } bb14: { - StorageDead(_25); - StorageDead(_24); - StorageDead(_22); - goto -> bb4; + StorageDead(_19); + goto -> bb15; } - bb15 (cleanup): { - drop(_2) -> [return: bb16, unwind terminate(cleanup)]; + bb15: { + StorageDead(_22); + StorageDead(_12); + StorageDead(_20); + StorageDead(_18); + StorageDead(_11); + StorageDead(_10); + StorageDead(_23); + drop(_2) -> [return: bb16, unwind continue]; } - bb16 (cleanup): { - resume; + bb16: { + return; } } diff --git a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-abort.mir index cc0fce26149e3..b14022b283dcb 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-abort.mir @@ -8,8 +8,9 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { let _4: std::ptr::NonNull; let mut _7: bool; let mut _10: std::ptr::NonNull; - let mut _12: usize; - let _14: &T; + let mut _12: bool; + let mut _13: usize; + let _15: &T; scope 2 { let _3: *const T; scope 3 { @@ -43,7 +44,7 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { } } scope 16 (inlined NonNull::::as_ref::<'_>) { - let _13: *const T; + let _14: *const T; scope 17 (inlined NonNull::::as_ptr) { } scope 18 (inlined std::ptr::mut_ptr::::cast_const) { @@ -57,9 +58,9 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { StorageLive(_2); StorageLive(_3); StorageLive(_11); - StorageLive(_12); + StorageLive(_13); StorageLive(_4); - StorageLive(_14); + StorageLive(_15); _2 = copy ((*_1).0: std::ptr::NonNull); _3 = copy ((*_1).1: *const T); switchInt(const ::IS_ZST) -> [0: bb1, otherwise: bb4]; @@ -90,7 +91,7 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { StorageDead(_9); ((*_1).0: std::ptr::NonNull) = move _10; StorageDead(_10); - goto -> bb7; + goto -> bb6; } bb3: { @@ -101,33 +102,37 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { bb4: { _11 = copy _3 as usize (Transmute); - switchInt(copy _11) -> [0: bb5, otherwise: bb6]; + StorageLive(_12); + _12 = Eq(copy _11, const 0_usize); + switchInt(move _12) -> [0: bb5, otherwise: bb7]; } bb5: { - _0 = const {transmute(0x0000000000000000): Option<&T>}; - goto -> bb8; + StorageDead(_12); + _13 = SubUnchecked(copy _11, const 1_usize); + ((*_1).1: *const T) = copy _13 as *const T (Transmute); + goto -> bb6; } bb6: { - _12 = SubUnchecked(copy _11, const 1_usize); - ((*_1).1: *const T) = copy _12 as *const T (Transmute); - goto -> bb7; + StorageLive(_14); + _14 = copy _2 as *const T (Transmute); + _15 = &(*_14); + StorageDead(_14); + _0 = Option::<&T>::Some(copy _15); + goto -> bb8; } bb7: { - StorageLive(_13); - _13 = copy _2 as *const T (Transmute); - _14 = &(*_13); - StorageDead(_13); - _0 = Option::<&T>::Some(copy _14); + _0 = const {transmute(0x0000000000000000): Option<&T>}; + StorageDead(_12); goto -> bb8; } bb8: { - StorageDead(_14); + StorageDead(_15); StorageDead(_4); - StorageDead(_12); + StorageDead(_13); StorageDead(_11); StorageDead(_3); StorageDead(_2); diff --git a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-unwind.mir index cc0fce26149e3..b14022b283dcb 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-unwind.mir @@ -8,8 +8,9 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { let _4: std::ptr::NonNull; let mut _7: bool; let mut _10: std::ptr::NonNull; - let mut _12: usize; - let _14: &T; + let mut _12: bool; + let mut _13: usize; + let _15: &T; scope 2 { let _3: *const T; scope 3 { @@ -43,7 +44,7 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { } } scope 16 (inlined NonNull::::as_ref::<'_>) { - let _13: *const T; + let _14: *const T; scope 17 (inlined NonNull::::as_ptr) { } scope 18 (inlined std::ptr::mut_ptr::::cast_const) { @@ -57,9 +58,9 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { StorageLive(_2); StorageLive(_3); StorageLive(_11); - StorageLive(_12); + StorageLive(_13); StorageLive(_4); - StorageLive(_14); + StorageLive(_15); _2 = copy ((*_1).0: std::ptr::NonNull); _3 = copy ((*_1).1: *const T); switchInt(const ::IS_ZST) -> [0: bb1, otherwise: bb4]; @@ -90,7 +91,7 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { StorageDead(_9); ((*_1).0: std::ptr::NonNull) = move _10; StorageDead(_10); - goto -> bb7; + goto -> bb6; } bb3: { @@ -101,33 +102,37 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { bb4: { _11 = copy _3 as usize (Transmute); - switchInt(copy _11) -> [0: bb5, otherwise: bb6]; + StorageLive(_12); + _12 = Eq(copy _11, const 0_usize); + switchInt(move _12) -> [0: bb5, otherwise: bb7]; } bb5: { - _0 = const {transmute(0x0000000000000000): Option<&T>}; - goto -> bb8; + StorageDead(_12); + _13 = SubUnchecked(copy _11, const 1_usize); + ((*_1).1: *const T) = copy _13 as *const T (Transmute); + goto -> bb6; } bb6: { - _12 = SubUnchecked(copy _11, const 1_usize); - ((*_1).1: *const T) = copy _12 as *const T (Transmute); - goto -> bb7; + StorageLive(_14); + _14 = copy _2 as *const T (Transmute); + _15 = &(*_14); + StorageDead(_14); + _0 = Option::<&T>::Some(copy _15); + goto -> bb8; } bb7: { - StorageLive(_13); - _13 = copy _2 as *const T (Transmute); - _14 = &(*_13); - StorageDead(_13); - _0 = Option::<&T>::Some(copy _14); + _0 = const {transmute(0x0000000000000000): Option<&T>}; + StorageDead(_12); goto -> bb8; } bb8: { - StorageDead(_14); + StorageDead(_15); StorageDead(_4); - StorageDead(_12); + StorageDead(_13); StorageDead(_11); StorageDead(_3); StorageDead(_2);