diff options
| author | bors <bors@rust-lang.org> | 2025-06-10 14:50:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-06-10 14:50:54 +0000 |
| commit | c6a955468b025dbe3d1de3e8f3e30496d1fb7f40 (patch) | |
| tree | e58b7afe3724cec095c13f9517e51baa8b4e635d /compiler/rustc_mir_transform | |
| parent | 100199c9aa50b0c47b37c9c86335d68b2a77b535 (diff) | |
| parent | 8c7faa6ed154893fdbfcb128055b593102b4c6db (diff) | |
| download | rust-c6a955468b025dbe3d1de3e8f3e30496d1fb7f40.tar.gz rust-c6a955468b025dbe3d1de3e8f3e30496d1fb7f40.zip | |
Auto merge of #141485 - dianqk:early_otherwise_branch_loop, r=oli-obk
mir-opt: Do not create storage marks in EarlyOtherwiseBranch Fixes #141212. The first commit add `StorageDead` by creating new indirect BB that makes CFG more complicated, but I think it's better to just not create storage marks. r? mir-opt
Diffstat (limited to 'compiler/rustc_mir_transform')
| -rw-r--r-- | compiler/rustc_mir_transform/src/early_otherwise_branch.rs | 32 |
1 files changed, 3 insertions, 29 deletions
diff --git a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs index c7feb9e949b..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 = @@ -200,23 +191,6 @@ impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch { 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].iter() { - patch.add_statement( - Location { block: *bb, statement_index: 0 }, - StatementKind::StorageDead(comp_temp), - ); - } - patch.apply(body); } |
