Perform instsimplify before inline to eliminate some trivial calls
This commit is contained in:
parent
80d8270d84
commit
ae681c940d
83 changed files with 226 additions and 182 deletions
|
@ -13,9 +13,25 @@ use rustc_target::spec::abi::Abi;
|
|||
use crate::simplify::simplify_duplicate_switch_targets;
|
||||
use crate::take_array;
|
||||
|
||||
pub struct InstSimplify;
|
||||
pub enum InstSimplify {
|
||||
BeforeInline,
|
||||
AfterSimplifyCfg,
|
||||
}
|
||||
|
||||
impl InstSimplify {
|
||||
pub fn name(&self) -> &'static str {
|
||||
match self {
|
||||
InstSimplify::BeforeInline => "InstSimplify-before-inline",
|
||||
InstSimplify::AfterSimplifyCfg => "InstSimplify-after-simplifycfg",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for InstSimplify {
|
||||
fn name(&self) -> &'static str {
|
||||
self.name()
|
||||
}
|
||||
|
||||
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
|
||||
sess.mir_opt_level() > 0
|
||||
}
|
||||
|
|
|
@ -571,6 +571,8 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
|||
// Has to be done before inlining, otherwise actual call will be almost always inlined.
|
||||
// Also simple, so can just do first
|
||||
&lower_slice_len::LowerSliceLenCalls,
|
||||
// Perform instsimplify before inline to eliminate some trivial calls (like clone shims).
|
||||
&instsimplify::InstSimplify::BeforeInline,
|
||||
// Perform inlining, which may add a lot of code.
|
||||
&inline::Inline,
|
||||
// Code from other crates may have storage markers, so this needs to happen after inlining.
|
||||
|
@ -590,7 +592,8 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
|||
&match_branches::MatchBranchSimplification,
|
||||
// inst combine is after MatchBranchSimplification to clean up Ne(_1, false)
|
||||
&multiple_return_terminators::MultipleReturnTerminators,
|
||||
&instsimplify::InstSimplify,
|
||||
// After simplifycfg, it allows us to discover new opportunities for peephole optimizations.
|
||||
&instsimplify::InstSimplify::AfterSimplifyCfg,
|
||||
&simplify::SimplifyLocals::BeforeConstProp,
|
||||
&dead_store_elimination::DeadStoreElimination::Initial,
|
||||
&gvn::GVN,
|
||||
|
|
|
@ -155,7 +155,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceKind<'tcx>) -> Body<
|
|||
&deref_separator::Derefer,
|
||||
&remove_noop_landing_pads::RemoveNoopLandingPads,
|
||||
&simplify::SimplifyCfg::MakeShim,
|
||||
&instsimplify::InstSimplify,
|
||||
&instsimplify::InstSimplify::BeforeInline,
|
||||
&abort_unwinding_calls::AbortUnwindingCalls,
|
||||
&add_call_guards::CriticalCallEdges,
|
||||
],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue