Skip to content

Commit 3d5a1e3

Browse files
committed
Only go through the body if something can be optimized
1 parent 307c608 commit 3d5a1e3

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

compiler/rustc_mir/src/transform/instcombine.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ impl<'tcx> MirPass<'tcx> for InstCombine {
2929
optimization_finder.optimizations
3030
};
3131

32-
// Then carry out those optimizations.
33-
MutVisitor::visit_body(&mut InstCombineVisitor { optimizations, tcx }, body);
32+
if !optimizations.is_empty() {
33+
// Then carry out those optimizations.
34+
MutVisitor::visit_body(&mut InstCombineVisitor { optimizations, tcx }, body);
35+
}
3436
}
3537
}
3638

@@ -296,3 +298,12 @@ struct OptimizationList<'tcx> {
296298
unneeded_equality_comparison: FxHashMap<Location, Operand<'tcx>>,
297299
unneeded_deref: FxHashMap<Location, Place<'tcx>>,
298300
}
301+
302+
impl<'tcx> OptimizationList<'tcx> {
303+
fn is_empty(&self) -> bool {
304+
self.and_stars.is_empty()
305+
&& self.arrays_lengths.is_empty()
306+
&& self.unneeded_equality_comparison.is_empty()
307+
&& self.unneeded_deref.is_empty()
308+
}
309+
}

0 commit comments

Comments
 (0)