Skip to content

Small perf changes for InstCombine #79084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 29, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 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 @@ -81,7 +83,7 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> {
*rvalue = Rvalue::Use(Operand::Copy(place));
}

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 @@ -285,7 +287,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 @@ -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()
}
}