Skip to content

Commit

Permalink
Auto merge of rust-lang#79084 - simonvandel:instcombine-perf, r=oli-obk
Browse files Browse the repository at this point in the history
Small perf changes for InstCombine
  • Loading branch information
bors committed Dec 29, 2020
2 parents d75f48e + 0010fc8 commit e2a2592
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions compiler/rustc_mir/src/transform/instcombine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ impl<'tcx> MirPass<'tcx> for InstCombine {
optimization_finder.optimizations
};

// Then carry out those optimizations.
MutVisitor::visit_body(&mut InstCombineVisitor { optimizations, tcx }, body);
if !optimizations.is_empty() {
// Then carry out those optimizations.
MutVisitor::visit_body(&mut InstCombineVisitor { optimizations, tcx }, body);
}
}
}

Expand Down Expand Up @@ -95,7 +97,7 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> {
}
}

self.super_rvalue(rvalue, location)
// We do not call super_rvalue as we are not interested in any other parts of the tree
}
}

Expand Down Expand Up @@ -299,7 +301,7 @@ impl Visitor<'tcx> for OptimizationFinder<'b, 'tcx> {

self.find_unneeded_equality_comparison(rvalue, location);

self.super_rvalue(rvalue, location)
// We do not call super_rvalue as we are not interested in any other parts of the tree
}
}

Expand All @@ -310,3 +312,21 @@ struct OptimizationList<'tcx> {
unneeded_equality_comparison: FxHashMap<Location, Operand<'tcx>>,
unneeded_deref: FxHashMap<Location, Place<'tcx>>,
}

impl<'tcx> OptimizationList<'tcx> {
fn is_empty(&self) -> bool {
match self {
OptimizationList {
and_stars,
arrays_lengths,
unneeded_equality_comparison,
unneeded_deref,
} => {
and_stars.is_empty()
&& arrays_lengths.is_empty()
&& unneeded_equality_comparison.is_empty()
&& unneeded_deref.is_empty()
}
}
}
}

0 comments on commit e2a2592

Please sign in to comment.