Only go through the body if something can be optimized
This commit is contained in:
parent
307c60843c
commit
3d5a1e330f
1 changed files with 13 additions and 2 deletions
|
@ -29,10 +29,12 @@ impl<'tcx> MirPass<'tcx> for InstCombine {
|
||||||
optimization_finder.optimizations
|
optimization_finder.optimizations
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if !optimizations.is_empty() {
|
||||||
// Then carry out those optimizations.
|
// Then carry out those optimizations.
|
||||||
MutVisitor::visit_body(&mut InstCombineVisitor { optimizations, tcx }, body);
|
MutVisitor::visit_body(&mut InstCombineVisitor { optimizations, tcx }, body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct InstCombineVisitor<'tcx> {
|
pub struct InstCombineVisitor<'tcx> {
|
||||||
optimizations: OptimizationList<'tcx>,
|
optimizations: OptimizationList<'tcx>,
|
||||||
|
@ -296,3 +298,12 @@ struct OptimizationList<'tcx> {
|
||||||
unneeded_equality_comparison: FxHashMap<Location, Operand<'tcx>>,
|
unneeded_equality_comparison: FxHashMap<Location, Operand<'tcx>>,
|
||||||
unneeded_deref: FxHashMap<Location, Place<'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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue