diff options
| author | dianqk <dianqk@dianqk.net> | 2025-05-24 15:36:06 +0800 |
|---|---|---|
| committer | dianqk <dianqk@dianqk.net> | 2025-05-24 15:36:06 +0800 |
| commit | 8c7faa6ed154893fdbfcb128055b593102b4c6db (patch) | |
| tree | 83c9389c2775f84cd6d2f6f09c4b9335805263ce /compiler/rustc_mir_transform/src | |
| parent | 145d2266d930d8d8b4119eb230590269d0626c05 (diff) | |
| download | rust-8c7faa6ed154893fdbfcb128055b593102b4c6db.tar.gz rust-8c7faa6ed154893fdbfcb128055b593102b4c6db.zip | |
mir-opt: Do not create storage marks for temporary locals
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/early_otherwise_branch.rs | 48 |
1 files changed, 5 insertions, 43 deletions
diff --git a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs index e7cd74a1f54..da88e5c698b 100644 --- a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs +++ b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs @@ -128,28 +128,20 @@ impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch { let mut patch = MirPatch::new(body); - let (second_discriminant_temp, second_operand) = if opt_data.need_hoist_discriminant { + let second_operand = if opt_data.need_hoist_discriminant { // create temp to store second discriminant in, `_s` in example above let second_discriminant_temp = patch.new_temp(opt_data.child_ty, opt_data.child_source.span); - patch.add_statement( - parent_end, - StatementKind::StorageLive(second_discriminant_temp), - ); - // create assignment of discriminant patch.add_assign( parent_end, Place::from(second_discriminant_temp), Rvalue::Discriminant(opt_data.child_place), ); - ( - Some(second_discriminant_temp), - Operand::Move(Place::from(second_discriminant_temp)), - ) + Operand::Move(Place::from(second_discriminant_temp)) } else { - (None, Operand::Copy(opt_data.child_place)) + Operand::Copy(opt_data.child_place) }; // create temp to store inequality comparison between the two discriminants, `_t` in @@ -157,7 +149,6 @@ impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch { let nequal = BinOp::Ne; let comp_res_type = nequal.ty(tcx, parent_ty, opt_data.child_ty); let comp_temp = patch.new_temp(comp_res_type, opt_data.child_source.span); - patch.add_statement(parent_end, StatementKind::StorageLive(comp_temp)); // create inequality comparison let comp_rvalue = @@ -193,42 +184,13 @@ impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch { let eq_bb = patch.new_block(eq_switch); // Jump to it on the basis of the inequality comparison - let mut true_case = opt_data.destination; - let mut false_case = eq_bb; - // Create an indirect BB to add `StorageDead` If the jump target is itself. - for bb in [&mut false_case, &mut true_case].into_iter() { - if *bb == parent { - *bb = patch.new_block(BasicBlockData::new( - Some(Terminator { - kind: TerminatorKind::Goto { target: parent }, - source_info: bbs[parent].terminator().source_info, - }), - bbs[parent].is_cleanup, - )); - } - } + let true_case = opt_data.destination; + let false_case = eq_bb; patch.patch_terminator( parent, TerminatorKind::if_(Operand::Move(Place::from(comp_temp)), true_case, false_case), ); - if let Some(second_discriminant_temp) = second_discriminant_temp { - // generate StorageDead for the second_discriminant_temp not in use anymore - patch.add_statement( - parent_end, - StatementKind::StorageDead(second_discriminant_temp), - ); - } - - // Generate a StorageDead for comp_temp in each of the targets, since we moved it into - // the switch - for bb in [false_case, true_case].into_iter() { - patch.add_statement( - Location { block: bb, statement_index: 0 }, - StatementKind::StorageDead(comp_temp), - ); - } - patch.apply(body); } |
