1
Fork 0

Reorder passes.

This commit is contained in:
Camille GILLOT 2023-07-22 15:34:54 +00:00
parent 31bc7e2c47
commit ed27cb0f49
7 changed files with 68 additions and 42 deletions

View file

@ -568,10 +568,11 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
&[
&check_alignment::CheckAlignment,
&lower_slice_len::LowerSliceLenCalls, // has to be done before inlining, otherwise actual call will be almost always inlined. Also simple, so can just do first
&unreachable_prop::UnreachablePropagation,
&uninhabited_enum_branching::UninhabitedEnumBranching,
&o1(simplify::SimplifyCfg::AfterUninhabitedEnumBranching),
&inline::Inline,
// Substitutions during inlining may introduce switch on enums with uninhabited branches.
&uninhabited_enum_branching::UninhabitedEnumBranching,
&unreachable_prop::UnreachablePropagation,
&o1(simplify::SimplifyCfg::AfterUninhabitedEnumBranching),
&remove_storage_markers::RemoveStorageMarkers,
&remove_zsts::RemoveZsts,
&normalize_array_len::NormalizeArrayLen, // has to run after `slice::len` lowering

View file

@ -2,7 +2,6 @@
//! when all of their successors are unreachable. This is achieved through a
//! post-order traversal of the blocks.
use crate::simplify;
use crate::MirPass;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_middle::mir::*;
@ -52,8 +51,6 @@ impl MirPass<'_> for UnreachablePropagation {
body.basic_blocks_mut()[bb].statements.clear();
}
let replaced = !replacements.is_empty();
for (bb, terminator_kind) in replacements {
if !tcx.consider_optimizing(|| {
format!("UnreachablePropagation {:?} ", body.source.def_id())
@ -64,9 +61,7 @@ impl MirPass<'_> for UnreachablePropagation {
body.basic_blocks_mut()[bb].terminator_mut().kind = terminator_kind;
}
if replaced {
simplify::remove_dead_blocks(body);
}
// Do not remove dead blocks, let `SimplifyCfg` do it.
}
}