From 19cd9103d85f51fc84f262b979f2877525d6a124 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sun, 24 May 2020 18:22:04 +0200 Subject: [PATCH 01/15] Implement a destination propagation pass --- src/librustc_mir/dataflow/impls/mod.rs | 2 +- src/librustc_mir/lib.rs | 1 + src/librustc_mir/transform/dest_prop.rs | 731 ++++++++++++++++++++++++ src/librustc_mir/transform/mod.rs | 2 + src/librustc_mir/transform/nrvo.rs | 6 + 5 files changed, 741 insertions(+), 1 deletion(-) create mode 100644 src/librustc_mir/transform/dest_prop.rs diff --git a/src/librustc_mir/dataflow/impls/mod.rs b/src/librustc_mir/dataflow/impls/mod.rs index d5def0389126a..e29f5be70455a 100644 --- a/src/librustc_mir/dataflow/impls/mod.rs +++ b/src/librustc_mir/dataflow/impls/mod.rs @@ -192,7 +192,7 @@ impl<'a, 'tcx> HasMoveData<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> { /// `EverInitializedPlaces` tracks all places that might have ever been /// initialized upon reaching a particular point in the control flow -/// for a function, without an intervening `Storage Dead`. +/// for a function, without an intervening `StorageDead`. /// /// This dataflow is used to determine if an immutable local variable may /// be assigned to. diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 928d5bf88f2fc..77334f5585ef4 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -6,6 +6,7 @@ Rust MIR: a lowered representation of Rust. #![feature(nll)] #![feature(in_band_lifetimes)] +#![feature(bindings_after_at)] #![feature(bool_to_option)] #![feature(box_patterns)] #![feature(box_syntax)] diff --git a/src/librustc_mir/transform/dest_prop.rs b/src/librustc_mir/transform/dest_prop.rs new file mode 100644 index 0000000000000..2554f70c6056e --- /dev/null +++ b/src/librustc_mir/transform/dest_prop.rs @@ -0,0 +1,731 @@ +//! Propagates assignment destinations backwards in the CFG to eliminate redundant assignments. +//! +//! # Motivation +//! +//! MIR building can insert a lot of redundant copies, and Rust code in general often tends to move +//! values around a lot. The result is a lot of assignments of the form `dest = {move} src;` in MIR. +//! MIR building for constants in particular tends to create additional locals that are only used +//! inside a single block to shuffle a value around unnecessarily. +//! +//! LLVM by itself is not good enough at eliminating these redundant copies (eg. see +//! https://github.com/rust-lang/rust/issues/32966), so this leaves some performance on the table +//! that we can regain by implementing an optimization for removing these assign statements in rustc +//! itself. When this optimization runs fast enough, it can also speed up the constant evaluation +//! and code generation phases of rustc due to the reduced number of statements and locals. +//! +//! # The Optimization +//! +//! Conceptually, this optimization is "destination propagation". It is similar to the Named Return +//! Value Optimization, or NRVO, known from the C++ world, except that it isn't limited to return +//! values or the return place `_0`. On a very high level, independent of the actual implementation +//! details, it does the following: +//! +//! 1) Identify `dest = src;` statements that can be soundly eliminated. +//! 2) Replace all mentions of `src` with `dest` ("unifying" them and propagating the destination +//! backwards). +//! 3) Delete the `dest = src;` statement (by making it a `nop`). +//! +//! Step 1) is by far the hardest, so it is explained in more detail below. +//! +//! ## Soundness +//! +//! Given an `Assign` statement `dest = src;`, where `dest` is a `Place` and `src` is an `Rvalue`, +//! there are a few requirements that must hold for the optimization to be sound: +//! +//! * `dest` must not contain any *indirection* through a pointer. It must access part of the base +//! local. Otherwise it might point to arbitrary memory that is hard to track. +//! +//! It must also not contain any indexing projections, since those take an arbitrary `Local` as +//! the index, and that local might only be initialized shortly before `dest` is used. +//! +//! Subtle case: If `dest` is a, or projects through a union, then we have to make sure that there +//! remains an assignment to it, since that sets the "active field" of the union. But if `src` is +//! a ZST, it might not be initialized, so there might not be any use of it before the assignment, +//! and performing the optimization would simply delete the assignment, leaving `dest` +//! uninitialized. +//! +//! * `src` must be a bare `Local` without any indirections or field projections (FIXME: Why?). +//! It can be copied or moved by the assignment. +//! +//! * The `dest` and `src` locals must never be [*live*][liveness] at the same time. If they are, it +//! means that they both hold a (potentially different) value that is needed by a future use of +//! the locals. Unifying them would overwrite one of the values. +//! +//! Note that computing liveness of locals that have had their address taken is more difficult: +//! Short of doing full escape analysis on the address/pointer/reference, the pass would need to +//! assume that any operation that can potentially involve opaque user code (such as function +//! calls, destructors, and inline assembly) may access any local that had its address taken +//! before that point. +//! +//! Here, the first two conditions are simple structural requirements on the `Assign` statements +//! that can be trivially checked. The liveness requirement however is more difficult and costly to +//! check. +//! +//! ## Previous Work +//! +//! A [previous attempt] at implementing an optimization like this turned out to be a significant +//! regression in compiler performance. Fixing the regressions introduced a lot of undesirable +//! complexity to the implementation. +//! +//! A [subsequent approach] tried to avoid the costly computation by limiting itself to acyclic +//! CFGs, but still turned out to be far too costly to run due to suboptimal performance within +//! individual basic blocks, requiring a walk across the entire block for every assignment found +//! within the block. For the `tuple-stress` benchmark, which has 458745 statements in a single +//! block, this proved to be far too costly. +//! +//! Since the first attempt at this, the compiler has improved dramatically, and new analysis +//! frameworks have been added that should make this approach viable without requiring a limited +//! approach that only works for some classes of CFGs: +//! - rustc now has a powerful dataflow analysis framework that can handle forwards and backwards +//! analyses efficiently. +//! - Layout optimizations for generators have been added to improve code generation for +//! async/await, which are very similar in spirit to what this optimization does. Both walk the +//! MIR and record conflicting uses of locals in a `BitMatrix`. +//! +//! Also, rustc now has a simple NRVO pass (see `nrvo.rs`), which handles a subset of the cases that +//! this destination propagation pass handles, proving that similar optimizations can be performed +//! on MIR. +//! +//! ## Pre/Post Optimization +//! +//! It is recommended to run `SimplifyCfg` and then `SimplifyLocals` some time after this pass, as +//! it replaces the eliminated assign statements with `nop`s and leaves unused locals behind. +//! +//! [liveness]: https://en.wikipedia.org/wiki/Live_variable_analysis +//! [previous attempt]: https://github.com/rust-lang/rust/pull/47954 +//! [subsequent approach]: https://github.com/rust-lang/rust/pull/71003 + +use crate::dataflow::{self, Analysis}; +use crate::{ + transform::{MirPass, MirSource}, + util::{dump_mir, PassWhere}, +}; +use dataflow::{ + impls::{MaybeInitializedLocals, MaybeLiveLocals}, + ResultsCursor, +}; +use rustc_data_structures::unify::{InPlaceUnificationTable, UnifyKey}; +use rustc_index::{ + bit_set::{BitMatrix, BitSet}, + vec::IndexVec, +}; +use rustc_middle::mir::tcx::PlaceTy; +use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor}; +use rustc_middle::mir::{ + traversal, Body, Local, LocalKind, Location, Operand, Place, PlaceElem, Rvalue, Statement, + StatementKind, Terminator, TerminatorKind, +}; +use rustc_middle::ty::{self, Ty, TyCtxt}; + +pub struct DestinationPropagation; + +impl<'tcx> MirPass<'tcx> for DestinationPropagation { + fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) { + // Only run at mir-opt-level=2 or higher for now (we don't fix up debuginfo and remove + // storage statements at the moment). + if tcx.sess.opts.debugging_opts.mir_opt_level <= 1 { + return; + } + + let mut conflicts = Conflicts::build(tcx, body, source); + let mut replacements = Replacements::new(body.local_decls.len()); + for candidate @ CandidateAssignment { dest, src, loc } in find_candidates(tcx, body) { + // Merge locals that don't conflict. + if conflicts.contains(dest.local, src) { + debug!("at assignment {:?}, conflict {:?} vs. {:?}", loc, dest.local, src); + continue; + } + + if !tcx.consider_optimizing(|| { + format!("DestinationPropagation {:?} {:?}", source.def_id(), candidate) + }) { + break; + } + + if replacements.push(candidate).is_ok() { + conflicts.unify(candidate.src, candidate.dest.local); + } + } + + replacements.flatten(tcx); + + debug!("replacements {:?}", replacements.map); + + Replacer { tcx, replacements, place_elem_cache: Vec::new() }.visit_body(body); + + // FIXME fix debug info + } +} + +#[derive(Debug, Eq, PartialEq, Copy, Clone)] +struct UnifyLocal(Local); + +impl From for UnifyLocal { + fn from(l: Local) -> Self { + Self(l) + } +} + +impl UnifyKey for UnifyLocal { + type Value = (); + fn index(&self) -> u32 { + self.0.as_u32() + } + fn from_index(u: u32) -> Self { + Self(Local::from_u32(u)) + } + fn tag() -> &'static str { + "UnifyLocal" + } +} + +struct Replacements<'tcx> { + /// Maps locals to their replacement. + map: IndexVec>>, + + /// Whose locals' live ranges to kill. + kill: BitSet, + + /// Tracks locals that have already been merged together to prevent cycles. + unified_locals: InPlaceUnificationTable, +} + +impl Replacements<'tcx> { + fn new(locals: usize) -> Self { + Self { + map: IndexVec::from_elem_n(None, locals), + kill: BitSet::new_empty(locals), + unified_locals: { + let mut table = InPlaceUnificationTable::new(); + for local in 0..locals { + assert_eq!(table.new_key(()), UnifyLocal(Local::from_usize(local))); + } + table + }, + } + } + + fn push(&mut self, candidate: CandidateAssignment<'tcx>) -> Result<(), ()> { + if self.unified_locals.unioned(candidate.src, candidate.dest.local) { + // Candidate conflicts with previous replacement (ie. could possibly form a cycle and + // hang). + + let replacement = self.map[candidate.src].as_mut().unwrap(); + + // If the current replacement is for the same `dest` local, there are 2 or more + // equivalent `src = dest;` assignments. This is fine, the replacer will `nop` out all + // of them. + if replacement.local == candidate.dest.local { + assert_eq!(replacement.projection, candidate.dest.projection); + } + + // We still return `Err` in any case, as `src` and `dest` do not need to be unified + // *again*. + return Err(()); + } + + let entry = &mut self.map[candidate.src]; + if entry.is_some() { + // We're already replacing `src` with something else, so this candidate is out. + return Err(()); + } + + self.unified_locals.union(candidate.src, candidate.dest.local); + + *entry = Some(candidate.dest); + self.kill.insert(candidate.src); + self.kill.insert(candidate.dest.local); + + Ok(()) + } + + /// Applies the stored replacements to all replacements, until no replacements would result in + /// locals that need further replacements when applied. + fn flatten(&mut self, tcx: TyCtxt<'tcx>) { + // Note: This assumes that there are no cycles in the replacements, which is enforced via + // `self.unified_locals`. Otherwise this can cause an infinite loop. + + for local in self.map.indices() { + if let Some(replacement) = self.map[local] { + // Substitute the base local of `replacement` until fixpoint. + let mut base = replacement.local; + let mut reversed_projection_slices = Vec::with_capacity(1); + while let Some(replacement_for_replacement) = self.map[base] { + base = replacement_for_replacement.local; + reversed_projection_slices.push(replacement_for_replacement.projection); + } + + let projection: Vec<_> = reversed_projection_slices + .iter() + .rev() + .flat_map(|projs| projs.iter()) + .chain(replacement.projection.iter()) + .collect(); + let projection = tcx.intern_place_elems(&projection); + + // Replace with the final `Place`. + self.map[local] = Some(Place { local: base, projection }); + } + } + } + + fn for_src(&self, src: Local) -> Option<&Place<'tcx>> { + self.map[src].as_ref() + } +} + +struct Replacer<'tcx> { + tcx: TyCtxt<'tcx>, + replacements: Replacements<'tcx>, + place_elem_cache: Vec>, +} + +impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> { + fn tcx<'a>(&'a self) -> TyCtxt<'tcx> { + self.tcx + } + + fn visit_local(&mut self, local: &mut Local, context: PlaceContext, location: Location) { + if context.is_use() && self.replacements.for_src(*local).is_some() { + bug!( + "use of local {:?} should have been replaced by visit_place; context={:?}, loc={:?}", + local, + context, + location, + ); + } + } + + fn process_projection_elem( + &mut self, + elem: PlaceElem<'tcx>, + _: Location, + ) -> Option> { + match elem { + PlaceElem::Index(local) => { + if let Some(replacement) = self.replacements.for_src(local) { + bug!( + "cannot replace {:?} with {:?} in index projection {:?}", + local, + replacement, + elem, + ); + } else { + None + } + } + _ => None, + } + } + + fn visit_place(&mut self, place: &mut Place<'tcx>, context: PlaceContext, location: Location) { + if let Some(replacement) = self.replacements.for_src(place.local) { + // Rebase `place`s projections onto `replacement`'s. + self.place_elem_cache.clear(); + self.place_elem_cache.extend(replacement.projection.iter().chain(place.projection)); + let projection = self.tcx.intern_place_elems(&self.place_elem_cache); + let new_place = Place { local: replacement.local, projection }; + + debug!("Replacer: {:?} -> {:?}", place, new_place); + *place = new_place; + } + + self.super_place(place, context, location); + } + + fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) { + self.super_statement(statement, location); + + match &statement.kind { + // FIXME: Don't delete storage statements, merge the live ranges instead + StatementKind::StorageDead(local) | StatementKind::StorageLive(local) + if self.replacements.kill.contains(*local) => + { + statement.make_nop() + } + + StatementKind::Assign(box (dest, rvalue)) => { + match rvalue { + Rvalue::Use(Operand::Copy(place) | Operand::Move(place)) => { + // These might've been turned into self-assignments by the replacement + // (this includes the original statement we wanted to eliminate). + if dest == place { + debug!("{:?} turned into self-assignment, deleting", location); + statement.make_nop(); + } + } + _ => {} + } + } + + _ => {} + } + } +} + +struct Conflicts { + /// The conflict matrix. It is always symmetric and the adjacency matrix of the corresponding + /// conflict graph. + matrix: BitMatrix, + + /// Preallocated `BitSet` used by `unify`. + unify_cache: BitSet, +} + +impl Conflicts { + fn build<'tcx>(tcx: TyCtxt<'tcx>, body: &'_ Body<'tcx>, source: MirSource<'tcx>) -> Self { + // We don't have to look out for locals that have their address taken, since `find_candidates` + // already takes care of that. + + let mut conflicts = BitMatrix::from_row_n( + &BitSet::new_empty(body.local_decls.len()), + body.local_decls.len(), + ); + + let mut record_conflicts = + |init: &ResultsCursor<'_, '_, _>, live: &ResultsCursor<'_, '_, _>| { + let mut requires_storage = init.get().clone(); + requires_storage.intersect(live.get()); + + for local in requires_storage.iter() { + conflicts.union_row_with(&requires_storage, local); + } + }; + + let def_id = source.def_id(); + let mut init = MaybeInitializedLocals + .into_engine(tcx, body, def_id) + .iterate_to_fixpoint() + .into_results_cursor(body); + let mut live = MaybeLiveLocals + .into_engine(tcx, body, def_id) + .iterate_to_fixpoint() + .into_results_cursor(body); + + dump_mir( + tcx, + None, + "DestinationPropagation-dataflow", + &"", + source, + body, + |pass_where, w| { + match pass_where { + PassWhere::BeforeLocation(loc) => { + init.seek_before_primary_effect(loc); + live.seek_after_primary_effect(loc); + + writeln!(w, " // init: {:?}", init.get())?; + writeln!(w, " // live: {:?}", live.get())?; + } + PassWhere::AfterTerminator(bb) => { + let loc = body.terminator_loc(bb); + init.seek_after_primary_effect(loc); + live.seek_before_primary_effect(loc); + + writeln!(w, " // init: {:?}", init.get())?; + writeln!(w, " // live: {:?}", live.get())?; + } + + PassWhere::BeforeBlock(bb) => { + init.seek_to_block_start(bb); + live.seek_to_block_start(bb); + + writeln!(w, " // init: {:?}", init.get())?; + writeln!(w, " // live: {:?}", live.get())?; + } + + PassWhere::BeforeCFG | PassWhere::AfterCFG | PassWhere::AfterLocation(_) => {} + } + + Ok(()) + }, + ); + + // Visit only reachable basic blocks. The exact order is not important. + for (block, data) in traversal::preorder(body) { + // Observe the dataflow state *before* all possible locations (statement or terminator) in + // each basic block... + for statement_index in 0..=data.statements.len() { + let loc = Location { block, statement_index }; + trace!("record conflicts at {:?}", loc); + init.seek_before_primary_effect(loc); + live.seek_after_primary_effect(loc); + // FIXME: liveness is backwards, so this is slow + + record_conflicts(&init, &live); + } + + // ...and then observe the state *after* the terminator effect is applied. As long as + // neither `init` nor `borrowed` has a "before" effect, we will observe all possible + // dataflow states here or in the loop above. + trace!("record conflicts at end of {:?}", block); + init.seek_to_block_end(block); + live.seek_to_block_end(block); + record_conflicts(&init, &live); + } + + Self { matrix: conflicts, unify_cache: BitSet::new_empty(body.local_decls.len()) } + } + + fn contains(&self, a: Local, b: Local) -> bool { + self.matrix.contains(a, b) + } + + /// Merges the conflicts of `a` and `b`, so that each one inherits all conflicts of the other. + /// + /// This is called when the pass makes the decision to unify `a` and `b` (or parts of `a` and + /// `b`) and is needed to ensure that future unification decisions take potentially newly + /// introduced conflicts into account. + /// + /// For an example, assume we have locals `_0`, `_1`, `_2`, and `_3`. There are these conflicts: + /// + /// * `_0` <-> `_1` + /// * `_1` <-> `_2` + /// * `_3` <-> `_0` + /// + /// We then decide to merge `_2` with `_3` since they don't conflict. Then we decide to merge + /// `_2` with `_0`, which also doesn't have a conflict in the above list. However `_2` is now + /// `_3`, which does conflict with `_0`. + fn unify(&mut self, a: Local, b: Local) { + // FIXME: This might be somewhat slow. Conflict graphs are undirected, maybe we can use + // something with union-find to speed this up? + + // Make all locals that conflict with `a` also conflict with `b`, and vice versa. + self.unify_cache.clear(); + for conflicts_with_a in self.matrix.iter(a) { + self.unify_cache.insert(conflicts_with_a); + } + for conflicts_with_b in self.matrix.iter(b) { + self.unify_cache.insert(conflicts_with_b); + } + for conflicts_with_a_or_b in self.unify_cache.iter() { + // Set both `a` and `b` for this local's row. + self.matrix.insert(conflicts_with_a_or_b, a); + self.matrix.insert(conflicts_with_a_or_b, b); + } + + // Write the locals `a` conflicts with to `b`'s row. + self.matrix.union_rows(a, b); + // Write the locals `b` conflicts with to `a`'s row. + self.matrix.union_rows(b, a); + } +} + +/// A `dest = {move} src;` statement at `loc`. +/// +/// We want to consider merging `dest` and `src` due to this assignment. +#[derive(Debug, Copy, Clone)] +struct CandidateAssignment<'tcx> { + /// Does not contain indirection or indexing (so the only local it contains is the place base). + dest: Place<'tcx>, + src: Local, + loc: Location, +} + +/// Scans the MIR for assignments between locals that we might want to consider merging. +/// +/// This will filter out assignments that do not match the right form (as described in the top-level +/// comment) and also throw out assignments that involve a local that has its address taken or is +/// otherwise ineligible (eg. locals used as array indices are ignored because we cannot propagate +/// arbitrary places into array indices). +fn find_candidates<'a, 'tcx>( + tcx: TyCtxt<'tcx>, + body: &'a Body<'tcx>, +) -> Vec> { + struct FindAssignments<'a, 'tcx> { + tcx: TyCtxt<'tcx>, + body: &'a Body<'tcx>, + candidates: Vec>, + ever_borrowed_locals: BitSet, + locals_used_as_array_index: BitSet, + } + + impl<'a, 'tcx> Visitor<'tcx> for FindAssignments<'a, 'tcx> { + fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) { + if let StatementKind::Assign(box ( + dest, + Rvalue::Use(Operand::Copy(src) | Operand::Move(src)), + )) = &statement.kind + { + // `dest` must not have pointer indirection. + if dest.is_indirect() { + return; + } + + // `src` must be a plain local. + if !src.projection.is_empty() { + return; + } + + // Since we want to replace `src` with `dest`, `src` must not be required. + if is_local_required(src.local, self.body) { + return; + } + + // Can't optimize if both locals ever have their address taken (can introduce + // aliasing). + // FIXME: This can be smarter and take `StorageDead` into account (which + // invalidates borrows). + if self.ever_borrowed_locals.contains(dest.local) + && self.ever_borrowed_locals.contains(src.local) + { + return; + } + + assert_ne!(dest.local, src.local, "self-assignments are UB"); + + // We can't replace locals occurring in `PlaceElem::Index` for now. + if self.locals_used_as_array_index.contains(src.local) { + return; + } + + // Handle the "subtle case" described above by rejecting any `dest` that is or + // projects through a union. + let is_union = |ty: Ty<'_>| { + if let ty::Adt(def, _) = &ty.kind { + if def.is_union() { + return true; + } + } + + false + }; + let mut place_ty = PlaceTy::from_ty(self.body.local_decls[dest.local].ty); + if is_union(place_ty.ty) { + return; + } + for elem in dest.projection { + if let PlaceElem::Index(_) = elem { + // `dest` contains an indexing projection. + return; + } + + place_ty = place_ty.projection_ty(self.tcx, elem); + if is_union(place_ty.ty) { + return; + } + } + + self.candidates.push(CandidateAssignment { + dest: *dest, + src: src.local, + loc: location, + }); + } + } + } + + let mut visitor = FindAssignments { + tcx, + body, + candidates: Vec::new(), + ever_borrowed_locals: ever_borrowed_locals(body), + locals_used_as_array_index: locals_used_as_array_index(body), + }; + visitor.visit_body(body); + visitor.candidates +} + +/// Some locals are part of the function's interface and can not be removed. +/// +/// Note that these locals *can* still be merged with non-required locals by removing that other +/// local. +fn is_local_required(local: Local, body: &Body<'_>) -> bool { + match body.local_kind(local) { + LocalKind::Arg | LocalKind::ReturnPointer => true, + LocalKind::Var | LocalKind::Temp => false, + } +} + +/// Walks MIR to find all locals that have their address taken anywhere. +fn ever_borrowed_locals(body: &Body<'_>) -> BitSet { + struct BorrowCollector { + locals: BitSet, + } + + impl<'tcx> Visitor<'tcx> for BorrowCollector { + fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { + self.super_rvalue(rvalue, location); + + match rvalue { + Rvalue::AddressOf(_, borrowed_place) | Rvalue::Ref(_, _, borrowed_place) => { + if !borrowed_place.is_indirect() { + self.locals.insert(borrowed_place.local); + } + } + + Rvalue::Cast(..) + | Rvalue::Use(..) + | Rvalue::Repeat(..) + | Rvalue::Len(..) + | Rvalue::BinaryOp(..) + | Rvalue::CheckedBinaryOp(..) + | Rvalue::NullaryOp(..) + | Rvalue::UnaryOp(..) + | Rvalue::Discriminant(..) + | Rvalue::Aggregate(..) + | Rvalue::ThreadLocalRef(..) => {} + } + } + + fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) { + self.super_terminator(terminator, location); + + match terminator.kind { + TerminatorKind::Drop { location: dropped_place, .. } + | TerminatorKind::DropAndReplace { location: dropped_place, .. } => { + self.locals.insert(dropped_place.local); + } + + TerminatorKind::Abort + | TerminatorKind::Assert { .. } + | TerminatorKind::Call { .. } + | TerminatorKind::FalseEdges { .. } + | TerminatorKind::FalseUnwind { .. } + | TerminatorKind::GeneratorDrop + | TerminatorKind::Goto { .. } + | TerminatorKind::Resume + | TerminatorKind::Return + | TerminatorKind::SwitchInt { .. } + | TerminatorKind::Unreachable + | TerminatorKind::Yield { .. } + | TerminatorKind::InlineAsm { .. } => {} + } + } + } + + let mut visitor = BorrowCollector { locals: BitSet::new_empty(body.local_decls.len()) }; + visitor.visit_body(body); + visitor.locals +} + +/// `PlaceElem::Index` only stores a `Local`, so we can't replace that with a full `Place`. +/// +/// Collect locals used as indices so we don't generate candidates that are impossible to apply +/// later. +fn locals_used_as_array_index(body: &Body<'_>) -> BitSet { + struct IndexCollector { + locals: BitSet, + } + + impl<'tcx> Visitor<'tcx> for IndexCollector { + fn visit_projection_elem( + &mut self, + local: Local, + proj_base: &[PlaceElem<'tcx>], + elem: PlaceElem<'tcx>, + context: PlaceContext, + location: Location, + ) { + if let PlaceElem::Index(i) = elem { + self.locals.insert(i); + } + self.super_projection_elem(local, proj_base, elem, context, location); + } + } + + let mut visitor = IndexCollector { locals: BitSet::new_empty(body.local_decls.len()) }; + visitor.visit_body(body); + visitor.locals +} diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 846ed1f86d8d6..9de6c5331e962 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -23,6 +23,7 @@ pub mod cleanup_post_borrowck; pub mod const_prop; pub mod copy_prop; pub mod deaggregator; +pub mod dest_prop; pub mod dump_mir; pub mod elaborate_drops; pub mod generator; @@ -381,6 +382,7 @@ fn run_optimization_passes<'tcx>( &deaggregator::Deaggregator, &simplify_try::SimplifyArmIdentity, &simplify_try::SimplifyBranchSame, + &dest_prop::DestinationPropagation, ©_prop::CopyPropagation, &simplify_branches::SimplifyBranches::new("after-copy-prop"), &remove_noop_landing_pads::RemoveNoopLandingPads, diff --git a/src/librustc_mir/transform/nrvo.rs b/src/librustc_mir/transform/nrvo.rs index 1f3d7bb7cc6f4..6f094fdc448d5 100644 --- a/src/librustc_mir/transform/nrvo.rs +++ b/src/librustc_mir/transform/nrvo.rs @@ -36,6 +36,12 @@ impl<'tcx> MirPass<'tcx> for RenameReturnPlace { return; } + if tcx.sess.opts.debugging_opts.mir_opt_level >= 2 { + // The `DestinationPropagation` pass runs at level 2, so this pass is redundant (and + // fails some asserts). + return; + } + let returned_local = match local_eligible_for_nrvo(body) { Some(l) => l, None => { From 2080a936eee96a0d655c030932d4a8be9b79e7b8 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 25 May 2020 23:22:19 +0200 Subject: [PATCH 02/15] simplify_try: print dest_prop diff and bless The new diff is to convince me that this is correct and nothing funky is going on. --- src/test/mir-opt/simplify_try.rs | 2 + ...c.try_identity.DestinationPropagation.diff | 72 +++++++++++++++++++ ...ustc.try_identity.SimplifyLocals.after.mir | 4 +- 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 src/test/mir-opt/simplify_try/rustc.try_identity.DestinationPropagation.diff diff --git a/src/test/mir-opt/simplify_try.rs b/src/test/mir-opt/simplify_try.rs index 88a0451a76f67..40037e6cba3ed 100644 --- a/src/test/mir-opt/simplify_try.rs +++ b/src/test/mir-opt/simplify_try.rs @@ -10,3 +10,5 @@ fn try_identity(x: Result) -> Result { fn main() { let _ = try_identity(Ok(0)); } + +// EMIT_MIR rustc.try_identity.DestinationPropagation.diff diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.DestinationPropagation.diff b/src/test/mir-opt/simplify_try/rustc.try_identity.DestinationPropagation.diff new file mode 100644 index 0000000000000..ff84af7491dbf --- /dev/null +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.DestinationPropagation.diff @@ -0,0 +1,72 @@ +- // MIR for `try_identity` before DestinationPropagation ++ // MIR for `try_identity` after DestinationPropagation + + fn try_identity(_1: std::result::Result) -> std::result::Result { + debug x => _1; // in scope 0 at $DIR/simplify_try.rs:5:17: 5:18 + let mut _0: std::result::Result; // return place in scope 0 at $DIR/simplify_try.rs:5:41: 5:57 + let _2: u32; // in scope 0 at $DIR/simplify_try.rs:6:9: 6:10 + let mut _3: std::result::Result; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:15 + let mut _4: std::result::Result; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:14 + let mut _5: isize; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + let _6: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + let mut _7: !; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + let mut _8: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + let mut _9: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + let _10: u32; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:15 + let mut _11: u32; // in scope 0 at $DIR/simplify_try.rs:7:8: 7:9 + scope 1 { + debug y => _2; // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 + } + scope 2 { + debug err => _6; // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 + scope 3 { + scope 7 { + debug t => _9; // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL + } + scope 8 { + debug v => _8; // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:6:14: 6:15 + } + } + } + scope 4 { + debug val => _10; // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 + scope 5 { + } + } + scope 6 { +- debug self => _4; // in scope 6 at $SRC_DIR/libcore/result.rs:LL:COL ++ debug self => _0; // in scope 6 at $SRC_DIR/libcore/result.rs:LL:COL + } + + bb0: { + StorageLive(_2); // scope 0 at $DIR/simplify_try.rs:6:9: 6:10 +- StorageLive(_3); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 +- StorageLive(_4); // scope 0 at $DIR/simplify_try.rs:6:13: 6:14 +- _4 = _1; // scope 0 at $DIR/simplify_try.rs:6:13: 6:14 +- _3 = move _4; // scope 6 at $SRC_DIR/libcore/result.rs:LL:COL +- StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 +- _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 ++ nop; // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 ++ nop; // scope 0 at $DIR/simplify_try.rs:6:13: 6:14 ++ _0 = _1; // scope 0 at $DIR/simplify_try.rs:6:13: 6:14 ++ nop; // scope 6 at $SRC_DIR/libcore/result.rs:LL:COL ++ nop; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 ++ _5 = discriminant(_0); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + goto -> bb1; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + } + + bb1: { +- _0 = move _3; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 +- StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 ++ nop; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 ++ nop; // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 + StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 + goto -> bb2; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 + } + + bb2: { + return; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 + } + } + diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir index b12036f6a03e4..00be3e2e84f69 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir @@ -28,12 +28,12 @@ fn try_identity(_1: std::result::Result) -> std::result::Result _1; // in scope 6 at $SRC_DIR/libcore/result.rs:LL:COL + debug self => _0; // in scope 6 at $SRC_DIR/libcore/result.rs:LL:COL } bb0: { StorageLive(_2); // scope 0 at $DIR/simplify_try.rs:6:9: 6:10 - _0 = move _1; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 + _0 = _1; // scope 0 at $DIR/simplify_try.rs:6:13: 6:14 StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 return; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 } From 0d017cc3820eda1d789bd9168fb9b1d649f729b8 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 25 May 2020 23:22:47 +0200 Subject: [PATCH 03/15] simplify_try: clean up test --- src/test/mir-opt/simplify_try.rs | 3 +- ...c.try_identity.DestinationPropagation.diff | 70 ++++++------ ...ustc.try_identity.SimplifyArmIdentity.diff | 107 +++++++++--------- ....try_identity.SimplifyBranchSame.after.mir | 56 ++++----- ...ustc.try_identity.SimplifyLocals.after.mir | 28 ++--- 5 files changed, 131 insertions(+), 133 deletions(-) diff --git a/src/test/mir-opt/simplify_try.rs b/src/test/mir-opt/simplify_try.rs index 40037e6cba3ed..2249c90123ed1 100644 --- a/src/test/mir-opt/simplify_try.rs +++ b/src/test/mir-opt/simplify_try.rs @@ -1,6 +1,7 @@ // EMIT_MIR rustc.try_identity.SimplifyArmIdentity.diff // EMIT_MIR rustc.try_identity.SimplifyBranchSame.after.mir // EMIT_MIR rustc.try_identity.SimplifyLocals.after.mir +// EMIT_MIR rustc.try_identity.DestinationPropagation.diff fn try_identity(x: Result) -> Result { let y = x?; @@ -10,5 +11,3 @@ fn try_identity(x: Result) -> Result { fn main() { let _ = try_identity(Ok(0)); } - -// EMIT_MIR rustc.try_identity.DestinationPropagation.diff diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.DestinationPropagation.diff b/src/test/mir-opt/simplify_try/rustc.try_identity.DestinationPropagation.diff index ff84af7491dbf..c3e503bf2c686 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.DestinationPropagation.diff +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.DestinationPropagation.diff @@ -2,35 +2,35 @@ + // MIR for `try_identity` after DestinationPropagation fn try_identity(_1: std::result::Result) -> std::result::Result { - debug x => _1; // in scope 0 at $DIR/simplify_try.rs:5:17: 5:18 - let mut _0: std::result::Result; // return place in scope 0 at $DIR/simplify_try.rs:5:41: 5:57 - let _2: u32; // in scope 0 at $DIR/simplify_try.rs:6:9: 6:10 - let mut _3: std::result::Result; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:15 - let mut _4: std::result::Result; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:14 - let mut _5: isize; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let _6: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let mut _7: !; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let mut _8: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let mut _9: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let _10: u32; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:15 - let mut _11: u32; // in scope 0 at $DIR/simplify_try.rs:7:8: 7:9 + debug x => _1; // in scope 0 at $DIR/simplify_try.rs:6:17: 6:18 + let mut _0: std::result::Result; // return place in scope 0 at $DIR/simplify_try.rs:6:41: 6:57 + let _2: u32; // in scope 0 at $DIR/simplify_try.rs:7:9: 7:10 + let mut _3: std::result::Result; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:15 + let mut _4: std::result::Result; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:14 + let mut _5: isize; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let _6: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let mut _7: !; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let mut _8: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let mut _9: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let _10: u32; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:15 + let mut _11: u32; // in scope 0 at $DIR/simplify_try.rs:8:8: 8:9 scope 1 { - debug y => _2; // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 + debug y => _2; // in scope 1 at $DIR/simplify_try.rs:7:9: 7:10 } scope 2 { - debug err => _6; // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 + debug err => _6; // in scope 2 at $DIR/simplify_try.rs:7:14: 7:15 scope 3 { scope 7 { debug t => _9; // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL } scope 8 { debug v => _8; // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:6:14: 6:15 + let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:7:14: 7:15 } } } scope 4 { - debug val => _10; // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 + debug val => _10; // in scope 4 at $DIR/simplify_try.rs:7:13: 7:15 scope 5 { } } @@ -40,33 +40,33 @@ } bb0: { - StorageLive(_2); // scope 0 at $DIR/simplify_try.rs:6:9: 6:10 -- StorageLive(_3); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 -- StorageLive(_4); // scope 0 at $DIR/simplify_try.rs:6:13: 6:14 -- _4 = _1; // scope 0 at $DIR/simplify_try.rs:6:13: 6:14 + StorageLive(_2); // scope 0 at $DIR/simplify_try.rs:7:9: 7:10 +- StorageLive(_3); // scope 0 at $DIR/simplify_try.rs:7:13: 7:15 +- StorageLive(_4); // scope 0 at $DIR/simplify_try.rs:7:13: 7:14 +- _4 = _1; // scope 0 at $DIR/simplify_try.rs:7:13: 7:14 - _3 = move _4; // scope 6 at $SRC_DIR/libcore/result.rs:LL:COL -- StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 -- _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 -+ nop; // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 -+ nop; // scope 0 at $DIR/simplify_try.rs:6:13: 6:14 -+ _0 = _1; // scope 0 at $DIR/simplify_try.rs:6:13: 6:14 +- StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 +- _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 ++ nop; // scope 0 at $DIR/simplify_try.rs:7:13: 7:15 ++ nop; // scope 0 at $DIR/simplify_try.rs:7:13: 7:14 ++ _0 = _1; // scope 0 at $DIR/simplify_try.rs:7:13: 7:14 + nop; // scope 6 at $SRC_DIR/libcore/result.rs:LL:COL -+ nop; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 -+ _5 = discriminant(_0); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - goto -> bb1; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 ++ nop; // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 ++ _5 = discriminant(_0); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + goto -> bb1; // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 } bb1: { -- _0 = move _3; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 -- StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 -+ nop; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 -+ nop; // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 - StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 - goto -> bb2; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 +- _0 = move _3; // scope 1 at $DIR/simplify_try.rs:8:5: 8:10 +- StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:7:15: 7:16 ++ nop; // scope 1 at $DIR/simplify_try.rs:8:5: 8:10 ++ nop; // scope 0 at $DIR/simplify_try.rs:7:15: 7:16 + StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:9:1: 9:2 + goto -> bb2; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2 } bb2: { - return; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 + return; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2 } } diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff index 97050122ca96e..143e7c8c27f38 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff @@ -1,93 +1,92 @@ - // MIR for `try_identity` before SimplifyArmIdentity + // MIR for `try_identity` after SimplifyArmIdentity - + fn try_identity(_1: std::result::Result) -> std::result::Result { - debug x => _1; // in scope 0 at $DIR/simplify_try.rs:5:17: 5:18 - let mut _0: std::result::Result; // return place in scope 0 at $DIR/simplify_try.rs:5:41: 5:57 - let _2: u32; // in scope 0 at $DIR/simplify_try.rs:6:9: 6:10 - let mut _3: std::result::Result; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:15 - let mut _4: std::result::Result; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:14 - let mut _5: isize; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let _6: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let mut _7: !; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let mut _8: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let mut _9: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let _10: u32; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:15 - let mut _11: u32; // in scope 0 at $DIR/simplify_try.rs:7:8: 7:9 + debug x => _1; // in scope 0 at $DIR/simplify_try.rs:6:17: 6:18 + let mut _0: std::result::Result; // return place in scope 0 at $DIR/simplify_try.rs:6:41: 6:57 + let _2: u32; // in scope 0 at $DIR/simplify_try.rs:7:9: 7:10 + let mut _3: std::result::Result; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:15 + let mut _4: std::result::Result; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:14 + let mut _5: isize; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let _6: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let mut _7: !; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let mut _8: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let mut _9: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let _10: u32; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:15 + let mut _11: u32; // in scope 0 at $DIR/simplify_try.rs:8:8: 8:9 scope 1 { - debug y => _2; // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 + debug y => _2; // in scope 1 at $DIR/simplify_try.rs:7:9: 7:10 } scope 2 { - debug err => _6; // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 + debug err => _6; // in scope 2 at $DIR/simplify_try.rs:7:14: 7:15 scope 3 { scope 7 { debug t => _9; // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL } scope 8 { debug v => _8; // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:6:14: 6:15 + let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:7:14: 7:15 } } } scope 4 { - debug val => _10; // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 + debug val => _10; // in scope 4 at $DIR/simplify_try.rs:7:13: 7:15 scope 5 { } } scope 6 { debug self => _4; // in scope 6 at $SRC_DIR/libcore/result.rs:LL:COL } - + bb0: { - StorageLive(_2); // scope 0 at $DIR/simplify_try.rs:6:9: 6:10 - StorageLive(_3); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 - StorageLive(_4); // scope 0 at $DIR/simplify_try.rs:6:13: 6:14 - _4 = _1; // scope 0 at $DIR/simplify_try.rs:6:13: 6:14 + StorageLive(_2); // scope 0 at $DIR/simplify_try.rs:7:9: 7:10 + StorageLive(_3); // scope 0 at $DIR/simplify_try.rs:7:13: 7:15 + StorageLive(_4); // scope 0 at $DIR/simplify_try.rs:7:13: 7:14 + _4 = _1; // scope 0 at $DIR/simplify_try.rs:7:13: 7:14 _3 = move _4; // scope 6 at $SRC_DIR/libcore/result.rs:LL:COL - StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - switchInt(move _5) -> [0isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + switchInt(move _5) -> [0isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 } - + bb1: { -- StorageLive(_10); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 -- _10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 -- _2 = _10; // scope 5 at $DIR/simplify_try.rs:6:13: 6:15 -- StorageDead(_10); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 -+ _0 = move _3; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 - StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 -- StorageLive(_11); // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 -- _11 = _2; // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 -- ((_0 as Ok).0: u32) = move _11; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 -- discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 -- StorageDead(_11); // scope 1 at $DIR/simplify_try.rs:7:9: 7:10 - StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 - goto -> bb3; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 +- StorageLive(_10); // scope 0 at $DIR/simplify_try.rs:7:13: 7:15 +- _10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:7:13: 7:15 +- _2 = _10; // scope 5 at $DIR/simplify_try.rs:7:13: 7:15 +- StorageDead(_10); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 ++ _0 = move _3; // scope 1 at $DIR/simplify_try.rs:8:5: 8:10 + StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:7:15: 7:16 +- StorageLive(_11); // scope 1 at $DIR/simplify_try.rs:8:8: 8:9 +- _11 = _2; // scope 1 at $DIR/simplify_try.rs:8:8: 8:9 +- ((_0 as Ok).0: u32) = move _11; // scope 1 at $DIR/simplify_try.rs:8:5: 8:10 +- discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:8:5: 8:10 +- StorageDead(_11); // scope 1 at $DIR/simplify_try.rs:8:9: 8:10 + StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:9:1: 9:2 + goto -> bb3; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2 } - + bb2: { -- StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 -- _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 -- StorageLive(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 -- StorageLive(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 -- _9 = _6; // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 +- StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 +- _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 +- StorageLive(_8); // scope 3 at $DIR/simplify_try.rs:7:14: 7:15 +- StorageLive(_9); // scope 3 at $DIR/simplify_try.rs:7:14: 7:15 +- _9 = _6; // scope 3 at $DIR/simplify_try.rs:7:14: 7:15 - _8 = move _9; // scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL -- StorageDead(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 +- StorageDead(_9); // scope 3 at $DIR/simplify_try.rs:7:14: 7:15 - StorageLive(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - _12 = move _8; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - ((_0 as Err).0: i32) = move _12; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - discriminant(_0) = 1; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - StorageDead(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL -- StorageDead(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 -- StorageDead(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 +- StorageDead(_8); // scope 3 at $DIR/simplify_try.rs:7:14: 7:15 +- StorageDead(_6); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + _0 = move _3; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 - StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 - goto -> bb3; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:7:15: 7:16 + StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:9:1: 9:2 + goto -> bb3; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2 } - + bb3: { - return; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 + return; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2 } } - diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir index be61e5e2a9fff..9169abcdbacdc 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir @@ -1,35 +1,35 @@ // MIR for `try_identity` after SimplifyBranchSame fn try_identity(_1: std::result::Result) -> std::result::Result { - debug x => _1; // in scope 0 at $DIR/simplify_try.rs:5:17: 5:18 - let mut _0: std::result::Result; // return place in scope 0 at $DIR/simplify_try.rs:5:41: 5:57 - let _2: u32; // in scope 0 at $DIR/simplify_try.rs:6:9: 6:10 - let mut _3: std::result::Result; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:15 - let mut _4: std::result::Result; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:14 - let mut _5: isize; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let _6: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let mut _7: !; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let mut _8: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let mut _9: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let _10: u32; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:15 - let mut _11: u32; // in scope 0 at $DIR/simplify_try.rs:7:8: 7:9 + debug x => _1; // in scope 0 at $DIR/simplify_try.rs:6:17: 6:18 + let mut _0: std::result::Result; // return place in scope 0 at $DIR/simplify_try.rs:6:41: 6:57 + let _2: u32; // in scope 0 at $DIR/simplify_try.rs:7:9: 7:10 + let mut _3: std::result::Result; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:15 + let mut _4: std::result::Result; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:14 + let mut _5: isize; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let _6: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let mut _7: !; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let mut _8: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let mut _9: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let _10: u32; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:15 + let mut _11: u32; // in scope 0 at $DIR/simplify_try.rs:8:8: 8:9 scope 1 { - debug y => _2; // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 + debug y => _2; // in scope 1 at $DIR/simplify_try.rs:7:9: 7:10 } scope 2 { - debug err => _6; // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 + debug err => _6; // in scope 2 at $DIR/simplify_try.rs:7:14: 7:15 scope 3 { scope 7 { debug t => _9; // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL } scope 8 { debug v => _8; // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:6:14: 6:15 + let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:7:14: 7:15 } } } scope 4 { - debug val => _10; // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 + debug val => _10; // in scope 4 at $DIR/simplify_try.rs:7:13: 7:15 scope 5 { } } @@ -38,24 +38,24 @@ fn try_identity(_1: std::result::Result) -> std::result::Result bb1; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + goto -> bb1; // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 } bb1: { - _0 = move _3; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 - StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 - StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 - goto -> bb2; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 + _0 = move _3; // scope 1 at $DIR/simplify_try.rs:8:5: 8:10 + StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:7:15: 7:16 + StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:9:1: 9:2 + goto -> bb2; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2 } bb2: { - return; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 + return; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2 } } diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir index 00be3e2e84f69..1cc6f7ce7ff02 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir @@ -1,18 +1,18 @@ // MIR for `try_identity` after SimplifyLocals fn try_identity(_1: std::result::Result) -> std::result::Result { - debug x => _1; // in scope 0 at $DIR/simplify_try.rs:5:17: 5:18 - let mut _0: std::result::Result; // return place in scope 0 at $DIR/simplify_try.rs:5:41: 5:57 - let _2: u32; // in scope 0 at $DIR/simplify_try.rs:6:9: 6:10 - let _3: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let mut _4: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let mut _5: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let _6: u32; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:15 + debug x => _1; // in scope 0 at $DIR/simplify_try.rs:6:17: 6:18 + let mut _0: std::result::Result; // return place in scope 0 at $DIR/simplify_try.rs:6:41: 6:57 + let _2: u32; // in scope 0 at $DIR/simplify_try.rs:7:9: 7:10 + let _3: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let mut _4: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let mut _5: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15 + let _6: u32; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:15 scope 1 { - debug y => _2; // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 + debug y => _2; // in scope 1 at $DIR/simplify_try.rs:7:9: 7:10 } scope 2 { - debug err => _3; // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 + debug err => _3; // in scope 2 at $DIR/simplify_try.rs:7:14: 7:15 scope 3 { scope 7 { debug t => _5; // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL @@ -23,7 +23,7 @@ fn try_identity(_1: std::result::Result) -> std::result::Result _6; // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 + debug val => _6; // in scope 4 at $DIR/simplify_try.rs:7:13: 7:15 scope 5 { } } @@ -32,9 +32,9 @@ fn try_identity(_1: std::result::Result) -> std::result::Result Date: Mon, 25 May 2020 23:37:10 +0200 Subject: [PATCH 04/15] Make nrvo-simple set mir-opt-level=1 The additional copies are due to the lack of copy propagation --- src/test/mir-opt/nrvo-simple.rs | 2 + .../rustc.nrvo.RenameReturnPlace.diff | 64 ++++++++++--------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/test/mir-opt/nrvo-simple.rs b/src/test/mir-opt/nrvo-simple.rs index bf3a0efeada0b..abdb7b633864f 100644 --- a/src/test/mir-opt/nrvo-simple.rs +++ b/src/test/mir-opt/nrvo-simple.rs @@ -1,3 +1,5 @@ +// compile-flags: -Zmir-opt-level=1 + // EMIT_MIR rustc.nrvo.RenameReturnPlace.diff fn nrvo(init: fn(&mut [u8; 1024])) -> [u8; 1024] { let mut buf = [0; 1024]; diff --git a/src/test/mir-opt/nrvo-simple/rustc.nrvo.RenameReturnPlace.diff b/src/test/mir-opt/nrvo-simple/rustc.nrvo.RenameReturnPlace.diff index 4511470f3a50f..05c09f222aeb9 100644 --- a/src/test/mir-opt/nrvo-simple/rustc.nrvo.RenameReturnPlace.diff +++ b/src/test/mir-opt/nrvo-simple/rustc.nrvo.RenameReturnPlace.diff @@ -1,46 +1,48 @@ - // MIR for `nrvo` before RenameReturnPlace + // MIR for `nrvo` after RenameReturnPlace - + fn nrvo(_1: for<'r> fn(&'r mut [u8; 1024])) -> [u8; 1024] { - debug init => _1; // in scope 0 at $DIR/nrvo-simple.rs:2:9: 2:13 -- let mut _0: [u8; 1024]; // return place in scope 0 at $DIR/nrvo-simple.rs:2:39: 2:49 -+ let mut _0: [u8; 1024]; // return place in scope 0 at $DIR/nrvo-simple.rs:3:9: 3:16 - let mut _2: [u8; 1024]; // in scope 0 at $DIR/nrvo-simple.rs:3:9: 3:16 - let _3: (); // in scope 0 at $DIR/nrvo-simple.rs:4:5: 4:19 - let mut _4: for<'r> fn(&'r mut [u8; 1024]); // in scope 0 at $DIR/nrvo-simple.rs:4:5: 4:9 - let mut _5: &mut [u8; 1024]; // in scope 0 at $DIR/nrvo-simple.rs:4:10: 4:18 - let mut _6: &mut [u8; 1024]; // in scope 0 at $DIR/nrvo-simple.rs:4:10: 4:18 + debug init => _1; // in scope 0 at $DIR/nrvo-simple.rs:4:9: 4:13 +- let mut _0: [u8; 1024]; // return place in scope 0 at $DIR/nrvo-simple.rs:4:39: 4:49 ++ let mut _0: [u8; 1024]; // return place in scope 0 at $DIR/nrvo-simple.rs:5:9: 5:16 + let mut _2: [u8; 1024]; // in scope 0 at $DIR/nrvo-simple.rs:5:9: 5:16 + let _3: (); // in scope 0 at $DIR/nrvo-simple.rs:6:5: 6:19 + let mut _4: for<'r> fn(&'r mut [u8; 1024]); // in scope 0 at $DIR/nrvo-simple.rs:6:5: 6:9 + let mut _5: &mut [u8; 1024]; // in scope 0 at $DIR/nrvo-simple.rs:6:10: 6:18 + let mut _6: &mut [u8; 1024]; // in scope 0 at $DIR/nrvo-simple.rs:6:10: 6:18 scope 1 { -- debug buf => _2; // in scope 1 at $DIR/nrvo-simple.rs:3:9: 3:16 -+ debug buf => _0; // in scope 1 at $DIR/nrvo-simple.rs:3:9: 3:16 +- debug buf => _2; // in scope 1 at $DIR/nrvo-simple.rs:5:9: 5:16 ++ debug buf => _0; // in scope 1 at $DIR/nrvo-simple.rs:5:9: 5:16 } - + bb0: { -- StorageLive(_2); // scope 0 at $DIR/nrvo-simple.rs:3:9: 3:16 -- _2 = [const 0u8; 1024]; // scope 0 at $DIR/nrvo-simple.rs:3:19: 3:28 -+ _0 = [const 0u8; 1024]; // scope 0 at $DIR/nrvo-simple.rs:3:19: 3:28 +- StorageLive(_2); // scope 0 at $DIR/nrvo-simple.rs:5:9: 5:16 +- _2 = [const 0u8; 1024]; // scope 0 at $DIR/nrvo-simple.rs:5:19: 5:28 ++ _0 = [const 0u8; 1024]; // scope 0 at $DIR/nrvo-simple.rs:5:19: 5:28 // ty::Const // + ty: u8 // + val: Value(Scalar(0x00)) // mir::Constant - // + span: $DIR/nrvo-simple.rs:3:20: 3:21 + // + span: $DIR/nrvo-simple.rs:5:20: 5:21 // + literal: Const { ty: u8, val: Value(Scalar(0x00)) } - StorageLive(_3); // scope 1 at $DIR/nrvo-simple.rs:4:5: 4:19 - StorageLive(_5); // scope 1 at $DIR/nrvo-simple.rs:4:10: 4:18 - StorageLive(_6); // scope 1 at $DIR/nrvo-simple.rs:4:10: 4:18 -- _6 = &mut _2; // scope 1 at $DIR/nrvo-simple.rs:4:10: 4:18 -+ _6 = &mut _0; // scope 1 at $DIR/nrvo-simple.rs:4:10: 4:18 - _5 = &mut (*_6); // scope 1 at $DIR/nrvo-simple.rs:4:10: 4:18 - _3 = move _1(move _5) -> bb1; // scope 1 at $DIR/nrvo-simple.rs:4:5: 4:19 + StorageLive(_3); // scope 1 at $DIR/nrvo-simple.rs:6:5: 6:19 + StorageLive(_4); // scope 1 at $DIR/nrvo-simple.rs:6:5: 6:9 + _4 = _1; // scope 1 at $DIR/nrvo-simple.rs:6:5: 6:9 + StorageLive(_5); // scope 1 at $DIR/nrvo-simple.rs:6:10: 6:18 + StorageLive(_6); // scope 1 at $DIR/nrvo-simple.rs:6:10: 6:18 +- _6 = &mut _2; // scope 1 at $DIR/nrvo-simple.rs:6:10: 6:18 ++ _6 = &mut _0; // scope 1 at $DIR/nrvo-simple.rs:6:10: 6:18 + _5 = move _6; // scope 1 at $DIR/nrvo-simple.rs:6:10: 6:18 + _3 = move _4(move _5) -> bb1; // scope 1 at $DIR/nrvo-simple.rs:6:5: 6:19 } - + bb1: { - StorageDead(_5); // scope 1 at $DIR/nrvo-simple.rs:4:18: 4:19 - StorageDead(_6); // scope 1 at $DIR/nrvo-simple.rs:4:19: 4:20 - StorageDead(_3); // scope 1 at $DIR/nrvo-simple.rs:4:19: 4:20 -- _0 = _2; // scope 1 at $DIR/nrvo-simple.rs:5:5: 5:8 -- StorageDead(_2); // scope 0 at $DIR/nrvo-simple.rs:6:1: 6:2 - return; // scope 0 at $DIR/nrvo-simple.rs:6:2: 6:2 + StorageDead(_5); // scope 1 at $DIR/nrvo-simple.rs:6:18: 6:19 + StorageDead(_4); // scope 1 at $DIR/nrvo-simple.rs:6:18: 6:19 + StorageDead(_6); // scope 1 at $DIR/nrvo-simple.rs:6:19: 6:20 + StorageDead(_3); // scope 1 at $DIR/nrvo-simple.rs:6:19: 6:20 +- _0 = _2; // scope 1 at $DIR/nrvo-simple.rs:7:5: 7:8 +- StorageDead(_2); // scope 0 at $DIR/nrvo-simple.rs:8:1: 8:2 + return; // scope 0 at $DIR/nrvo-simple.rs:8:2: 8:2 } } - From 8f77e36e18c139946d15f82b49136a5f6fa11142 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 26 May 2020 00:03:25 +0200 Subject: [PATCH 05/15] Bless mir-opt tests --- .../32bit/rustc.main.ConstProp.after.mir | 28 ++++++++-------- .../64bit/rustc.main.ConstProp.after.mir | 32 +++++++++---------- .../32bit/rustc.main.ConstProp.after.mir | 26 +++++++-------- .../64bit/rustc.main.ConstProp.after.mir | 28 ++++++++-------- .../32bit/rustc.main.ConstProp.after.mir | 4 +-- .../64bit/rustc.main.ConstProp.after.mir | 4 +-- .../rustc.test.CopyPropagation.diff | 15 +++------ .../rustc.arg_src.CopyPropagation.diff | 10 +++--- .../rustc.baz.CopyPropagation.diff | 8 ++--- .../rustc.foo.CopyPropagation.diff | 8 ++--- .../rustc.foo.Inline.after.mir | 20 +++++------- 11 files changed, 87 insertions(+), 96 deletions(-) diff --git a/src/test/mir-opt/const_allocation/32bit/rustc.main.ConstProp.after.mir b/src/test/mir-opt/const_allocation/32bit/rustc.main.ConstProp.after.mir index 30a383fd162b2..b5cf4e08460f8 100644 --- a/src/test/mir-opt/const_allocation/32bit/rustc.main.ConstProp.after.mir +++ b/src/test/mir-opt/const_allocation/32bit/rustc.main.ConstProp.after.mir @@ -30,42 +30,42 @@ fn main() -> () { } alloc0 (static: FOO, size: 8, align: 4) { - ╾─alloc17─╼ 03 00 00 00 │ ╾──╼.... + ╾─alloc14─╼ 03 00 00 00 │ ╾──╼.... } -alloc17 (size: 48, align: 4) { +alloc14 (size: 48, align: 4) { 0x00 │ 00 00 00 00 __ __ __ __ ╾─alloc4──╼ 00 00 00 00 │ ....░░░░╾──╼.... - 0x10 │ 00 00 00 00 __ __ __ __ ╾─alloc8──╼ 02 00 00 00 │ ....░░░░╾──╼.... - 0x20 │ 01 00 00 00 2a 00 00 00 ╾─alloc13─╼ 03 00 00 00 │ ....*...╾──╼.... + 0x10 │ 00 00 00 00 __ __ __ __ ╾─alloc7──╼ 02 00 00 00 │ ....░░░░╾──╼.... + 0x20 │ 01 00 00 00 2a 00 00 00 ╾─alloc11─╼ 03 00 00 00 │ ....*...╾──╼.... } alloc4 (size: 0, align: 4) {} -alloc8 (size: 16, align: 4) { - ╾─alloc7──╼ 03 00 00 00 ╾─alloc9──╼ 03 00 00 00 │ ╾──╼....╾──╼.... +alloc7 (size: 16, align: 4) { + ╾─alloc6──╼ 03 00 00 00 ╾─alloc8──╼ 03 00 00 00 │ ╾──╼....╾──╼.... } -alloc7 (size: 3, align: 1) { +alloc6 (size: 3, align: 1) { 66 6f 6f │ foo } -alloc9 (size: 3, align: 1) { +alloc8 (size: 3, align: 1) { 62 61 72 │ bar } -alloc13 (size: 24, align: 4) { - 0x00 │ ╾─alloc12─╼ 03 00 00 00 ╾─alloc14─╼ 03 00 00 00 │ ╾──╼....╾──╼.... - 0x10 │ ╾─alloc15─╼ 04 00 00 00 │ ╾──╼.... +alloc11 (size: 24, align: 4) { + 0x00 │ ╾─alloc10─╼ 03 00 00 00 ╾─alloc12─╼ 03 00 00 00 │ ╾──╼....╾──╼.... + 0x10 │ ╾─alloc13─╼ 04 00 00 00 │ ╾──╼.... } -alloc12 (size: 3, align: 1) { +alloc10 (size: 3, align: 1) { 6d 65 68 │ meh } -alloc14 (size: 3, align: 1) { +alloc12 (size: 3, align: 1) { 6d 6f 70 │ mop } -alloc15 (size: 4, align: 1) { +alloc13 (size: 4, align: 1) { 6d c3 b6 70 │ m..p } diff --git a/src/test/mir-opt/const_allocation/64bit/rustc.main.ConstProp.after.mir b/src/test/mir-opt/const_allocation/64bit/rustc.main.ConstProp.after.mir index 5fa54ae5a58ec..b62cb50e77386 100644 --- a/src/test/mir-opt/const_allocation/64bit/rustc.main.ConstProp.after.mir +++ b/src/test/mir-opt/const_allocation/64bit/rustc.main.ConstProp.after.mir @@ -30,46 +30,46 @@ fn main() -> () { } alloc0 (static: FOO, size: 16, align: 8) { - ╾───────alloc17───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........ + ╾───────alloc14───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........ } -alloc17 (size: 72, align: 8) { +alloc14 (size: 72, align: 8) { 0x00 │ 00 00 00 00 __ __ __ __ ╾───────alloc4────────╼ │ ....░░░░╾──────╼ 0x10 │ 00 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ │ ............░░░░ - 0x20 │ ╾───────alloc8────────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........ - 0x30 │ 01 00 00 00 2a 00 00 00 ╾───────alloc13───────╼ │ ....*...╾──────╼ + 0x20 │ ╾───────alloc7────────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........ + 0x30 │ 01 00 00 00 2a 00 00 00 ╾───────alloc11───────╼ │ ....*...╾──────╼ 0x40 │ 03 00 00 00 00 00 00 00 │ ........ } alloc4 (size: 0, align: 8) {} -alloc8 (size: 32, align: 8) { - 0x00 │ ╾───────alloc7────────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........ - 0x10 │ ╾───────alloc9────────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........ +alloc7 (size: 32, align: 8) { + 0x00 │ ╾───────alloc6────────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........ + 0x10 │ ╾───────alloc8────────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........ } -alloc7 (size: 3, align: 1) { +alloc6 (size: 3, align: 1) { 66 6f 6f │ foo } -alloc9 (size: 3, align: 1) { +alloc8 (size: 3, align: 1) { 62 61 72 │ bar } -alloc13 (size: 48, align: 8) { - 0x00 │ ╾───────alloc12───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........ - 0x10 │ ╾───────alloc14───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........ - 0x20 │ ╾───────alloc15───────╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........ +alloc11 (size: 48, align: 8) { + 0x00 │ ╾───────alloc10───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........ + 0x10 │ ╾───────alloc12───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........ + 0x20 │ ╾───────alloc13───────╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........ } -alloc12 (size: 3, align: 1) { +alloc10 (size: 3, align: 1) { 6d 65 68 │ meh } -alloc14 (size: 3, align: 1) { +alloc12 (size: 3, align: 1) { 6d 6f 70 │ mop } -alloc15 (size: 4, align: 1) { +alloc13 (size: 4, align: 1) { 6d c3 b6 70 │ m..p } diff --git a/src/test/mir-opt/const_allocation2/32bit/rustc.main.ConstProp.after.mir b/src/test/mir-opt/const_allocation2/32bit/rustc.main.ConstProp.after.mir index d386d24782926..1633e94b5c9ad 100644 --- a/src/test/mir-opt/const_allocation2/32bit/rustc.main.ConstProp.after.mir +++ b/src/test/mir-opt/const_allocation2/32bit/rustc.main.ConstProp.after.mir @@ -30,41 +30,41 @@ fn main() -> () { } alloc0 (static: FOO, size: 8, align: 4) { - ╾─alloc21─╼ 03 00 00 00 │ ╾──╼.... + ╾─alloc18─╼ 03 00 00 00 │ ╾──╼.... } -alloc21 (size: 48, align: 4) { +alloc18 (size: 48, align: 4) { 0x00 │ 00 00 00 00 __ __ __ __ ╾─alloc4──╼ 00 00 00 00 │ ....░░░░╾──╼.... - 0x10 │ 00 00 00 00 __ __ __ __ ╾─alloc9──╼ 02 00 00 00 │ ....░░░░╾──╼.... - 0x20 │ 01 00 00 00 2a 00 00 00 ╾─alloc19─╼ 03 00 00 00 │ ....*...╾──╼.... + 0x10 │ 00 00 00 00 __ __ __ __ ╾─alloc8──╼ 02 00 00 00 │ ....░░░░╾──╼.... + 0x20 │ 01 00 00 00 2a 00 00 00 ╾─alloc17─╼ 03 00 00 00 │ ....*...╾──╼.... } alloc4 (size: 0, align: 4) {} -alloc9 (size: 8, align: 4) { - ╾─alloc7──╼ ╾─alloc8──╼ │ ╾──╼╾──╼ +alloc8 (size: 8, align: 4) { + ╾─alloc6──╼ ╾─alloc7──╼ │ ╾──╼╾──╼ } -alloc7 (size: 1, align: 1) { +alloc6 (size: 1, align: 1) { 05 │ . } -alloc8 (size: 1, align: 1) { +alloc7 (size: 1, align: 1) { 06 │ . } -alloc19 (size: 12, align: 4) { - ╾─a15+0x3─╼ ╾─alloc16─╼ ╾─a18+0x2─╼ │ ╾──╼╾──╼╾──╼ +alloc17 (size: 12, align: 4) { + ╾─a13+0x3─╼ ╾─alloc14─╼ ╾─a16+0x2─╼ │ ╾──╼╾──╼╾──╼ } -alloc15 (size: 4, align: 1) { +alloc13 (size: 4, align: 1) { 2a 45 15 6f │ *E.o } -alloc16 (size: 1, align: 1) { +alloc14 (size: 1, align: 1) { 2a │ * } -alloc18 (size: 4, align: 1) { +alloc16 (size: 4, align: 1) { 2a 45 15 6f │ *E.o } diff --git a/src/test/mir-opt/const_allocation2/64bit/rustc.main.ConstProp.after.mir b/src/test/mir-opt/const_allocation2/64bit/rustc.main.ConstProp.after.mir index d7acd0f0f4335..85925adeb2931 100644 --- a/src/test/mir-opt/const_allocation2/64bit/rustc.main.ConstProp.after.mir +++ b/src/test/mir-opt/const_allocation2/64bit/rustc.main.ConstProp.after.mir @@ -30,44 +30,44 @@ fn main() -> () { } alloc0 (static: FOO, size: 16, align: 8) { - ╾───────alloc21───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........ + ╾───────alloc18───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........ } -alloc21 (size: 72, align: 8) { +alloc18 (size: 72, align: 8) { 0x00 │ 00 00 00 00 __ __ __ __ ╾───────alloc4────────╼ │ ....░░░░╾──────╼ 0x10 │ 00 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ │ ............░░░░ - 0x20 │ ╾───────alloc9────────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........ - 0x30 │ 01 00 00 00 2a 00 00 00 ╾───────alloc19───────╼ │ ....*...╾──────╼ + 0x20 │ ╾───────alloc8────────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........ + 0x30 │ 01 00 00 00 2a 00 00 00 ╾───────alloc17───────╼ │ ....*...╾──────╼ 0x40 │ 03 00 00 00 00 00 00 00 │ ........ } alloc4 (size: 0, align: 8) {} -alloc9 (size: 16, align: 8) { - ╾───────alloc7────────╼ ╾───────alloc8────────╼ │ ╾──────╼╾──────╼ +alloc8 (size: 16, align: 8) { + ╾───────alloc6────────╼ ╾───────alloc7────────╼ │ ╾──────╼╾──────╼ } -alloc7 (size: 1, align: 1) { +alloc6 (size: 1, align: 1) { 05 │ . } -alloc8 (size: 1, align: 1) { +alloc7 (size: 1, align: 1) { 06 │ . } -alloc19 (size: 24, align: 8) { - 0x00 │ ╾─────alloc15+0x3─────╼ ╾───────alloc16───────╼ │ ╾──────╼╾──────╼ - 0x10 │ ╾─────alloc18+0x2─────╼ │ ╾──────╼ +alloc17 (size: 24, align: 8) { + 0x00 │ ╾─────alloc13+0x3─────╼ ╾───────alloc14───────╼ │ ╾──────╼╾──────╼ + 0x10 │ ╾─────alloc16+0x2─────╼ │ ╾──────╼ } -alloc15 (size: 4, align: 1) { +alloc13 (size: 4, align: 1) { 2a 45 15 6f │ *E.o } -alloc16 (size: 1, align: 1) { +alloc14 (size: 1, align: 1) { 2a │ * } -alloc18 (size: 4, align: 1) { +alloc16 (size: 4, align: 1) { 2a 45 15 6f │ *E.o } diff --git a/src/test/mir-opt/const_allocation3/32bit/rustc.main.ConstProp.after.mir b/src/test/mir-opt/const_allocation3/32bit/rustc.main.ConstProp.after.mir index 39c60ad987a6f..dbe577b9781a9 100644 --- a/src/test/mir-opt/const_allocation3/32bit/rustc.main.ConstProp.after.mir +++ b/src/test/mir-opt/const_allocation3/32bit/rustc.main.ConstProp.after.mir @@ -30,10 +30,10 @@ fn main() -> () { } alloc0 (static: FOO, size: 4, align: 4) { - ╾─alloc9──╼ │ ╾──╼ + ╾─alloc3──╼ │ ╾──╼ } -alloc9 (size: 168, align: 1) { +alloc3 (size: 168, align: 1) { 0x00 │ ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab │ ................ 0x10 │ ab ab ab ab ab ab ab ab ab ab ab ab ╾─alloc4──╼ │ ............╾──╼ 0x20 │ 01 ef cd ab 00 00 00 00 00 00 00 00 00 00 00 00 │ ................ diff --git a/src/test/mir-opt/const_allocation3/64bit/rustc.main.ConstProp.after.mir b/src/test/mir-opt/const_allocation3/64bit/rustc.main.ConstProp.after.mir index 96024f1c82caa..a3bf967295498 100644 --- a/src/test/mir-opt/const_allocation3/64bit/rustc.main.ConstProp.after.mir +++ b/src/test/mir-opt/const_allocation3/64bit/rustc.main.ConstProp.after.mir @@ -30,10 +30,10 @@ fn main() -> () { } alloc0 (static: FOO, size: 8, align: 8) { - ╾───────alloc9────────╼ │ ╾──────╼ + ╾───────alloc3────────╼ │ ╾──────╼ } -alloc9 (size: 180, align: 1) { +alloc3 (size: 180, align: 1) { 0x00 │ ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab │ ................ 0x10 │ ab ab ab ab ab ab ab ab ab ab ab ab ╾──alloc4── │ ............╾─── 0x20 │ ──────────╼ 01 ef cd ab 00 00 00 00 00 00 00 00 │ ───╼............ diff --git a/src/test/mir-opt/copy_propagation/rustc.test.CopyPropagation.diff b/src/test/mir-opt/copy_propagation/rustc.test.CopyPropagation.diff index f2838638aca0e..1f3e559c1b7f4 100644 --- a/src/test/mir-opt/copy_propagation/rustc.test.CopyPropagation.diff +++ b/src/test/mir-opt/copy_propagation/rustc.test.CopyPropagation.diff @@ -6,19 +6,14 @@ let mut _0: u32; // return place in scope 0 at $DIR/copy_propagation.rs:3:20: 3:23 let _2: u32; // in scope 0 at $DIR/copy_propagation.rs:4:9: 4:10 scope 1 { -- debug y => _2; // in scope 1 at $DIR/copy_propagation.rs:4:9: 4:10 -+ debug y => _1; // in scope 1 at $DIR/copy_propagation.rs:4:9: 4:10 + debug y => _0; // in scope 1 at $DIR/copy_propagation.rs:4:9: 4:10 } bb0: { -- StorageLive(_2); // scope 0 at $DIR/copy_propagation.rs:4:9: 4:10 -- _2 = _1; // scope 0 at $DIR/copy_propagation.rs:4:13: 4:14 -- _0 = _2; // scope 1 at $DIR/copy_propagation.rs:5:5: 5:6 -- StorageDead(_2); // scope 0 at $DIR/copy_propagation.rs:6:1: 6:2 -+ nop; // scope 0 at $DIR/copy_propagation.rs:4:9: 4:10 -+ nop; // scope 0 at $DIR/copy_propagation.rs:4:13: 4:14 -+ _0 = _1; // scope 1 at $DIR/copy_propagation.rs:5:5: 5:6 -+ nop; // scope 0 at $DIR/copy_propagation.rs:6:1: 6:2 + nop; // scope 0 at $DIR/copy_propagation.rs:4:9: 4:10 + _0 = _1; // scope 0 at $DIR/copy_propagation.rs:4:13: 4:14 + nop; // scope 1 at $DIR/copy_propagation.rs:5:5: 5:6 + nop; // scope 0 at $DIR/copy_propagation.rs:6:1: 6:2 return; // scope 0 at $DIR/copy_propagation.rs:6:2: 6:2 } } diff --git a/src/test/mir-opt/copy_propagation_arg/rustc.arg_src.CopyPropagation.diff b/src/test/mir-opt/copy_propagation_arg/rustc.arg_src.CopyPropagation.diff index 1e0271a560f65..3797248f34296 100644 --- a/src/test/mir-opt/copy_propagation_arg/rustc.arg_src.CopyPropagation.diff +++ b/src/test/mir-opt/copy_propagation_arg/rustc.arg_src.CopyPropagation.diff @@ -6,12 +6,12 @@ let mut _0: i32; // return place in scope 0 at $DIR/copy_propagation_arg.rs:27:27: 27:30 let _2: i32; // in scope 0 at $DIR/copy_propagation_arg.rs:28:9: 28:10 scope 1 { - debug y => _2; // in scope 1 at $DIR/copy_propagation_arg.rs:28:9: 28:10 + debug y => _0; // in scope 1 at $DIR/copy_propagation_arg.rs:28:9: 28:10 } bb0: { - StorageLive(_2); // scope 0 at $DIR/copy_propagation_arg.rs:28:9: 28:10 - _2 = _1; // scope 0 at $DIR/copy_propagation_arg.rs:28:13: 28:14 + nop; // scope 0 at $DIR/copy_propagation_arg.rs:28:9: 28:10 + _0 = _1; // scope 0 at $DIR/copy_propagation_arg.rs:28:13: 28:14 _1 = const 123i32; // scope 1 at $DIR/copy_propagation_arg.rs:29:5: 29:12 // ty::Const // + ty: i32 @@ -19,8 +19,8 @@ // mir::Constant // + span: $DIR/copy_propagation_arg.rs:29:9: 29:12 // + literal: Const { ty: i32, val: Value(Scalar(0x0000007b)) } - _0 = _2; // scope 1 at $DIR/copy_propagation_arg.rs:30:5: 30:6 - StorageDead(_2); // scope 0 at $DIR/copy_propagation_arg.rs:31:1: 31:2 + nop; // scope 1 at $DIR/copy_propagation_arg.rs:30:5: 30:6 + nop; // scope 0 at $DIR/copy_propagation_arg.rs:31:1: 31:2 return; // scope 0 at $DIR/copy_propagation_arg.rs:31:2: 31:2 } } diff --git a/src/test/mir-opt/copy_propagation_arg/rustc.baz.CopyPropagation.diff b/src/test/mir-opt/copy_propagation_arg/rustc.baz.CopyPropagation.diff index ee20553f7cc3f..0bf04d1775d2b 100644 --- a/src/test/mir-opt/copy_propagation_arg/rustc.baz.CopyPropagation.diff +++ b/src/test/mir-opt/copy_propagation_arg/rustc.baz.CopyPropagation.diff @@ -7,10 +7,10 @@ let mut _2: i32; // in scope 0 at $DIR/copy_propagation_arg.rs:23:9: 23:10 bb0: { - StorageLive(_2); // scope 0 at $DIR/copy_propagation_arg.rs:23:9: 23:10 - _2 = _1; // scope 0 at $DIR/copy_propagation_arg.rs:23:9: 23:10 - _1 = move _2; // scope 0 at $DIR/copy_propagation_arg.rs:23:5: 23:10 - StorageDead(_2); // scope 0 at $DIR/copy_propagation_arg.rs:23:9: 23:10 + nop; // scope 0 at $DIR/copy_propagation_arg.rs:23:9: 23:10 + nop; // scope 0 at $DIR/copy_propagation_arg.rs:23:9: 23:10 + nop; // scope 0 at $DIR/copy_propagation_arg.rs:23:5: 23:10 + nop; // scope 0 at $DIR/copy_propagation_arg.rs:23:9: 23:10 _0 = const (); // scope 0 at $DIR/copy_propagation_arg.rs:21:20: 24:2 // ty::Const // + ty: () diff --git a/src/test/mir-opt/copy_propagation_arg/rustc.foo.CopyPropagation.diff b/src/test/mir-opt/copy_propagation_arg/rustc.foo.CopyPropagation.diff index 33aaa7486787d..1b50d43b7d699 100644 --- a/src/test/mir-opt/copy_propagation_arg/rustc.foo.CopyPropagation.diff +++ b/src/test/mir-opt/copy_propagation_arg/rustc.foo.CopyPropagation.diff @@ -8,10 +8,10 @@ let mut _3: u8; // in scope 0 at $DIR/copy_propagation_arg.rs:11:15: 11:16 bb0: { - StorageLive(_2); // scope 0 at $DIR/copy_propagation_arg.rs:11:9: 11:17 + nop; // scope 0 at $DIR/copy_propagation_arg.rs:11:9: 11:17 StorageLive(_3); // scope 0 at $DIR/copy_propagation_arg.rs:11:15: 11:16 _3 = _1; // scope 0 at $DIR/copy_propagation_arg.rs:11:15: 11:16 - _2 = const dummy(move _3) -> bb1; // scope 0 at $DIR/copy_propagation_arg.rs:11:9: 11:17 + _1 = const dummy(move _3) -> bb1; // scope 0 at $DIR/copy_propagation_arg.rs:11:9: 11:17 // ty::Const // + ty: fn(u8) -> u8 {dummy} // + val: Value(Scalar()) @@ -22,8 +22,8 @@ bb1: { StorageDead(_3); // scope 0 at $DIR/copy_propagation_arg.rs:11:16: 11:17 - _1 = move _2; // scope 0 at $DIR/copy_propagation_arg.rs:11:5: 11:17 - StorageDead(_2); // scope 0 at $DIR/copy_propagation_arg.rs:11:16: 11:17 + nop; // scope 0 at $DIR/copy_propagation_arg.rs:11:5: 11:17 + nop; // scope 0 at $DIR/copy_propagation_arg.rs:11:16: 11:17 _0 = const (); // scope 0 at $DIR/copy_propagation_arg.rs:9:19: 12:2 // ty::Const // + ty: () diff --git a/src/test/mir-opt/inline/inline-closure-captures/rustc.foo.Inline.after.mir b/src/test/mir-opt/inline/inline-closure-captures/rustc.foo.Inline.after.mir index eeff914ccffb9..573cc51d76bc2 100644 --- a/src/test/mir-opt/inline/inline-closure-captures/rustc.foo.Inline.after.mir +++ b/src/test/mir-opt/inline/inline-closure-captures/rustc.foo.Inline.after.mir @@ -10,15 +10,14 @@ fn foo(_1: T, _2: i32) -> (i32, T) { let mut _6: &[closure@foo::{{closure}}#0 q:&i32, t:&T]; // in scope 0 at $DIR/inline-closure-captures.rs:12:5: 12:6 let mut _7: (i32,); // in scope 0 at $DIR/inline-closure-captures.rs:12:5: 12:9 let mut _8: i32; // in scope 0 at $DIR/inline-closure-captures.rs:12:7: 12:8 - let mut _11: i32; // in scope 0 at $DIR/inline-closure-captures.rs:12:5: 12:9 + let mut _10: i32; // in scope 0 at $DIR/inline-closure-captures.rs:12:5: 12:9 scope 1 { debug x => _3; // in scope 1 at $DIR/inline-closure-captures.rs:11:9: 11:10 scope 2 { - debug _q => _11; // in scope 2 at $DIR/inline-closure-captures.rs:11:14: 11:16 + debug _q => _10; // in scope 2 at $DIR/inline-closure-captures.rs:11:14: 11:16 debug q => (*((*_6).0: &i32)); // in scope 2 at $DIR/inline-closure-captures.rs:10:23: 10:24 debug t => (*((*_6).1: &T)); // in scope 2 at $DIR/inline-closure-captures.rs:10:17: 10:18 - let mut _9: i32; // in scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9 - let mut _10: T; // in scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9 + let mut _9: T; // in scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9 } } @@ -45,14 +44,11 @@ fn foo(_1: T, _2: i32) -> (i32, T) { StorageLive(_8); // scope 1 at $DIR/inline-closure-captures.rs:12:7: 12:8 _8 = _2; // scope 1 at $DIR/inline-closure-captures.rs:12:7: 12:8 _7 = (move _8,); // scope 1 at $DIR/inline-closure-captures.rs:12:5: 12:9 - _11 = move (_7.0: i32); // scope 1 at $DIR/inline-closure-captures.rs:12:5: 12:9 - StorageLive(_9); // scope 2 at $DIR/inline-closure-captures.rs:11:19: 11:20 - _9 = (*((*_6).0: &i32)); // scope 2 at $DIR/inline-closure-captures.rs:11:19: 11:20 - StorageLive(_10); // scope 2 at $DIR/inline-closure-captures.rs:11:22: 11:23 - _10 = (*((*_6).1: &T)); // scope 2 at $DIR/inline-closure-captures.rs:11:22: 11:23 - (_0.0: i32) = move _9; // scope 2 at $DIR/inline-closure-captures.rs:11:18: 11:24 - (_0.1: T) = move _10; // scope 2 at $DIR/inline-closure-captures.rs:11:18: 11:24 - StorageDead(_10); // scope 2 at $DIR/inline-closure-captures.rs:11:23: 11:24 + _10 = move (_7.0: i32); // scope 1 at $DIR/inline-closure-captures.rs:12:5: 12:9 + (_0.0: i32) = (*((*_6).0: &i32)); // scope 2 at $DIR/inline-closure-captures.rs:11:19: 11:20 + StorageLive(_9); // scope 2 at $DIR/inline-closure-captures.rs:11:22: 11:23 + _9 = (*((*_6).1: &T)); // scope 2 at $DIR/inline-closure-captures.rs:11:22: 11:23 + (_0.1: T) = move _9; // scope 2 at $DIR/inline-closure-captures.rs:11:18: 11:24 StorageDead(_9); // scope 2 at $DIR/inline-closure-captures.rs:11:23: 11:24 StorageDead(_8); // scope 1 at $DIR/inline-closure-captures.rs:12:8: 12:9 StorageDead(_7); // scope 1 at $DIR/inline-closure-captures.rs:12:8: 12:9 From fbcf758e47c79f023d4b4b47639197111f56ab68 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sun, 24 May 2020 21:37:09 +0200 Subject: [PATCH 06/15] Add a few dest-prop MIR tests --- src/test/mir-opt/dest-prop/branch.rs | 21 +++++ .../rustc.main.DestinationPropagation.diff | 88 ++++++++++++++++++ src/test/mir-opt/dest-prop/cycle.rs | 15 +++ .../rustc.main.DestinationPropagation.diff | 91 +++++++++++++++++++ src/test/mir-opt/dest-prop/simple.rs | 14 +++ .../rustc.nrvo.DestinationPropagation.diff | 56 ++++++++++++ src/test/mir-opt/dest-prop/union.rs | 16 ++++ .../rustc.main.DestinationPropagation.diff | 61 +++++++++++++ 8 files changed, 362 insertions(+) create mode 100644 src/test/mir-opt/dest-prop/branch.rs create mode 100644 src/test/mir-opt/dest-prop/branch/rustc.main.DestinationPropagation.diff create mode 100644 src/test/mir-opt/dest-prop/cycle.rs create mode 100644 src/test/mir-opt/dest-prop/cycle/rustc.main.DestinationPropagation.diff create mode 100644 src/test/mir-opt/dest-prop/simple.rs create mode 100644 src/test/mir-opt/dest-prop/simple/rustc.nrvo.DestinationPropagation.diff create mode 100644 src/test/mir-opt/dest-prop/union.rs create mode 100644 src/test/mir-opt/dest-prop/union/rustc.main.DestinationPropagation.diff diff --git a/src/test/mir-opt/dest-prop/branch.rs b/src/test/mir-opt/dest-prop/branch.rs new file mode 100644 index 0000000000000..b49ecf07daa39 --- /dev/null +++ b/src/test/mir-opt/dest-prop/branch.rs @@ -0,0 +1,21 @@ +//! Tests that assignment in both branches of an `if` are eliminated. + +fn val() -> i32 { + 1 +} + +fn cond() -> bool { + true +} + +// EMIT_MIR rustc.main.DestinationPropagation.diff +fn main() { + let x = val(); + + let y = if cond() { + x + } else { + val(); + x + }; +} diff --git a/src/test/mir-opt/dest-prop/branch/rustc.main.DestinationPropagation.diff b/src/test/mir-opt/dest-prop/branch/rustc.main.DestinationPropagation.diff new file mode 100644 index 0000000000000..b8387ae449387 --- /dev/null +++ b/src/test/mir-opt/dest-prop/branch/rustc.main.DestinationPropagation.diff @@ -0,0 +1,88 @@ +- // MIR for `main` before DestinationPropagation ++ // MIR for `main` after DestinationPropagation + + fn main() -> () { + let mut _0: (); // return place in scope 0 at $DIR/branch.rs:12:11: 12:11 + let _1: i32; // in scope 0 at $DIR/branch.rs:13:9: 13:10 + let mut _3: bool; // in scope 0 at $DIR/branch.rs:15:16: 15:22 + let _4: i32; // in scope 0 at $DIR/branch.rs:18:9: 18:14 + scope 1 { +- debug x => _1; // in scope 1 at $DIR/branch.rs:13:9: 13:10 ++ debug x => _2; // in scope 1 at $DIR/branch.rs:13:9: 13:10 + let _2: i32; // in scope 1 at $DIR/branch.rs:15:9: 15:10 + scope 2 { + debug y => _2; // in scope 2 at $DIR/branch.rs:15:9: 15:10 + } + } + + bb0: { +- StorageLive(_1); // scope 0 at $DIR/branch.rs:13:9: 13:10 +- _1 = const val() -> bb1; // scope 0 at $DIR/branch.rs:13:13: 13:18 ++ nop; // scope 0 at $DIR/branch.rs:13:9: 13:10 ++ _2 = const val() -> bb1; // scope 0 at $DIR/branch.rs:13:13: 13:18 + // ty::Const + // + ty: fn() -> i32 {val} + // + val: Value(Scalar()) + // mir::Constant + // + span: $DIR/branch.rs:13:13: 13:16 + // + literal: Const { ty: fn() -> i32 {val}, val: Value(Scalar()) } + } + + bb1: { +- StorageLive(_2); // scope 1 at $DIR/branch.rs:15:9: 15:10 ++ nop; // scope 1 at $DIR/branch.rs:15:9: 15:10 + StorageLive(_3); // scope 1 at $DIR/branch.rs:15:16: 15:22 + _3 = const cond() -> bb2; // scope 1 at $DIR/branch.rs:15:16: 15:22 + // ty::Const + // + ty: fn() -> bool {cond} + // + val: Value(Scalar()) + // mir::Constant + // + span: $DIR/branch.rs:15:16: 15:20 + // + literal: Const { ty: fn() -> bool {cond}, val: Value(Scalar()) } + } + + bb2: { + switchInt(_3) -> [false: bb3, otherwise: bb4]; // scope 1 at $DIR/branch.rs:15:13: 20:6 + } + + bb3: { + StorageLive(_4); // scope 1 at $DIR/branch.rs:18:9: 18:14 + _4 = const val() -> bb5; // scope 1 at $DIR/branch.rs:18:9: 18:14 + // ty::Const + // + ty: fn() -> i32 {val} + // + val: Value(Scalar()) + // mir::Constant + // + span: $DIR/branch.rs:18:9: 18:12 + // + literal: Const { ty: fn() -> i32 {val}, val: Value(Scalar()) } + } + + bb4: { +- _2 = _1; // scope 1 at $DIR/branch.rs:16:9: 16:10 ++ nop; // scope 1 at $DIR/branch.rs:16:9: 16:10 + goto -> bb6; // scope 1 at $DIR/branch.rs:15:13: 20:6 + } + + bb5: { + StorageDead(_4); // scope 1 at $DIR/branch.rs:18:14: 18:15 +- _2 = _1; // scope 1 at $DIR/branch.rs:19:9: 19:10 ++ nop; // scope 1 at $DIR/branch.rs:19:9: 19:10 + goto -> bb6; // scope 1 at $DIR/branch.rs:15:13: 20:6 + } + + bb6: { + StorageDead(_3); // scope 1 at $DIR/branch.rs:20:6: 20:7 + _0 = const (); // scope 0 at $DIR/branch.rs:12:11: 21:2 + // ty::Const + // + ty: () + // + val: Value(Scalar()) + // mir::Constant + // + span: $DIR/branch.rs:12:11: 21:2 + // + literal: Const { ty: (), val: Value(Scalar()) } +- StorageDead(_2); // scope 1 at $DIR/branch.rs:21:1: 21:2 +- StorageDead(_1); // scope 0 at $DIR/branch.rs:21:1: 21:2 ++ nop; // scope 1 at $DIR/branch.rs:21:1: 21:2 ++ nop; // scope 0 at $DIR/branch.rs:21:1: 21:2 + return; // scope 0 at $DIR/branch.rs:21:2: 21:2 + } + } + diff --git a/src/test/mir-opt/dest-prop/cycle.rs b/src/test/mir-opt/dest-prop/cycle.rs new file mode 100644 index 0000000000000..d55d527bc65f6 --- /dev/null +++ b/src/test/mir-opt/dest-prop/cycle.rs @@ -0,0 +1,15 @@ +//! Tests that cyclic assignments don't hang DestinationPropagation, and result in reasonable code. + +fn val() -> i32 { + 1 +} + +// EMIT_MIR rustc.main.DestinationPropagation.diff +fn main() { + let mut x = val(); + let y = x; + let z = y; + x = z; + + drop(x); +} diff --git a/src/test/mir-opt/dest-prop/cycle/rustc.main.DestinationPropagation.diff b/src/test/mir-opt/dest-prop/cycle/rustc.main.DestinationPropagation.diff new file mode 100644 index 0000000000000..5189b665acff1 --- /dev/null +++ b/src/test/mir-opt/dest-prop/cycle/rustc.main.DestinationPropagation.diff @@ -0,0 +1,91 @@ +- // MIR for `main` before DestinationPropagation ++ // MIR for `main` after DestinationPropagation + + fn main() -> () { + let mut _0: (); // return place in scope 0 at $DIR/cycle.rs:8:11: 8:11 + let mut _1: i32; // in scope 0 at $DIR/cycle.rs:9:9: 9:14 + let mut _4: i32; // in scope 0 at $DIR/cycle.rs:12:9: 12:10 + let _5: (); // in scope 0 at $DIR/cycle.rs:14:5: 14:12 + let mut _6: i32; // in scope 0 at $DIR/cycle.rs:14:10: 14:11 + scope 1 { +- debug x => _1; // in scope 1 at $DIR/cycle.rs:9:9: 9:14 ++ debug x => _4; // in scope 1 at $DIR/cycle.rs:9:9: 9:14 + let _2: i32; // in scope 1 at $DIR/cycle.rs:10:9: 10:10 + scope 2 { +- debug y => _2; // in scope 2 at $DIR/cycle.rs:10:9: 10:10 ++ debug y => _4; // in scope 2 at $DIR/cycle.rs:10:9: 10:10 + let _3: i32; // in scope 2 at $DIR/cycle.rs:11:9: 11:10 + scope 3 { +- debug z => _3; // in scope 3 at $DIR/cycle.rs:11:9: 11:10 ++ debug z => _4; // in scope 3 at $DIR/cycle.rs:11:9: 11:10 + scope 4 { + debug _x => _6; // in scope 4 at $SRC_DIR/libcore/mem/mod.rs:LL:COL + } + } + } + } + + bb0: { +- StorageLive(_1); // scope 0 at $DIR/cycle.rs:9:9: 9:14 +- _1 = const val() -> bb1; // scope 0 at $DIR/cycle.rs:9:17: 9:22 ++ nop; // scope 0 at $DIR/cycle.rs:9:9: 9:14 ++ _4 = const val() -> bb1; // scope 0 at $DIR/cycle.rs:9:17: 9:22 + // ty::Const + // + ty: fn() -> i32 {val} + // + val: Value(Scalar()) + // mir::Constant + // + span: $DIR/cycle.rs:9:17: 9:20 + // + literal: Const { ty: fn() -> i32 {val}, val: Value(Scalar()) } + } + + bb1: { +- StorageLive(_2); // scope 1 at $DIR/cycle.rs:10:9: 10:10 +- _2 = _1; // scope 1 at $DIR/cycle.rs:10:13: 10:14 +- StorageLive(_3); // scope 2 at $DIR/cycle.rs:11:9: 11:10 +- _3 = _2; // scope 2 at $DIR/cycle.rs:11:13: 11:14 +- StorageLive(_4); // scope 3 at $DIR/cycle.rs:12:9: 12:10 +- _4 = _3; // scope 3 at $DIR/cycle.rs:12:9: 12:10 +- _1 = move _4; // scope 3 at $DIR/cycle.rs:12:5: 12:10 +- StorageDead(_4); // scope 3 at $DIR/cycle.rs:12:9: 12:10 ++ nop; // scope 1 at $DIR/cycle.rs:10:9: 10:10 ++ nop; // scope 1 at $DIR/cycle.rs:10:13: 10:14 ++ nop; // scope 2 at $DIR/cycle.rs:11:9: 11:10 ++ nop; // scope 2 at $DIR/cycle.rs:11:13: 11:14 ++ nop; // scope 3 at $DIR/cycle.rs:12:9: 12:10 ++ nop; // scope 3 at $DIR/cycle.rs:12:9: 12:10 ++ nop; // scope 3 at $DIR/cycle.rs:12:5: 12:10 ++ nop; // scope 3 at $DIR/cycle.rs:12:9: 12:10 + StorageLive(_5); // scope 3 at $DIR/cycle.rs:14:5: 14:12 + StorageLive(_6); // scope 3 at $DIR/cycle.rs:14:10: 14:11 +- _6 = _1; // scope 3 at $DIR/cycle.rs:14:10: 14:11 ++ _6 = _4; // scope 3 at $DIR/cycle.rs:14:10: 14:11 + _5 = const (); // scope 4 at $SRC_DIR/libcore/mem/mod.rs:LL:COL + // ty::Const + // + ty: () + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/mem/mod.rs:LL:COL + // + literal: Const { ty: (), val: Value(Scalar()) } + drop(_6) -> bb2; // scope 4 at $SRC_DIR/libcore/mem/mod.rs:LL:COL + } + + bb2: { + StorageDead(_6); // scope 3 at $DIR/cycle.rs:14:11: 14:12 + StorageDead(_5); // scope 3 at $DIR/cycle.rs:14:12: 14:13 + _0 = const (); // scope 0 at $DIR/cycle.rs:8:11: 15:2 + // ty::Const + // + ty: () + // + val: Value(Scalar()) + // mir::Constant + // + span: $DIR/cycle.rs:8:11: 15:2 + // + literal: Const { ty: (), val: Value(Scalar()) } +- StorageDead(_3); // scope 2 at $DIR/cycle.rs:15:1: 15:2 +- StorageDead(_2); // scope 1 at $DIR/cycle.rs:15:1: 15:2 +- StorageDead(_1); // scope 0 at $DIR/cycle.rs:15:1: 15:2 ++ nop; // scope 2 at $DIR/cycle.rs:15:1: 15:2 ++ nop; // scope 1 at $DIR/cycle.rs:15:1: 15:2 ++ nop; // scope 0 at $DIR/cycle.rs:15:1: 15:2 + return; // scope 0 at $DIR/cycle.rs:15:2: 15:2 + } + } + diff --git a/src/test/mir-opt/dest-prop/simple.rs b/src/test/mir-opt/dest-prop/simple.rs new file mode 100644 index 0000000000000..add821eafe0b0 --- /dev/null +++ b/src/test/mir-opt/dest-prop/simple.rs @@ -0,0 +1,14 @@ +//! Copy of `nrvo-simple.rs`, to ensure that full dest-prop handles it too. + +// EMIT_MIR rustc.nrvo.DestinationPropagation.diff +fn nrvo(init: fn(&mut [u8; 1024])) -> [u8; 1024] { + let mut buf = [0; 1024]; + init(&mut buf); + buf +} + +fn main() { + let _ = nrvo(|buf| { + buf[4] = 4; + }); +} diff --git a/src/test/mir-opt/dest-prop/simple/rustc.nrvo.DestinationPropagation.diff b/src/test/mir-opt/dest-prop/simple/rustc.nrvo.DestinationPropagation.diff new file mode 100644 index 0000000000000..d59e1f3c0c938 --- /dev/null +++ b/src/test/mir-opt/dest-prop/simple/rustc.nrvo.DestinationPropagation.diff @@ -0,0 +1,56 @@ +- // MIR for `nrvo` before DestinationPropagation ++ // MIR for `nrvo` after DestinationPropagation + + fn nrvo(_1: for<'r> fn(&'r mut [u8; 1024])) -> [u8; 1024] { + debug init => _1; // in scope 0 at $DIR/simple.rs:4:9: 4:13 + let mut _0: [u8; 1024]; // return place in scope 0 at $DIR/simple.rs:4:39: 4:49 + let mut _2: [u8; 1024]; // in scope 0 at $DIR/simple.rs:5:9: 5:16 + let _3: (); // in scope 0 at $DIR/simple.rs:6:5: 6:19 + let mut _4: for<'r> fn(&'r mut [u8; 1024]); // in scope 0 at $DIR/simple.rs:6:5: 6:9 + let mut _5: &mut [u8; 1024]; // in scope 0 at $DIR/simple.rs:6:10: 6:18 + let mut _6: &mut [u8; 1024]; // in scope 0 at $DIR/simple.rs:6:10: 6:18 + scope 1 { +- debug buf => _2; // in scope 1 at $DIR/simple.rs:5:9: 5:16 ++ debug buf => _0; // in scope 1 at $DIR/simple.rs:5:9: 5:16 + } + + bb0: { +- StorageLive(_2); // scope 0 at $DIR/simple.rs:5:9: 5:16 +- _2 = [const 0u8; 1024]; // scope 0 at $DIR/simple.rs:5:19: 5:28 ++ nop; // scope 0 at $DIR/simple.rs:5:9: 5:16 ++ _0 = [const 0u8; 1024]; // scope 0 at $DIR/simple.rs:5:19: 5:28 + // ty::Const + // + ty: u8 + // + val: Value(Scalar(0x00)) + // mir::Constant + // + span: $DIR/simple.rs:5:20: 5:21 + // + literal: Const { ty: u8, val: Value(Scalar(0x00)) } + StorageLive(_3); // scope 1 at $DIR/simple.rs:6:5: 6:19 + StorageLive(_4); // scope 1 at $DIR/simple.rs:6:5: 6:9 + _4 = _1; // scope 1 at $DIR/simple.rs:6:5: 6:9 +- StorageLive(_5); // scope 1 at $DIR/simple.rs:6:10: 6:18 +- StorageLive(_6); // scope 1 at $DIR/simple.rs:6:10: 6:18 +- _6 = &mut _2; // scope 1 at $DIR/simple.rs:6:10: 6:18 +- _5 = move _6; // scope 1 at $DIR/simple.rs:6:10: 6:18 ++ nop; // scope 1 at $DIR/simple.rs:6:10: 6:18 ++ nop; // scope 1 at $DIR/simple.rs:6:10: 6:18 ++ _5 = &mut _0; // scope 1 at $DIR/simple.rs:6:10: 6:18 ++ nop; // scope 1 at $DIR/simple.rs:6:10: 6:18 + _3 = move _4(move _5) -> bb1; // scope 1 at $DIR/simple.rs:6:5: 6:19 + } + + bb1: { +- StorageDead(_5); // scope 1 at $DIR/simple.rs:6:18: 6:19 ++ nop; // scope 1 at $DIR/simple.rs:6:18: 6:19 + StorageDead(_4); // scope 1 at $DIR/simple.rs:6:18: 6:19 +- StorageDead(_6); // scope 1 at $DIR/simple.rs:6:19: 6:20 ++ nop; // scope 1 at $DIR/simple.rs:6:19: 6:20 + StorageDead(_3); // scope 1 at $DIR/simple.rs:6:19: 6:20 +- _0 = _2; // scope 1 at $DIR/simple.rs:7:5: 7:8 +- StorageDead(_2); // scope 0 at $DIR/simple.rs:8:1: 8:2 ++ nop; // scope 1 at $DIR/simple.rs:7:5: 7:8 ++ nop; // scope 0 at $DIR/simple.rs:8:1: 8:2 + return; // scope 0 at $DIR/simple.rs:8:2: 8:2 + } + } + diff --git a/src/test/mir-opt/dest-prop/union.rs b/src/test/mir-opt/dest-prop/union.rs new file mode 100644 index 0000000000000..ea8364124043e --- /dev/null +++ b/src/test/mir-opt/dest-prop/union.rs @@ -0,0 +1,16 @@ +//! Tests that projections through unions cancel `DestinationPropagation`. + +fn val() -> u32 { + 1 +} + +// EMIT_MIR rustc.main.DestinationPropagation.diff +fn main() { + union Un { + us: u32, + } + + let un = Un { us: val() }; + + drop(unsafe { un.us }); +} diff --git a/src/test/mir-opt/dest-prop/union/rustc.main.DestinationPropagation.diff b/src/test/mir-opt/dest-prop/union/rustc.main.DestinationPropagation.diff new file mode 100644 index 0000000000000..f6ebb6cb9403d --- /dev/null +++ b/src/test/mir-opt/dest-prop/union/rustc.main.DestinationPropagation.diff @@ -0,0 +1,61 @@ +- // MIR for `main` before DestinationPropagation ++ // MIR for `main` after DestinationPropagation + + fn main() -> () { + let mut _0: (); // return place in scope 0 at $DIR/union.rs:8:11: 8:11 + let _1: main::Un; // in scope 0 at $DIR/union.rs:13:9: 13:11 + let mut _2: u32; // in scope 0 at $DIR/union.rs:13:23: 13:28 + let _3: (); // in scope 0 at $DIR/union.rs:15:5: 15:27 + let mut _4: u32; // in scope 0 at $DIR/union.rs:15:10: 15:26 + scope 1 { + debug un => _1; // in scope 1 at $DIR/union.rs:13:9: 13:11 + scope 2 { + } + scope 3 { + debug _x => _4; // in scope 3 at $SRC_DIR/libcore/mem/mod.rs:LL:COL + } + } + + bb0: { + StorageLive(_1); // scope 0 at $DIR/union.rs:13:9: 13:11 + StorageLive(_2); // scope 0 at $DIR/union.rs:13:23: 13:28 + _2 = const val() -> bb1; // scope 0 at $DIR/union.rs:13:23: 13:28 + // ty::Const + // + ty: fn() -> u32 {val} + // + val: Value(Scalar()) + // mir::Constant + // + span: $DIR/union.rs:13:23: 13:26 + // + literal: Const { ty: fn() -> u32 {val}, val: Value(Scalar()) } + } + + bb1: { + (_1.0: u32) = move _2; // scope 0 at $DIR/union.rs:13:14: 13:30 + StorageDead(_2); // scope 0 at $DIR/union.rs:13:29: 13:30 + StorageLive(_3); // scope 1 at $DIR/union.rs:15:5: 15:27 + StorageLive(_4); // scope 1 at $DIR/union.rs:15:10: 15:26 + _4 = (_1.0: u32); // scope 2 at $DIR/union.rs:15:19: 15:24 + _3 = const (); // scope 3 at $SRC_DIR/libcore/mem/mod.rs:LL:COL + // ty::Const + // + ty: () + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/mem/mod.rs:LL:COL + // + literal: Const { ty: (), val: Value(Scalar()) } + drop(_4) -> bb2; // scope 3 at $SRC_DIR/libcore/mem/mod.rs:LL:COL + } + + bb2: { + StorageDead(_4); // scope 1 at $DIR/union.rs:15:26: 15:27 + StorageDead(_3); // scope 1 at $DIR/union.rs:15:27: 15:28 + _0 = const (); // scope 0 at $DIR/union.rs:8:11: 16:2 + // ty::Const + // + ty: () + // + val: Value(Scalar()) + // mir::Constant + // + span: $DIR/union.rs:8:11: 16:2 + // + literal: Const { ty: (), val: Value(Scalar()) } + StorageDead(_1); // scope 0 at $DIR/union.rs:16:1: 16:2 + return; // scope 0 at $DIR/union.rs:16:2: 16:2 + } + } + From fef25975df2b5a52f4277376477b35e530ee1be2 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 26 May 2020 01:28:06 +0200 Subject: [PATCH 07/15] perf: walk liveness backwards in Conflicts::build --- src/librustc_mir/transform/dest_prop.rs | 62 ++++++++++++++++--------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/src/librustc_mir/transform/dest_prop.rs b/src/librustc_mir/transform/dest_prop.rs index 2554f70c6056e..17ee587452282 100644 --- a/src/librustc_mir/transform/dest_prop.rs +++ b/src/librustc_mir/transform/dest_prop.rs @@ -100,10 +100,7 @@ use crate::{ transform::{MirPass, MirSource}, util::{dump_mir, PassWhere}, }; -use dataflow::{ - impls::{MaybeInitializedLocals, MaybeLiveLocals}, - ResultsCursor, -}; +use dataflow::impls::{MaybeInitializedLocals, MaybeLiveLocals}; use rustc_data_structures::unify::{InPlaceUnificationTable, UnifyKey}; use rustc_index::{ bit_set::{BitMatrix, BitSet}, @@ -382,15 +379,11 @@ impl Conflicts { body.local_decls.len(), ); - let mut record_conflicts = - |init: &ResultsCursor<'_, '_, _>, live: &ResultsCursor<'_, '_, _>| { - let mut requires_storage = init.get().clone(); - requires_storage.intersect(live.get()); - - for local in requires_storage.iter() { - conflicts.union_row_with(&requires_storage, local); - } - }; + let mut record_conflicts = |new_conflicts: &BitSet<_>| { + for local in new_conflicts.iter() { + conflicts.union_row_with(&new_conflicts, local); + } + }; let def_id = source.def_id(); let mut init = MaybeInitializedLocals @@ -442,27 +435,50 @@ impl Conflicts { }, ); + let mut relevant_locals = Vec::new(); + // Visit only reachable basic blocks. The exact order is not important. for (block, data) in traversal::preorder(body) { - // Observe the dataflow state *before* all possible locations (statement or terminator) in - // each basic block... + // We need to observe the dataflow state *before* all possible locations (statement or + // terminator) in each basic block, and then observe the state *after* the terminator + // effect is applied. As long as neither `init` nor `borrowed` has a "before" effect, + // we will observe all possible dataflow states. + + // Since liveness is a backwards analysis, we need to walk the results backwards. To do + // that, we first collect in the `MaybeInitializedLocals` results in a forwards + // traversal. + + relevant_locals.resize_with(data.statements.len() + 1, || { + BitSet::new_empty(body.local_decls.len()) + }); + + // First, go forwards for `MaybeInitializedLocals`. for statement_index in 0..=data.statements.len() { let loc = Location { block, statement_index }; - trace!("record conflicts at {:?}", loc); init.seek_before_primary_effect(loc); + + relevant_locals[statement_index].overwrite(init.get()); + } + + // Now, go backwards and union with the liveness results. + for statement_index in (0..=data.statements.len()).rev() { + let loc = Location { block, statement_index }; live.seek_after_primary_effect(loc); - // FIXME: liveness is backwards, so this is slow - record_conflicts(&init, &live); + relevant_locals[statement_index].intersect(live.get()); + + trace!("record conflicts at {:?}", loc); + + record_conflicts(&relevant_locals[statement_index]); } - // ...and then observe the state *after* the terminator effect is applied. As long as - // neither `init` nor `borrowed` has a "before" effect, we will observe all possible - // dataflow states here or in the loop above. - trace!("record conflicts at end of {:?}", block); init.seek_to_block_end(block); live.seek_to_block_end(block); - record_conflicts(&init, &live); + let mut conflicts = init.get().clone(); + conflicts.intersect(live.get()); + trace!("record conflicts at end of {:?}", block); + + record_conflicts(&conflicts); } Self { matrix: conflicts, unify_cache: BitSet::new_empty(body.local_decls.len()) } From 093b248a5f58ddf5927c2670e474947941c00068 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 26 May 2020 22:21:10 +0200 Subject: [PATCH 08/15] perf: only calculate conflicts for candidates --- src/librustc_mir/transform/dest_prop.rs | 51 +++++++++++++++++++------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/src/librustc_mir/transform/dest_prop.rs b/src/librustc_mir/transform/dest_prop.rs index 17ee587452282..5ea1e94a840b2 100644 --- a/src/librustc_mir/transform/dest_prop.rs +++ b/src/librustc_mir/transform/dest_prop.rs @@ -124,9 +124,22 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation { return; } - let mut conflicts = Conflicts::build(tcx, body, source); + let candidates = find_candidates(tcx, body); + if candidates.is_empty() { + debug!("{:?}: no dest prop candidates, done", source.def_id()); + return; + } + + // Collect all locals we care about. We only compute conflicts for these to save time. + let mut relevant_locals = BitSet::new_empty(body.local_decls.len()); + for CandidateAssignment { dest, src, loc: _ } in &candidates { + relevant_locals.insert(dest.local); + relevant_locals.insert(*src); + } + + let mut conflicts = Conflicts::build(tcx, body, source, &relevant_locals); let mut replacements = Replacements::new(body.local_decls.len()); - for candidate @ CandidateAssignment { dest, src, loc } in find_candidates(tcx, body) { + for candidate @ CandidateAssignment { dest, src, loc } in candidates { // Merge locals that don't conflict. if conflicts.contains(dest.local, src) { debug!("at assignment {:?}, conflict {:?} vs. {:?}", loc, dest.local, src); @@ -370,16 +383,30 @@ struct Conflicts { } impl Conflicts { - fn build<'tcx>(tcx: TyCtxt<'tcx>, body: &'_ Body<'tcx>, source: MirSource<'tcx>) -> Self { - // We don't have to look out for locals that have their address taken, since `find_candidates` - // already takes care of that. + fn build<'tcx>( + tcx: TyCtxt<'tcx>, + body: &'_ Body<'tcx>, + source: MirSource<'tcx>, + relevant_locals: &BitSet, + ) -> Self { + // We don't have to look out for locals that have their address taken, since + // `find_candidates` already takes care of that. + + debug!( + "Conflicts::build: {}/{} locals relevant", + relevant_locals.count(), + body.local_decls.len() + ); let mut conflicts = BitMatrix::from_row_n( &BitSet::new_empty(body.local_decls.len()), body.local_decls.len(), ); - let mut record_conflicts = |new_conflicts: &BitSet<_>| { + let mut record_conflicts = |new_conflicts: &mut BitSet<_>| { + // Remove all locals that are not candidates. + new_conflicts.intersect(relevant_locals); + for local in new_conflicts.iter() { conflicts.union_row_with(&new_conflicts, local); } @@ -435,7 +462,7 @@ impl Conflicts { }, ); - let mut relevant_locals = Vec::new(); + let mut live_and_init_locals = Vec::new(); // Visit only reachable basic blocks. The exact order is not important. for (block, data) in traversal::preorder(body) { @@ -448,7 +475,7 @@ impl Conflicts { // that, we first collect in the `MaybeInitializedLocals` results in a forwards // traversal. - relevant_locals.resize_with(data.statements.len() + 1, || { + live_and_init_locals.resize_with(data.statements.len() + 1, || { BitSet::new_empty(body.local_decls.len()) }); @@ -457,7 +484,7 @@ impl Conflicts { let loc = Location { block, statement_index }; init.seek_before_primary_effect(loc); - relevant_locals[statement_index].overwrite(init.get()); + live_and_init_locals[statement_index].overwrite(init.get()); } // Now, go backwards and union with the liveness results. @@ -465,11 +492,11 @@ impl Conflicts { let loc = Location { block, statement_index }; live.seek_after_primary_effect(loc); - relevant_locals[statement_index].intersect(live.get()); + live_and_init_locals[statement_index].intersect(live.get()); trace!("record conflicts at {:?}", loc); - record_conflicts(&relevant_locals[statement_index]); + record_conflicts(&mut live_and_init_locals[statement_index]); } init.seek_to_block_end(block); @@ -478,7 +505,7 @@ impl Conflicts { conflicts.intersect(live.get()); trace!("record conflicts at end of {:?}", block); - record_conflicts(&conflicts); + record_conflicts(&mut conflicts); } Self { matrix: conflicts, unify_cache: BitSet::new_empty(body.local_decls.len()) } From 85750269cb0531498531eb11fbf086c5f9d2f51d Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 26 May 2020 21:39:24 +0200 Subject: [PATCH 09/15] perf: bail out when there's >500 candidate locals --- src/librustc_mir/transform/dest_prop.rs | 30 ++++++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/librustc_mir/transform/dest_prop.rs b/src/librustc_mir/transform/dest_prop.rs index 5ea1e94a840b2..4ed829c37189f 100644 --- a/src/librustc_mir/transform/dest_prop.rs +++ b/src/librustc_mir/transform/dest_prop.rs @@ -114,6 +114,8 @@ use rustc_middle::mir::{ }; use rustc_middle::ty::{self, Ty, TyCtxt}; +const MAX_LOCALS: usize = 500; + pub struct DestinationPropagation; impl<'tcx> MirPass<'tcx> for DestinationPropagation { @@ -137,7 +139,29 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation { relevant_locals.insert(*src); } + // This pass unfortunately has `O(l² * s)` performance, where `l` is the number of locals + // and `s` is the number of statements and terminators in the function. + // To prevent blowing up compile times too much, we bail out when there are too many locals. + let relevant = relevant_locals.count(); + debug!( + "{:?}: {} locals ({} relevant), {} blocks", + source.def_id(), + body.local_decls.len(), + relevant, + body.basic_blocks().len() + ); + if relevant > MAX_LOCALS { + warn!( + "too many candidate locals in {:?} ({}, max is {}), not optimizing", + source.def_id(), + relevant, + MAX_LOCALS + ); + return; + } + let mut conflicts = Conflicts::build(tcx, body, source, &relevant_locals); + let mut replacements = Replacements::new(body.local_decls.len()); for candidate @ CandidateAssignment { dest, src, loc } in candidates { // Merge locals that don't conflict. @@ -392,12 +416,6 @@ impl Conflicts { // We don't have to look out for locals that have their address taken, since // `find_candidates` already takes care of that. - debug!( - "Conflicts::build: {}/{} locals relevant", - relevant_locals.count(), - body.local_decls.len() - ); - let mut conflicts = BitMatrix::from_row_n( &BitSet::new_empty(body.local_decls.len()), body.local_decls.len(), From d6fe24cddf1afb54ebceac607b23337883b843f6 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 5 Jun 2020 00:13:29 +0200 Subject: [PATCH 10/15] Record intra-statement/terminator conflicts Some MIR statements and terminators have an (undocumented...) invariant that some of their input and outputs must not overlap. This records conflicts between locals used in these positions. --- src/librustc_mir/transform/dest_prop.rs | 228 +++++++++++++++++++++--- 1 file changed, 206 insertions(+), 22 deletions(-) diff --git a/src/librustc_mir/transform/dest_prop.rs b/src/librustc_mir/transform/dest_prop.rs index 4ed829c37189f..91ca11c4aa91b 100644 --- a/src/librustc_mir/transform/dest_prop.rs +++ b/src/librustc_mir/transform/dest_prop.rs @@ -109,8 +109,8 @@ use rustc_index::{ use rustc_middle::mir::tcx::PlaceTy; use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor}; use rustc_middle::mir::{ - traversal, Body, Local, LocalKind, Location, Operand, Place, PlaceElem, Rvalue, Statement, - StatementKind, Terminator, TerminatorKind, + traversal, Body, InlineAsmOperand, Local, LocalKind, Location, Operand, Place, PlaceElem, + Rvalue, Statement, StatementKind, Terminator, TerminatorKind, }; use rustc_middle::ty::{self, Ty, TyCtxt}; @@ -397,7 +397,9 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> { } } -struct Conflicts { +struct Conflicts<'a> { + relevant_locals: &'a BitSet, + /// The conflict matrix. It is always symmetric and the adjacency matrix of the corresponding /// conflict graph. matrix: BitMatrix, @@ -406,30 +408,21 @@ struct Conflicts { unify_cache: BitSet, } -impl Conflicts { +impl Conflicts<'a> { fn build<'tcx>( tcx: TyCtxt<'tcx>, body: &'_ Body<'tcx>, source: MirSource<'tcx>, - relevant_locals: &BitSet, + relevant_locals: &'a BitSet, ) -> Self { // We don't have to look out for locals that have their address taken, since // `find_candidates` already takes care of that. - let mut conflicts = BitMatrix::from_row_n( + let conflicts = BitMatrix::from_row_n( &BitSet::new_empty(body.local_decls.len()), body.local_decls.len(), ); - let mut record_conflicts = |new_conflicts: &mut BitSet<_>| { - // Remove all locals that are not candidates. - new_conflicts.intersect(relevant_locals); - - for local in new_conflicts.iter() { - conflicts.union_row_with(&new_conflicts, local); - } - }; - let def_id = source.def_id(); let mut init = MaybeInitializedLocals .into_engine(tcx, body, def_id) @@ -480,6 +473,12 @@ impl Conflicts { }, ); + let mut this = Self { + relevant_locals, + matrix: conflicts, + unify_cache: BitSet::new_empty(body.local_decls.len()), + }; + let mut live_and_init_locals = Vec::new(); // Visit only reachable basic blocks. The exact order is not important. @@ -497,14 +496,22 @@ impl Conflicts { BitSet::new_empty(body.local_decls.len()) }); - // First, go forwards for `MaybeInitializedLocals`. - for statement_index in 0..=data.statements.len() { - let loc = Location { block, statement_index }; + // First, go forwards for `MaybeInitializedLocals` and apply intra-statement/terminator + // conflicts. + for (i, statement) in data.statements.iter().enumerate() { + this.record_statement_conflicts(statement); + + let loc = Location { block, statement_index: i }; init.seek_before_primary_effect(loc); - live_and_init_locals[statement_index].overwrite(init.get()); + live_and_init_locals[i].overwrite(init.get()); } + this.record_terminator_conflicts(data.terminator()); + let term_loc = Location { block, statement_index: data.statements.len() }; + init.seek_before_primary_effect(term_loc); + live_and_init_locals[term_loc.statement_index].overwrite(init.get()); + // Now, go backwards and union with the liveness results. for statement_index in (0..=data.statements.len()).rev() { let loc = Location { block, statement_index }; @@ -514,7 +521,7 @@ impl Conflicts { trace!("record conflicts at {:?}", loc); - record_conflicts(&mut live_and_init_locals[statement_index]); + this.record_conflicts(&mut live_and_init_locals[statement_index]); } init.seek_to_block_end(block); @@ -523,10 +530,187 @@ impl Conflicts { conflicts.intersect(live.get()); trace!("record conflicts at end of {:?}", block); - record_conflicts(&mut conflicts); + this.record_conflicts(&mut conflicts); + } + + this + } + + fn record_conflicts(&mut self, new_conflicts: &mut BitSet) { + // Remove all locals that are not candidates. + new_conflicts.intersect(self.relevant_locals); + + for local in new_conflicts.iter() { + self.matrix.union_row_with(&new_conflicts, local); + } + } + + /// Records locals that must not overlap during the evaluation of `stmt`. These locals conflict + /// and must not be merged. + fn record_statement_conflicts(&mut self, stmt: &Statement<'_>) { + match &stmt.kind { + // While the left and right sides of an assignment must not overlap, we do not mark + // conflicts here as that would make this optimization useless. When we optimize, we + // eliminate the resulting self-assignments automatically. + StatementKind::Assign(_) => {} + + StatementKind::LlvmInlineAsm(asm) => { + // Inputs and outputs must not overlap. + for (_, input) in &*asm.inputs { + if let Some(in_place) = input.place() { + if !in_place.is_indirect() { + for out_place in &*asm.outputs { + if !out_place.is_indirect() && !in_place.is_indirect() { + self.matrix.insert(in_place.local, out_place.local); + self.matrix.insert(out_place.local, in_place.local); + } + } + } + } + } + } + + StatementKind::SetDiscriminant { .. } + | StatementKind::StorageLive(_) + | StatementKind::StorageDead(_) + | StatementKind::Retag(_, _) + | StatementKind::FakeRead(_, _) + | StatementKind::AscribeUserType(_, _) + | StatementKind::Nop => {} } + } - Self { matrix: conflicts, unify_cache: BitSet::new_empty(body.local_decls.len()) } + fn record_terminator_conflicts(&mut self, term: &Terminator<'_>) { + match &term.kind { + TerminatorKind::DropAndReplace { location, value, target: _, unwind: _ } => { + if let Some(place) = value.place() { + if !place.is_indirect() && !location.is_indirect() { + self.matrix.insert(place.local, location.local); + self.matrix.insert(location.local, place.local); + } + } + } + TerminatorKind::Yield { value, resume: _, resume_arg, drop: _ } => { + if let Some(place) = value.place() { + if !place.is_indirect() && !resume_arg.is_indirect() { + self.matrix.insert(place.local, resume_arg.local); + self.matrix.insert(resume_arg.local, place.local); + } + } + } + TerminatorKind::Call { + func, + args, + destination: Some((dest_place, _)), + cleanup: _, + from_hir_call: _, + } => { + // No arguments may overlap with the destination. + for arg in args.iter().chain(Some(func)) { + if let Some(place) = arg.place() { + if !place.is_indirect() && !dest_place.is_indirect() { + self.matrix.insert(dest_place.local, place.local); + self.matrix.insert(place.local, dest_place.local); + } + } + } + } + TerminatorKind::InlineAsm { + template: _, + operands, + options: _, + line_spans: _, + destination: _, + } => { + // The intended semantics here aren't documented, we just assume that nothing that + // could be written to by the assembly may overlap with any other operands. + for op in operands { + match op { + InlineAsmOperand::Out { reg: _, late: _, place: Some(dest_place) } + | InlineAsmOperand::InOut { + reg: _, + late: _, + in_value: _, + out_place: Some(dest_place), + } => { + // For output place `place`, add all places accessed by the inline asm. + for op in operands { + match op { + InlineAsmOperand::In { reg: _, value } => { + if let Some(p) = value.place() { + if !p.is_indirect() && !dest_place.is_indirect() { + self.matrix.insert(p.local, dest_place.local); + self.matrix.insert(dest_place.local, p.local); + } + } + } + InlineAsmOperand::Out { + reg: _, + late: _, + place: Some(place), + } => { + if !place.is_indirect() && !dest_place.is_indirect() { + self.matrix.insert(place.local, dest_place.local); + self.matrix.insert(dest_place.local, place.local); + } + } + InlineAsmOperand::InOut { + reg: _, + late: _, + in_value, + out_place, + } => { + if let Some(place) = in_value.place() { + if !place.is_indirect() && !dest_place.is_indirect() { + self.matrix.insert(place.local, dest_place.local); + self.matrix.insert(dest_place.local, place.local); + } + } + + if let Some(place) = out_place { + if !place.is_indirect() && !dest_place.is_indirect() { + self.matrix.insert(place.local, dest_place.local); + self.matrix.insert(dest_place.local, place.local); + } + } + } + InlineAsmOperand::Out { reg: _, late: _, place: None } + | InlineAsmOperand::Const { value: _ } + | InlineAsmOperand::SymFn { value: _ } + | InlineAsmOperand::SymStatic { value: _ } => {} + } + } + } + InlineAsmOperand::Const { value } => { + assert!(value.place().is_none()); + } + InlineAsmOperand::InOut { + reg: _, + late: _, + in_value: _, + out_place: None, + } + | InlineAsmOperand::In { reg: _, value: _ } + | InlineAsmOperand::Out { reg: _, late: _, place: None } + | InlineAsmOperand::SymFn { value: _ } + | InlineAsmOperand::SymStatic { value: _ } => {} + } + } + } + + TerminatorKind::Goto { .. } + | TerminatorKind::Call { destination: None, .. } + | TerminatorKind::SwitchInt { .. } + | TerminatorKind::Resume + | TerminatorKind::Abort + | TerminatorKind::Return + | TerminatorKind::Unreachable + | TerminatorKind::Drop { .. } + | TerminatorKind::Assert { .. } + | TerminatorKind::GeneratorDrop + | TerminatorKind::FalseEdges { .. } + | TerminatorKind::FalseUnwind { .. } => {} + } } fn contains(&self, a: Local, b: Local) -> bool { From b7c44d37b19f90c5dfa5b497d268a903951de363 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 23 Jun 2020 01:25:52 +0200 Subject: [PATCH 11/15] More logging --- src/librustc_mir/transform/dest_prop.rs | 80 ++++++++++++++++++------- 1 file changed, 59 insertions(+), 21 deletions(-) diff --git a/src/librustc_mir/transform/dest_prop.rs b/src/librustc_mir/transform/dest_prop.rs index 91ca11c4aa91b..dc8b7331a466b 100644 --- a/src/librustc_mir/transform/dest_prop.rs +++ b/src/librustc_mir/transform/dest_prop.rs @@ -95,12 +95,13 @@ //! [previous attempt]: https://github.com/rust-lang/rust/pull/47954 //! [subsequent approach]: https://github.com/rust-lang/rust/pull/71003 -use crate::dataflow::{self, Analysis}; +use crate::dataflow::impls::{MaybeInitializedLocals, MaybeLiveLocals}; +use crate::dataflow::Analysis; use crate::{ transform::{MirPass, MirSource}, util::{dump_mir, PassWhere}, }; -use dataflow::impls::{MaybeInitializedLocals, MaybeLiveLocals}; +use itertools::Itertools; use rustc_data_structures::unify::{InPlaceUnificationTable, UnifyKey}; use rustc_index::{ bit_set::{BitMatrix, BitSet}, @@ -255,12 +256,14 @@ impl Replacements<'tcx> { // We still return `Err` in any case, as `src` and `dest` do not need to be unified // *again*. + trace!("push({:?}): already unified", candidate); return Err(()); } let entry = &mut self.map[candidate.src]; if entry.is_some() { // We're already replacing `src` with something else, so this candidate is out. + trace!("push({:?}): src already has replacement", candidate); return Err(()); } @@ -270,6 +273,7 @@ impl Replacements<'tcx> { self.kill.insert(candidate.src); self.kill.insert(candidate.dest.local); + trace!("push({:?}): accepted", candidate); Ok(()) } @@ -521,7 +525,7 @@ impl Conflicts<'a> { trace!("record conflicts at {:?}", loc); - this.record_conflicts(&mut live_and_init_locals[statement_index]); + this.record_dataflow_conflicts(&mut live_and_init_locals[statement_index]); } init.seek_to_block_end(block); @@ -530,13 +534,13 @@ impl Conflicts<'a> { conflicts.intersect(live.get()); trace!("record conflicts at end of {:?}", block); - this.record_conflicts(&mut conflicts); + this.record_dataflow_conflicts(&mut conflicts); } this } - fn record_conflicts(&mut self, new_conflicts: &mut BitSet) { + fn record_dataflow_conflicts(&mut self, new_conflicts: &mut BitSet) { // Remove all locals that are not candidates. new_conflicts.intersect(self.relevant_locals); @@ -545,6 +549,12 @@ impl Conflicts<'a> { } } + fn record_local_conflict(&mut self, a: Local, b: Local, why: &str) { + trace!("conflict {:?} <-> {:?} due to {}", a, b, why); + self.matrix.insert(a, b); + self.matrix.insert(b, a); + } + /// Records locals that must not overlap during the evaluation of `stmt`. These locals conflict /// and must not be merged. fn record_statement_conflicts(&mut self, stmt: &Statement<'_>) { @@ -561,8 +571,11 @@ impl Conflicts<'a> { if !in_place.is_indirect() { for out_place in &*asm.outputs { if !out_place.is_indirect() && !in_place.is_indirect() { - self.matrix.insert(in_place.local, out_place.local); - self.matrix.insert(out_place.local, in_place.local); + self.record_local_conflict( + in_place.local, + out_place.local, + "aliasing llvm_asm! operands", + ); } } } @@ -585,16 +598,22 @@ impl Conflicts<'a> { TerminatorKind::DropAndReplace { location, value, target: _, unwind: _ } => { if let Some(place) = value.place() { if !place.is_indirect() && !location.is_indirect() { - self.matrix.insert(place.local, location.local); - self.matrix.insert(location.local, place.local); + self.record_local_conflict( + place.local, + location.local, + "DropAndReplace operand overlap", + ); } } } TerminatorKind::Yield { value, resume: _, resume_arg, drop: _ } => { if let Some(place) = value.place() { if !place.is_indirect() && !resume_arg.is_indirect() { - self.matrix.insert(place.local, resume_arg.local); - self.matrix.insert(resume_arg.local, place.local); + self.record_local_conflict( + place.local, + resume_arg.local, + "Yield operand overlap", + ); } } } @@ -609,8 +628,11 @@ impl Conflicts<'a> { for arg in args.iter().chain(Some(func)) { if let Some(place) = arg.place() { if !place.is_indirect() && !dest_place.is_indirect() { - self.matrix.insert(dest_place.local, place.local); - self.matrix.insert(place.local, dest_place.local); + self.record_local_conflict( + dest_place.local, + place.local, + "call dest/arg overlap", + ); } } } @@ -639,8 +661,11 @@ impl Conflicts<'a> { InlineAsmOperand::In { reg: _, value } => { if let Some(p) = value.place() { if !p.is_indirect() && !dest_place.is_indirect() { - self.matrix.insert(p.local, dest_place.local); - self.matrix.insert(dest_place.local, p.local); + self.record_local_conflict( + p.local, + dest_place.local, + "asm! operand overlap", + ); } } } @@ -650,8 +675,11 @@ impl Conflicts<'a> { place: Some(place), } => { if !place.is_indirect() && !dest_place.is_indirect() { - self.matrix.insert(place.local, dest_place.local); - self.matrix.insert(dest_place.local, place.local); + self.record_local_conflict( + place.local, + dest_place.local, + "asm! operand overlap", + ); } } InlineAsmOperand::InOut { @@ -662,15 +690,21 @@ impl Conflicts<'a> { } => { if let Some(place) = in_value.place() { if !place.is_indirect() && !dest_place.is_indirect() { - self.matrix.insert(place.local, dest_place.local); - self.matrix.insert(dest_place.local, place.local); + self.record_local_conflict( + place.local, + dest_place.local, + "asm! operand overlap", + ); } } if let Some(place) = out_place { if !place.is_indirect() && !dest_place.is_indirect() { - self.matrix.insert(place.local, dest_place.local); - self.matrix.insert(dest_place.local, place.local); + self.record_local_conflict( + place.local, + dest_place.local, + "asm! operand overlap", + ); } } } @@ -736,6 +770,10 @@ impl Conflicts<'a> { // FIXME: This might be somewhat slow. Conflict graphs are undirected, maybe we can use // something with union-find to speed this up? + trace!("unify({:?}, {:?})", a, b); + trace!("{:?} conflicts: {:?}", a, self.matrix.iter(a).format(", ")); + trace!("{:?} conflicts: {:?}", b, self.matrix.iter(b).format(", ")); + // Make all locals that conflict with `a` also conflict with `b`, and vice versa. self.unify_cache.clear(); for conflicts_with_a in self.matrix.iter(a) { From 97d49ef61b24657cebde3f998696acfe698aeaad Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 24 Jun 2020 02:23:53 +0200 Subject: [PATCH 12/15] Properly inherit conflicts when merging locals --- src/librustc_mir/transform/dest_prop.rs | 113 +++++++++++--------- src/test/ui/dest-prop/skeptic-miscompile.rs | 24 +++++ 2 files changed, 84 insertions(+), 53 deletions(-) create mode 100644 src/test/ui/dest-prop/skeptic-miscompile.rs diff --git a/src/librustc_mir/transform/dest_prop.rs b/src/librustc_mir/transform/dest_prop.rs index dc8b7331a466b..2d00be8c80f99 100644 --- a/src/librustc_mir/transform/dest_prop.rs +++ b/src/librustc_mir/transform/dest_prop.rs @@ -166,20 +166,24 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation { let mut replacements = Replacements::new(body.local_decls.len()); for candidate @ CandidateAssignment { dest, src, loc } in candidates { // Merge locals that don't conflict. - if conflicts.contains(dest.local, src) { + if !conflicts.can_unify(dest.local, src) { debug!("at assignment {:?}, conflict {:?} vs. {:?}", loc, dest.local, src); continue; } + if replacements.for_src(candidate.src).is_some() { + debug!("src {:?} already has replacement", candidate.src); + continue; + } + if !tcx.consider_optimizing(|| { format!("DestinationPropagation {:?} {:?}", source.def_id(), candidate) }) { break; } - if replacements.push(candidate).is_ok() { - conflicts.unify(candidate.src, candidate.dest.local); - } + replacements.push(candidate); + conflicts.unify(candidate.src, candidate.dest.local); } replacements.flatten(tcx); @@ -220,61 +224,21 @@ struct Replacements<'tcx> { /// Whose locals' live ranges to kill. kill: BitSet, - - /// Tracks locals that have already been merged together to prevent cycles. - unified_locals: InPlaceUnificationTable, } impl Replacements<'tcx> { fn new(locals: usize) -> Self { - Self { - map: IndexVec::from_elem_n(None, locals), - kill: BitSet::new_empty(locals), - unified_locals: { - let mut table = InPlaceUnificationTable::new(); - for local in 0..locals { - assert_eq!(table.new_key(()), UnifyLocal(Local::from_usize(local))); - } - table - }, - } + Self { map: IndexVec::from_elem_n(None, locals), kill: BitSet::new_empty(locals) } } - fn push(&mut self, candidate: CandidateAssignment<'tcx>) -> Result<(), ()> { - if self.unified_locals.unioned(candidate.src, candidate.dest.local) { - // Candidate conflicts with previous replacement (ie. could possibly form a cycle and - // hang). - - let replacement = self.map[candidate.src].as_mut().unwrap(); - - // If the current replacement is for the same `dest` local, there are 2 or more - // equivalent `src = dest;` assignments. This is fine, the replacer will `nop` out all - // of them. - if replacement.local == candidate.dest.local { - assert_eq!(replacement.projection, candidate.dest.projection); - } - - // We still return `Err` in any case, as `src` and `dest` do not need to be unified - // *again*. - trace!("push({:?}): already unified", candidate); - return Err(()); - } - + fn push(&mut self, candidate: CandidateAssignment<'tcx>) { + trace!("Replacements::push({:?})", candidate); let entry = &mut self.map[candidate.src]; - if entry.is_some() { - // We're already replacing `src` with something else, so this candidate is out. - trace!("push({:?}): src already has replacement", candidate); - return Err(()); - } - - self.unified_locals.union(candidate.src, candidate.dest.local); + assert!(entry.is_none()); *entry = Some(candidate.dest); self.kill.insert(candidate.src); self.kill.insert(candidate.dest.local); - - trace!("push({:?}): accepted", candidate); - Ok(()) } /// Applies the stored replacements to all replacements, until no replacements would result in @@ -410,6 +374,9 @@ struct Conflicts<'a> { /// Preallocated `BitSet` used by `unify`. unify_cache: BitSet, + + /// Tracks locals that have been merged together to prevent cycles and propagate conflicts. + unified_locals: InPlaceUnificationTable, } impl Conflicts<'a> { @@ -481,6 +448,15 @@ impl Conflicts<'a> { relevant_locals, matrix: conflicts, unify_cache: BitSet::new_empty(body.local_decls.len()), + unified_locals: { + let mut table = InPlaceUnificationTable::new(); + // Pre-fill table with all locals (this creates N nodes / "connected" components, + // "graph"-ically speaking). + for local in 0..body.local_decls.len() { + assert_eq!(table.new_key(()), UnifyLocal(Local::from_usize(local))); + } + table + }, }; let mut live_and_init_locals = Vec::new(); @@ -747,11 +723,31 @@ impl Conflicts<'a> { } } - fn contains(&self, a: Local, b: Local) -> bool { - self.matrix.contains(a, b) + /// Checks whether `a` and `b` may be merged. Returns `false` if there's a conflict. + fn can_unify(&mut self, a: Local, b: Local) -> bool { + // After some locals have been unified, their conflicts are only tracked in the root key, + // so look that up. + let a = self.unified_locals.find(a).0; + let b = self.unified_locals.find(b).0; + + if a == b { + // Already merged (part of the same connected component). + return false; + } + + if self.matrix.contains(a, b) { + // Conflict (derived via dataflow, intra-statement conflicts, or inherited from another + // local during unification). + return false; + } + + true } /// Merges the conflicts of `a` and `b`, so that each one inherits all conflicts of the other. + /// + /// `can_unify` must have returned `true` for the same locals, or this may panic or lead to + /// miscompiles. /// /// This is called when the pass makes the decision to unify `a` and `b` (or parts of `a` and /// `b`) and is needed to ensure that future unification decisions take potentially newly @@ -767,13 +763,24 @@ impl Conflicts<'a> { /// `_2` with `_0`, which also doesn't have a conflict in the above list. However `_2` is now /// `_3`, which does conflict with `_0`. fn unify(&mut self, a: Local, b: Local) { - // FIXME: This might be somewhat slow. Conflict graphs are undirected, maybe we can use - // something with union-find to speed this up? - trace!("unify({:?}, {:?})", a, b); + + // Get the root local of the connected components. The root local stores the conflicts of + // all locals in the connected component (and *is stored* as the conflicting local of other + // locals). + let a = self.unified_locals.find(a).0; + let b = self.unified_locals.find(b).0; + assert_ne!(a, b); + + trace!("roots: a={:?}, b={:?}", a, b); trace!("{:?} conflicts: {:?}", a, self.matrix.iter(a).format(", ")); trace!("{:?} conflicts: {:?}", b, self.matrix.iter(b).format(", ")); + self.unified_locals.union(a, b); + + let root = self.unified_locals.find(a).0; + assert!(root == a || root == b); + // Make all locals that conflict with `a` also conflict with `b`, and vice versa. self.unify_cache.clear(); for conflicts_with_a in self.matrix.iter(a) { diff --git a/src/test/ui/dest-prop/skeptic-miscompile.rs b/src/test/ui/dest-prop/skeptic-miscompile.rs new file mode 100644 index 0000000000000..c27a1f04532e7 --- /dev/null +++ b/src/test/ui/dest-prop/skeptic-miscompile.rs @@ -0,0 +1,24 @@ +// run-pass + +// compile-flags: -Zmir-opt-level=2 + +trait IterExt: Iterator { + fn fold_ex(mut self, init: B, mut f: F) -> B + where + Self: Sized, + F: FnMut(B, Self::Item) -> B, + { + let mut accum = init; + while let Some(x) = self.next() { + accum = f(accum, x); + } + accum + } +} + +impl IterExt for T {} + +fn main() { + let test = &["\n"]; + test.iter().fold_ex(String::new(), |_, b| b.to_string()); +} From 731dbe3a78622c0977888b9d01a377f405db2018 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 24 Jun 2020 02:47:16 +0200 Subject: [PATCH 13/15] Fix rebase fallout --- src/librustc_mir/transform/dest_prop.rs | 26 ++++++++++++------- .../rustc.nrvo.DestinationPropagation.diff | 17 +++++------- .../rustc.nrvo.RenameReturnPlace.diff | 9 ++++--- ...ustc.try_identity.SimplifyArmIdentity.diff | 13 +++++----- 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/librustc_mir/transform/dest_prop.rs b/src/librustc_mir/transform/dest_prop.rs index 2d00be8c80f99..75963ddbb2ecc 100644 --- a/src/librustc_mir/transform/dest_prop.rs +++ b/src/librustc_mir/transform/dest_prop.rs @@ -571,12 +571,17 @@ impl Conflicts<'a> { fn record_terminator_conflicts(&mut self, term: &Terminator<'_>) { match &term.kind { - TerminatorKind::DropAndReplace { location, value, target: _, unwind: _ } => { + TerminatorKind::DropAndReplace { + place: dropped_place, + value, + target: _, + unwind: _, + } => { if let Some(place) = value.place() { - if !place.is_indirect() && !location.is_indirect() { + if !place.is_indirect() && !dropped_place.is_indirect() { self.record_local_conflict( place.local, - location.local, + dropped_place.local, "DropAndReplace operand overlap", ); } @@ -599,6 +604,7 @@ impl Conflicts<'a> { destination: Some((dest_place, _)), cleanup: _, from_hir_call: _, + fn_span: _, } => { // No arguments may overlap with the destination. for arg in args.iter().chain(Some(func)) { @@ -687,7 +693,7 @@ impl Conflicts<'a> { InlineAsmOperand::Out { reg: _, late: _, place: None } | InlineAsmOperand::Const { value: _ } | InlineAsmOperand::SymFn { value: _ } - | InlineAsmOperand::SymStatic { value: _ } => {} + | InlineAsmOperand::SymStatic { def_id: _ } => {} } } } @@ -703,7 +709,7 @@ impl Conflicts<'a> { | InlineAsmOperand::In { reg: _, value: _ } | InlineAsmOperand::Out { reg: _, late: _, place: None } | InlineAsmOperand::SymFn { value: _ } - | InlineAsmOperand::SymStatic { value: _ } => {} + | InlineAsmOperand::SymStatic { def_id: _ } => {} } } } @@ -718,7 +724,7 @@ impl Conflicts<'a> { | TerminatorKind::Drop { .. } | TerminatorKind::Assert { .. } | TerminatorKind::GeneratorDrop - | TerminatorKind::FalseEdges { .. } + | TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } => {} } } @@ -745,7 +751,7 @@ impl Conflicts<'a> { } /// Merges the conflicts of `a` and `b`, so that each one inherits all conflicts of the other. - /// + /// /// `can_unify` must have returned `true` for the same locals, or this may panic or lead to /// miscompiles. /// @@ -963,15 +969,15 @@ fn ever_borrowed_locals(body: &Body<'_>) -> BitSet { self.super_terminator(terminator, location); match terminator.kind { - TerminatorKind::Drop { location: dropped_place, .. } - | TerminatorKind::DropAndReplace { location: dropped_place, .. } => { + TerminatorKind::Drop { place: dropped_place, .. } + | TerminatorKind::DropAndReplace { place: dropped_place, .. } => { self.locals.insert(dropped_place.local); } TerminatorKind::Abort | TerminatorKind::Assert { .. } | TerminatorKind::Call { .. } - | TerminatorKind::FalseEdges { .. } + | TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } | TerminatorKind::GeneratorDrop | TerminatorKind::Goto { .. } diff --git a/src/test/mir-opt/dest-prop/simple/rustc.nrvo.DestinationPropagation.diff b/src/test/mir-opt/dest-prop/simple/rustc.nrvo.DestinationPropagation.diff index d59e1f3c0c938..d6343f3fcd762 100644 --- a/src/test/mir-opt/dest-prop/simple/rustc.nrvo.DestinationPropagation.diff +++ b/src/test/mir-opt/dest-prop/simple/rustc.nrvo.DestinationPropagation.diff @@ -28,23 +28,18 @@ StorageLive(_3); // scope 1 at $DIR/simple.rs:6:5: 6:19 StorageLive(_4); // scope 1 at $DIR/simple.rs:6:5: 6:9 _4 = _1; // scope 1 at $DIR/simple.rs:6:5: 6:9 -- StorageLive(_5); // scope 1 at $DIR/simple.rs:6:10: 6:18 -- StorageLive(_6); // scope 1 at $DIR/simple.rs:6:10: 6:18 + StorageLive(_5); // scope 1 at $DIR/simple.rs:6:10: 6:18 + StorageLive(_6); // scope 1 at $DIR/simple.rs:6:10: 6:18 - _6 = &mut _2; // scope 1 at $DIR/simple.rs:6:10: 6:18 -- _5 = move _6; // scope 1 at $DIR/simple.rs:6:10: 6:18 -+ nop; // scope 1 at $DIR/simple.rs:6:10: 6:18 -+ nop; // scope 1 at $DIR/simple.rs:6:10: 6:18 -+ _5 = &mut _0; // scope 1 at $DIR/simple.rs:6:10: 6:18 -+ nop; // scope 1 at $DIR/simple.rs:6:10: 6:18 ++ _6 = &mut _0; // scope 1 at $DIR/simple.rs:6:10: 6:18 + _5 = &mut (*_6); // scope 1 at $DIR/simple.rs:6:10: 6:18 _3 = move _4(move _5) -> bb1; // scope 1 at $DIR/simple.rs:6:5: 6:19 } bb1: { -- StorageDead(_5); // scope 1 at $DIR/simple.rs:6:18: 6:19 -+ nop; // scope 1 at $DIR/simple.rs:6:18: 6:19 + StorageDead(_5); // scope 1 at $DIR/simple.rs:6:18: 6:19 StorageDead(_4); // scope 1 at $DIR/simple.rs:6:18: 6:19 -- StorageDead(_6); // scope 1 at $DIR/simple.rs:6:19: 6:20 -+ nop; // scope 1 at $DIR/simple.rs:6:19: 6:20 + StorageDead(_6); // scope 1 at $DIR/simple.rs:6:19: 6:20 StorageDead(_3); // scope 1 at $DIR/simple.rs:6:19: 6:20 - _0 = _2; // scope 1 at $DIR/simple.rs:7:5: 7:8 - StorageDead(_2); // scope 0 at $DIR/simple.rs:8:1: 8:2 diff --git a/src/test/mir-opt/nrvo-simple/rustc.nrvo.RenameReturnPlace.diff b/src/test/mir-opt/nrvo-simple/rustc.nrvo.RenameReturnPlace.diff index 05c09f222aeb9..96866bfe21f4f 100644 --- a/src/test/mir-opt/nrvo-simple/rustc.nrvo.RenameReturnPlace.diff +++ b/src/test/mir-opt/nrvo-simple/rustc.nrvo.RenameReturnPlace.diff @@ -1,6 +1,6 @@ - // MIR for `nrvo` before RenameReturnPlace + // MIR for `nrvo` after RenameReturnPlace - + fn nrvo(_1: for<'r> fn(&'r mut [u8; 1024])) -> [u8; 1024] { debug init => _1; // in scope 0 at $DIR/nrvo-simple.rs:4:9: 4:13 - let mut _0: [u8; 1024]; // return place in scope 0 at $DIR/nrvo-simple.rs:4:39: 4:49 @@ -14,7 +14,7 @@ - debug buf => _2; // in scope 1 at $DIR/nrvo-simple.rs:5:9: 5:16 + debug buf => _0; // in scope 1 at $DIR/nrvo-simple.rs:5:9: 5:16 } - + bb0: { - StorageLive(_2); // scope 0 at $DIR/nrvo-simple.rs:5:9: 5:16 - _2 = [const 0u8; 1024]; // scope 0 at $DIR/nrvo-simple.rs:5:19: 5:28 @@ -32,10 +32,10 @@ StorageLive(_6); // scope 1 at $DIR/nrvo-simple.rs:6:10: 6:18 - _6 = &mut _2; // scope 1 at $DIR/nrvo-simple.rs:6:10: 6:18 + _6 = &mut _0; // scope 1 at $DIR/nrvo-simple.rs:6:10: 6:18 - _5 = move _6; // scope 1 at $DIR/nrvo-simple.rs:6:10: 6:18 + _5 = &mut (*_6); // scope 1 at $DIR/nrvo-simple.rs:6:10: 6:18 _3 = move _4(move _5) -> bb1; // scope 1 at $DIR/nrvo-simple.rs:6:5: 6:19 } - + bb1: { StorageDead(_5); // scope 1 at $DIR/nrvo-simple.rs:6:18: 6:19 StorageDead(_4); // scope 1 at $DIR/nrvo-simple.rs:6:18: 6:19 @@ -46,3 +46,4 @@ return; // scope 0 at $DIR/nrvo-simple.rs:8:2: 8:2 } } + diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff index 143e7c8c27f38..df8b046c386d6 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff @@ -1,6 +1,6 @@ - // MIR for `try_identity` before SimplifyArmIdentity + // MIR for `try_identity` after SimplifyArmIdentity - + fn try_identity(_1: std::result::Result) -> std::result::Result { debug x => _1; // in scope 0 at $DIR/simplify_try.rs:6:17: 6:18 let mut _0: std::result::Result; // return place in scope 0 at $DIR/simplify_try.rs:6:41: 6:57 @@ -37,7 +37,7 @@ scope 6 { debug self => _4; // in scope 6 at $SRC_DIR/libcore/result.rs:LL:COL } - + bb0: { StorageLive(_2); // scope 0 at $DIR/simplify_try.rs:7:9: 7:10 StorageLive(_3); // scope 0 at $DIR/simplify_try.rs:7:13: 7:15 @@ -48,7 +48,7 @@ _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 switchInt(move _5) -> [0isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 } - + bb1: { - StorageLive(_10); // scope 0 at $DIR/simplify_try.rs:7:13: 7:15 - _10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:7:13: 7:15 @@ -64,7 +64,7 @@ StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:9:1: 9:2 goto -> bb3; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2 } - + bb2: { - StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 - _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 @@ -83,10 +83,11 @@ + _0 = move _3; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:7:15: 7:16 StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:9:1: 9:2 - goto -> bb3; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2 + goto -> bb3; // scope 0 at $DIR/simplify_try.rs:7:14: 7:15 } - + bb3: { return; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2 } } + From b7600237ce3b0121871cc7fb39f6c685410bbd8b Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 24 Jun 2020 22:55:12 +0200 Subject: [PATCH 14/15] Limit block count --- src/librustc_mir/transform/dest_prop.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/librustc_mir/transform/dest_prop.rs b/src/librustc_mir/transform/dest_prop.rs index 75963ddbb2ecc..3fe20fd676d61 100644 --- a/src/librustc_mir/transform/dest_prop.rs +++ b/src/librustc_mir/transform/dest_prop.rs @@ -115,7 +115,12 @@ use rustc_middle::mir::{ }; use rustc_middle::ty::{self, Ty, TyCtxt}; +// Empirical measurements have resulted in some observations: +// - Running on a body with a single block and 500 locals takes barely any time +// - Running on a body with ~400 blocks and ~300 relevant locals takes "too long" +// ...so we just limit both to somewhat reasonable-ish looking values. const MAX_LOCALS: usize = 500; +const MAX_BLOCKS: usize = 250; pub struct DestinationPropagation; @@ -160,6 +165,15 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation { ); return; } + if body.basic_blocks().len() > MAX_BLOCKS { + warn!( + "too many blocks in {:?} ({}, max is {}), not optimizing", + source.def_id(), + body.basic_blocks().len(), + MAX_BLOCKS + ); + return; + } let mut conflicts = Conflicts::build(tcx, body, source, &relevant_locals); From d36b2871c042a6f9015cb93f24d928035cfa311d Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 27 May 2020 00:51:12 +0200 Subject: [PATCH 15/15] [perf] run destination propagation by default --- src/librustc_mir/transform/dest_prop.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/transform/dest_prop.rs b/src/librustc_mir/transform/dest_prop.rs index 3fe20fd676d61..ec47c72c06c30 100644 --- a/src/librustc_mir/transform/dest_prop.rs +++ b/src/librustc_mir/transform/dest_prop.rs @@ -128,7 +128,7 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation { fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) { // Only run at mir-opt-level=2 or higher for now (we don't fix up debuginfo and remove // storage statements at the moment). - if tcx.sess.opts.debugging_opts.mir_opt_level <= 1 { + if tcx.sess.opts.debugging_opts.mir_opt_level == 0 { return; }