Only go through the body if something can be optimized

This commit is contained in:
Simon Vandel Sillesen 2020-11-15 22:34:50 +01:00
parent 307c60843c
commit 3d5a1e330f

View file

@ -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);
}
}
}
@ -296,3 +298,12 @@ 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 {
self.and_stars.is_empty()
&& self.arrays_lengths.is_empty()
&& self.unneeded_equality_comparison.is_empty()
&& self.unneeded_deref.is_empty()
}
}