diff options
| author | bors <bors@rust-lang.org> | 2023-05-28 09:59:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-05-28 09:59:20 +0000 |
| commit | f59d577838fb0449a2b59ec3525a7fa91509e861 (patch) | |
| tree | e2e75787426055813a5e54321e91d9f6bef4d6ae /compiler/rustc_mir_transform | |
| parent | ddad0576caf8d0515ed453e04b468977c7d3dfc1 (diff) | |
| parent | 7e04c93493a2f9b4d508e6bbf08227407683d666 (diff) | |
| download | rust-f59d577838fb0449a2b59ec3525a7fa91509e861.tar.gz rust-f59d577838fb0449a2b59ec3525a7fa91509e861.zip | |
Auto merge of #112001 - saethlin:enable-matchbranchsimplification, r=cjgillot
Enable MatchBranchSimplification This pass is one of the small number of benefits from `-Zmir-opt-level=3` that has motivated rustc_codegen_cranelift to use it: https://github.com/rust-lang/rust/blob/19ed0aade60e1c1038fe40554bcd9d01b717effa/compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs#L244-L246 Cranelift's motivation for this is _runtime_ performance improvements in debug builds. Lifting this pass all the way to `-Zmir-opt-level=1` seems to come without significant perf overhead, so that's what I'm suggesting here.
Diffstat (limited to 'compiler/rustc_mir_transform')
| -rw-r--r-- | compiler/rustc_mir_transform/src/match_branches.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/compiler/rustc_mir_transform/src/match_branches.rs b/compiler/rustc_mir_transform/src/match_branches.rs index 59942dc76f9..6eb48498274 100644 --- a/compiler/rustc_mir_transform/src/match_branches.rs +++ b/compiler/rustc_mir_transform/src/match_branches.rs @@ -41,7 +41,7 @@ pub struct MatchBranchSimplification; impl<'tcx> MirPass<'tcx> for MatchBranchSimplification { fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() >= 3 + sess.mir_opt_level() >= 1 } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { @@ -62,7 +62,12 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification { .. } if targets.iter().len() == 1 => { let (value, target) = targets.iter().next().unwrap(); - if target == targets.otherwise() { + // We require that this block and the two possible target blocks all be + // distinct. + if target == targets.otherwise() + || bb_idx == target + || bb_idx == targets.otherwise() + { continue; } (discr, value, target, targets.otherwise()) |
