1
Fork 0

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:

19ed0aade6/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.
This commit is contained in:
bors 2023-05-28 09:59:20 +00:00
commit f59d577838
5 changed files with 50 additions and 7 deletions

View file

@ -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())

View file

@ -116,6 +116,7 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
}
impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
#[inline]
fn register_predicate_obligation(
&mut self,
infcx: &InferCtxt<'tcx>,