diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index 8f651b2a2db4b..201926fee3e02 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -1333,7 +1333,7 @@ pub enum AggregateKind<'tcx> { Generator(DefId, GenericArgsRef<'tcx>, hir::Movability), } -#[derive(Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)] pub enum NullOp<'tcx> { /// Returns the size of a value of that type SizeOf, diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs new file mode 100644 index 0000000000000..449bade332261 --- /dev/null +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -0,0 +1,538 @@ +//! Global value numbering. +//! +//! MIR may contain repeated and/or redundant computations. The objective of this pass is to detect +//! such redundancies and re-use the already-computed result when possible. +//! +//! In a first pass, we compute a symbolic representation of values that are assigned to SSA +//! locals. This symbolic representation is defined by the `Value` enum. Each produced instance of +//! `Value` is interned as a `VnIndex`, which allows us to cheaply compute identical values. +//! +//! From those assignments, we construct a mapping `VnIndex -> Vec<(Local, Location)>` of available +//! values, the locals in which they are stored, and a the assignment location. +//! +//! In a second pass, we traverse all (non SSA) assignments `x = rvalue` and operands. For each +//! one, we compute the `VnIndex` of the rvalue. If this `VnIndex` is associated to a constant, we +//! replace the rvalue/operand by that constant. Otherwise, if there is an SSA local `y` +//! associated to this `VnIndex`, and if its definition location strictly dominates the assignment +//! to `x`, we replace the assignment by `x = y`. +//! +//! By opportunity, this pass simplifies some `Rvalue`s based on the accumulated knowledge. +//! +//! # Operational semantic +//! +//! Operationally, this pass attempts to prove bitwise equality between locals. Given this MIR: +//! ```ignore (MIR) +//! _a = some value // has VnIndex i +//! // some MIR +//! _b = some other value // also has VnIndex i +//! ``` +//! +//! We consider it to be replacable by: +//! ```ignore (MIR) +//! _a = some value // has VnIndex i +//! // some MIR +//! _c = some other value // also has VnIndex i +//! assume(_a bitwise equal to _c) // follows from having the same VnIndex +//! _b = _a // follows from the `assume` +//! ``` +//! +//! Which is simplifiable to: +//! ```ignore (MIR) +//! _a = some value // has VnIndex i +//! // some MIR +//! _b = _a +//! ``` +//! +//! # Handling of references +//! +//! We handle references by assigning a different "provenance" index to each Ref/AddressOf rvalue. +//! This ensure that we do not spuriously merge borrows that should not be merged. Meanwhile, we +//! consider all the derefs of an immutable reference to a freeze type to give the same value: +//! ```ignore (MIR) +//! _a = *_b // _b is &Freeze +//! _c = *_b // replaced by _c = _a +//! ``` + +use rustc_data_structures::fx::{FxHashMap, FxIndexSet}; +use rustc_data_structures::graph::dominators::Dominators; +use rustc_index::bit_set::BitSet; +use rustc_index::IndexVec; +use rustc_macros::newtype_index; +use rustc_middle::mir::visit::*; +use rustc_middle::mir::*; +use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_target::abi::{VariantIdx, FIRST_VARIANT}; + +use crate::ssa::SsaLocals; +use crate::MirPass; + +pub struct GVN; + +impl<'tcx> MirPass<'tcx> for GVN { + fn is_enabled(&self, sess: &rustc_session::Session) -> bool { + sess.mir_opt_level() >= 4 + } + + #[instrument(level = "trace", skip(self, tcx, body))] + fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + debug!(def_id = ?body.source.def_id()); + propagate_ssa(tcx, body); + } +} + +fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id()); + let ssa = SsaLocals::new(body); + // Clone dominators as we need them while mutating the body. + let dominators = body.basic_blocks.dominators().clone(); + + let mut state = VnState::new(tcx, param_env, &ssa, &dominators, &body.local_decls); + for arg in body.args_iter() { + if ssa.is_ssa(arg) { + let value = state.new_opaque().unwrap(); + state.assign(arg, value); + } + } + + ssa.for_each_assignment_mut(&mut body.basic_blocks, |local, rvalue, location| { + let value = state.simplify_rvalue(rvalue, location).or_else(|| state.new_opaque()).unwrap(); + // FIXME(#112651) `rvalue` may have a subtype to `local`. We can only mark `local` as + // reusable if we have an exact type match. + if state.local_decls[local].ty == rvalue.ty(state.local_decls, tcx) { + state.assign(local, value); + } + }); + + // Stop creating opaques during replacement as it is useless. + state.next_opaque = None; + + let reverse_postorder = body.basic_blocks.reverse_postorder().to_vec(); + for bb in reverse_postorder { + let data = &mut body.basic_blocks.as_mut_preserves_cfg()[bb]; + state.visit_basic_block_data(bb, data); + } + let any_replacement = state.any_replacement; + + // For each local that is reused (`y` above), we remove its storage statements do avoid any + // difficulty. Those locals are SSA, so should be easy to optimize by LLVM without storage + // statements. + StorageRemover { tcx, reused_locals: state.reused_locals }.visit_body_preserves_cfg(body); + + if any_replacement { + crate::simplify::remove_unused_definitions(body); + } +} + +newtype_index! { + struct VnIndex {} +} + +#[derive(Debug, PartialEq, Eq, Hash)] +enum Value<'tcx> { + // Root values. + /// Used to represent values we know nothing about. + /// The `usize` is a counter incremented by `new_opaque`. + Opaque(usize), + /// Evaluated or unevaluated constant value. + Constant(Const<'tcx>), + /// An aggregate value, either tuple/closure/struct/enum. + /// This does not contain unions, as we cannot reason with the value. + Aggregate(Ty<'tcx>, VariantIdx, Vec), + /// This corresponds to a `[value; count]` expression. + Repeat(VnIndex, ty::Const<'tcx>), + /// The address of a place. + Address { + place: Place<'tcx>, + /// Give each borrow and pointer a different provenance, so we don't merge them. + provenance: usize, + }, + + // Extractions. + /// This is the *value* obtained by projecting another value. + Projection(VnIndex, ProjectionElem>), + /// Discriminant of the given value. + Discriminant(VnIndex), + /// Length of an array or slice. + Len(VnIndex), + + // Operations. + NullaryOp(NullOp<'tcx>, Ty<'tcx>), + UnaryOp(UnOp, VnIndex), + BinaryOp(BinOp, VnIndex, VnIndex), + CheckedBinaryOp(BinOp, VnIndex, VnIndex), + Cast { + kind: CastKind, + value: VnIndex, + from: Ty<'tcx>, + to: Ty<'tcx>, + }, +} + +struct VnState<'body, 'tcx> { + tcx: TyCtxt<'tcx>, + param_env: ty::ParamEnv<'tcx>, + local_decls: &'body LocalDecls<'tcx>, + /// Value stored in each local. + locals: IndexVec>, + /// First local to be assigned that value. + rev_locals: FxHashMap>, + values: FxIndexSet>, + /// Counter to generate different values. + /// This is an option to stop creating opaques during replacement. + next_opaque: Option, + ssa: &'body SsaLocals, + dominators: &'body Dominators, + reused_locals: BitSet, + any_replacement: bool, +} + +impl<'body, 'tcx> VnState<'body, 'tcx> { + fn new( + tcx: TyCtxt<'tcx>, + param_env: ty::ParamEnv<'tcx>, + ssa: &'body SsaLocals, + dominators: &'body Dominators, + local_decls: &'body LocalDecls<'tcx>, + ) -> Self { + VnState { + tcx, + param_env, + local_decls, + locals: IndexVec::from_elem(None, local_decls), + rev_locals: FxHashMap::default(), + values: FxIndexSet::default(), + next_opaque: Some(0), + ssa, + dominators, + reused_locals: BitSet::new_empty(local_decls.len()), + any_replacement: false, + } + } + + #[instrument(level = "trace", skip(self), ret)] + fn insert(&mut self, value: Value<'tcx>) -> VnIndex { + let (index, _) = self.values.insert_full(value); + VnIndex::from_usize(index) + } + + /// Create a new `Value` for which we have no information at all, except that it is distinct + /// from all the others. + #[instrument(level = "trace", skip(self), ret)] + fn new_opaque(&mut self) -> Option { + let next_opaque = self.next_opaque.as_mut()?; + let value = Value::Opaque(*next_opaque); + *next_opaque += 1; + Some(self.insert(value)) + } + + /// Create a new `Value::Address` distinct from all the others. + #[instrument(level = "trace", skip(self), ret)] + fn new_pointer(&mut self, place: Place<'tcx>) -> Option { + let next_opaque = self.next_opaque.as_mut()?; + let value = Value::Address { place, provenance: *next_opaque }; + *next_opaque += 1; + Some(self.insert(value)) + } + + fn get(&self, index: VnIndex) -> &Value<'tcx> { + self.values.get_index(index.as_usize()).unwrap() + } + + /// Record that `local` is assigned `value`. `local` must be SSA. + #[instrument(level = "trace", skip(self))] + fn assign(&mut self, local: Local, value: VnIndex) { + self.locals[local] = Some(value); + + // Only register the value if its type is `Sized`, as we will emit copies of it. + let is_sized = !self.tcx.features().unsized_locals + || self.local_decls[local].ty.is_sized(self.tcx, self.param_env); + if is_sized { + self.rev_locals.entry(value).or_default().push(local); + } + } + + /// Represent the *value* which would be read from `place`, and point `place` to a preexisting + /// place with the same value (if that already exists). + #[instrument(level = "trace", skip(self), ret)] + fn simplify_place_value( + &mut self, + place: &mut Place<'tcx>, + location: Location, + ) -> Option { + // Invariant: `place` and `place_ref` point to the same value, even if they point to + // different memory locations. + let mut place_ref = place.as_ref(); + + // Invariant: `value` holds the value up-to the `index`th projection excluded. + let mut value = self.locals[place.local]?; + for (index, proj) in place.projection.iter().enumerate() { + if let Some(local) = self.try_as_local(value, location) { + // Both `local` and `Place { local: place.local, projection: projection[..index] }` + // hold the same value. Therefore, following place holds the value in the original + // `place`. + place_ref = PlaceRef { local, projection: &place.projection[index..] }; + } + + let proj = match proj { + ProjectionElem::Deref => { + let ty = Place::ty_from( + place.local, + &place.projection[..index], + self.local_decls, + self.tcx, + ) + .ty; + if let Some(Mutability::Not) = ty.ref_mutability() + && let Some(pointee_ty) = ty.builtin_deref(true) + && pointee_ty.ty.is_freeze(self.tcx, self.param_env) + { + // An immutable borrow `_x` always points to the same value for the + // lifetime of the borrow, so we can merge all instances of `*_x`. + ProjectionElem::Deref + } else { + return None; + } + } + ProjectionElem::Field(f, ty) => ProjectionElem::Field(f, ty), + ProjectionElem::Index(idx) => { + let idx = self.locals[idx]?; + ProjectionElem::Index(idx) + } + ProjectionElem::ConstantIndex { offset, min_length, from_end } => { + ProjectionElem::ConstantIndex { offset, min_length, from_end } + } + ProjectionElem::Subslice { from, to, from_end } => { + ProjectionElem::Subslice { from, to, from_end } + } + ProjectionElem::Downcast(name, index) => ProjectionElem::Downcast(name, index), + ProjectionElem::OpaqueCast(ty) => ProjectionElem::OpaqueCast(ty), + }; + value = self.insert(Value::Projection(value, proj)); + } + + if let Some(local) = self.try_as_local(value, location) + && local != place.local // in case we had no projection to begin with. + { + *place = local.into(); + self.reused_locals.insert(local); + self.any_replacement = true; + } else if place_ref.local != place.local + || place_ref.projection.len() < place.projection.len() + { + // By the invariant on `place_ref`. + *place = place_ref.project_deeper(&[], self.tcx); + self.reused_locals.insert(place_ref.local); + self.any_replacement = true; + } + + Some(value) + } + + #[instrument(level = "trace", skip(self), ret)] + fn simplify_operand( + &mut self, + operand: &mut Operand<'tcx>, + location: Location, + ) -> Option { + match *operand { + Operand::Constant(ref constant) => Some(self.insert(Value::Constant(constant.const_))), + Operand::Copy(ref mut place) | Operand::Move(ref mut place) => { + let value = self.simplify_place_value(place, location)?; + if let Some(const_) = self.try_as_constant(value) { + *operand = Operand::Constant(Box::new(const_)); + self.any_replacement = true; + } + Some(value) + } + } + } + + #[instrument(level = "trace", skip(self), ret)] + fn simplify_rvalue( + &mut self, + rvalue: &mut Rvalue<'tcx>, + location: Location, + ) -> Option { + let value = match *rvalue { + // Forward values. + Rvalue::Use(ref mut operand) => return self.simplify_operand(operand, location), + Rvalue::CopyForDeref(place) => { + let mut operand = Operand::Copy(place); + let val = self.simplify_operand(&mut operand, location); + *rvalue = Rvalue::Use(operand); + return val; + } + + // Roots. + Rvalue::Repeat(ref mut op, amount) => { + let op = self.simplify_operand(op, location)?; + Value::Repeat(op, amount) + } + Rvalue::NullaryOp(op, ty) => Value::NullaryOp(op, ty), + Rvalue::Aggregate(box ref kind, ref mut fields) => { + let variant_index = match *kind { + AggregateKind::Array(..) + | AggregateKind::Tuple + | AggregateKind::Closure(..) + | AggregateKind::Generator(..) => FIRST_VARIANT, + AggregateKind::Adt(_, variant_index, _, _, None) => variant_index, + // Do not track unions. + AggregateKind::Adt(_, _, _, _, Some(_)) => return None, + }; + let fields: Option> = fields + .iter_mut() + .map(|op| self.simplify_operand(op, location).or_else(|| self.new_opaque())) + .collect(); + let ty = rvalue.ty(self.local_decls, self.tcx); + Value::Aggregate(ty, variant_index, fields?) + } + Rvalue::Ref(.., place) | Rvalue::AddressOf(_, place) => return self.new_pointer(place), + + // Operations. + Rvalue::Len(ref mut place) => { + let place = self.simplify_place_value(place, location)?; + Value::Len(place) + } + Rvalue::Cast(kind, ref mut value, to) => { + let from = value.ty(self.local_decls, self.tcx); + let value = self.simplify_operand(value, location)?; + Value::Cast { kind, value, from, to } + } + Rvalue::BinaryOp(op, box (ref mut lhs, ref mut rhs)) => { + let lhs = self.simplify_operand(lhs, location); + let rhs = self.simplify_operand(rhs, location); + Value::BinaryOp(op, lhs?, rhs?) + } + Rvalue::CheckedBinaryOp(op, box (ref mut lhs, ref mut rhs)) => { + let lhs = self.simplify_operand(lhs, location); + let rhs = self.simplify_operand(rhs, location); + Value::CheckedBinaryOp(op, lhs?, rhs?) + } + Rvalue::UnaryOp(op, ref mut arg) => { + let arg = self.simplify_operand(arg, location)?; + Value::UnaryOp(op, arg) + } + Rvalue::Discriminant(ref mut place) => { + let place = self.simplify_place_value(place, location)?; + Value::Discriminant(place) + } + + // Unsupported values. + Rvalue::ThreadLocalRef(..) | Rvalue::ShallowInitBox(..) => return None, + }; + debug!(?value); + Some(self.insert(value)) + } +} + +impl<'tcx> VnState<'_, 'tcx> { + /// If `index` is a `Value::Constant`, return the `Constant` to be put in the MIR. + fn try_as_constant(&mut self, index: VnIndex) -> Option> { + if let Value::Constant(const_) = *self.get(index) { + // Some constants may contain pointers. We need to preserve the provenance of these + // pointers, but not all constants guarantee this: + // - valtrees purposefully do not; + // - ConstValue::Slice does not either. + match const_ { + Const::Ty(c) => match c.kind() { + ty::ConstKind::Value(valtree) => match valtree { + // This is just an integer, keep it. + ty::ValTree::Leaf(_) => {} + ty::ValTree::Branch(_) => return None, + }, + ty::ConstKind::Param(..) + | ty::ConstKind::Unevaluated(..) + | ty::ConstKind::Expr(..) => {} + // Should not appear in runtime MIR. + ty::ConstKind::Infer(..) + | ty::ConstKind::Bound(..) + | ty::ConstKind::Placeholder(..) + | ty::ConstKind::Error(..) => bug!(), + }, + Const::Unevaluated(..) => {} + // If the same slice appears twice in the MIR, we cannot guarantee that we will + // give the same `AllocId` to the data. + Const::Val(ConstValue::Slice { .. }, _) => return None, + Const::Val( + ConstValue::ZeroSized | ConstValue::Scalar(_) | ConstValue::Indirect { .. }, + _, + ) => {} + } + Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_ }) + } else { + None + } + } + + /// If there is a local which is assigned `index`, and its assignment strictly dominates `loc`, + /// return it. + fn try_as_local(&mut self, index: VnIndex, loc: Location) -> Option { + let other = self.rev_locals.get(&index)?; + other + .iter() + .copied() + .find(|&other| self.ssa.assignment_dominates(self.dominators, other, loc)) + } +} + +impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> { + fn tcx(&self) -> TyCtxt<'tcx> { + self.tcx + } + + fn visit_operand(&mut self, operand: &mut Operand<'tcx>, location: Location) { + self.simplify_operand(operand, location); + } + + fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, location: Location) { + self.super_statement(stmt, location); + if let StatementKind::Assign(box (_, ref mut rvalue)) = stmt.kind + // Do not try to simplify a constant, it's already in canonical shape. + && !matches!(rvalue, Rvalue::Use(Operand::Constant(_))) + && let Some(value) = self.simplify_rvalue(rvalue, location) + { + if let Some(const_) = self.try_as_constant(value) { + *rvalue = Rvalue::Use(Operand::Constant(Box::new(const_))); + self.any_replacement = true; + } else if let Some(local) = self.try_as_local(value, location) + && *rvalue != Rvalue::Use(Operand::Move(local.into())) + { + *rvalue = Rvalue::Use(Operand::Copy(local.into())); + self.reused_locals.insert(local); + self.any_replacement = true; + } + } + } +} + +struct StorageRemover<'tcx> { + tcx: TyCtxt<'tcx>, + reused_locals: BitSet, +} + +impl<'tcx> MutVisitor<'tcx> for StorageRemover<'tcx> { + fn tcx(&self) -> TyCtxt<'tcx> { + self.tcx + } + + fn visit_operand(&mut self, operand: &mut Operand<'tcx>, _: Location) { + if let Operand::Move(place) = *operand + && let Some(local) = place.as_local() + && self.reused_locals.contains(local) + { + *operand = Operand::Copy(place); + } + } + + fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, loc: Location) { + match stmt.kind { + // When removing storage statements, we need to remove both (#107511). + StatementKind::StorageLive(l) | StatementKind::StorageDead(l) + if self.reused_locals.contains(l) => + { + stmt.make_nop() + } + _ => self.super_statement(stmt, loc), + } + } +} diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index d7fef093278ea..9e4bc456d51a2 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -76,6 +76,7 @@ mod errors; mod ffi_unwind_calls; mod function_item_references; mod generator; +mod gvn; pub mod inline; mod instsimplify; mod large_enums; @@ -549,6 +550,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { // latter pass will leverage the created opportunities. &separate_const_switch::SeparateConstSwitch, &const_prop::ConstProp, + &gvn::GVN, &dataflow_const_prop::DataflowConstProp, // // Const-prop runs unconditionally, but doesn't mutate the MIR at mir-opt-level=0. diff --git a/compiler/rustc_mir_transform/src/ref_prop.rs b/compiler/rustc_mir_transform/src/ref_prop.rs index 49a940b57799c..67941cf439525 100644 --- a/compiler/rustc_mir_transform/src/ref_prop.rs +++ b/compiler/rustc_mir_transform/src/ref_prop.rs @@ -108,7 +108,7 @@ enum Value<'tcx> { } /// For each local, save the place corresponding to `*local`. -#[instrument(level = "trace", skip(tcx, body))] +#[instrument(level = "trace", skip(tcx, body, ssa))] fn compute_replacement<'tcx>( tcx: TyCtxt<'tcx>, body: &Body<'tcx>, diff --git a/compiler/rustc_mir_transform/src/ssa.rs b/compiler/rustc_mir_transform/src/ssa.rs index 04bc461c815cd..3a675752fba91 100644 --- a/compiler/rustc_mir_transform/src/ssa.rs +++ b/compiler/rustc_mir_transform/src/ssa.rs @@ -13,7 +13,6 @@ use rustc_middle::middle::resolve_bound_vars::Set1; use rustc_middle::mir::visit::*; use rustc_middle::mir::*; -#[derive(Debug)] pub struct SsaLocals { /// Assignments to each local. This defines whether the local is SSA. assignments: IndexVec>, @@ -129,6 +128,25 @@ impl SsaLocals { self.direct_uses[local] } + pub fn assignment_dominates( + &self, + dominators: &Dominators, + local: Local, + location: Location, + ) -> bool { + match self.assignments[local] { + Set1::One(LocationExtended::Arg) => true, + Set1::One(LocationExtended::Plain(ass)) => { + if ass.block == location.block { + ass.statement_index < location.statement_index + } else { + dominators.dominates(ass.block, location.block) + } + } + _ => false, + } + } + pub fn assignments<'a, 'tcx>( &'a self, body: &'a Body<'tcx>, @@ -146,6 +164,24 @@ impl SsaLocals { }) } + pub fn for_each_assignment_mut<'tcx>( + &self, + basic_blocks: &mut BasicBlocks<'tcx>, + mut f: impl FnMut(Local, &mut Rvalue<'tcx>, Location), + ) { + for &local in &self.assignment_order { + if let Set1::One(LocationExtended::Plain(loc)) = self.assignments[local] { + // `loc` must point to a direct assignment to `local`. + let bbs = basic_blocks.as_mut_preserves_cfg(); + let bb = &mut bbs[loc.block]; + let stmt = &mut bb.statements[loc.statement_index]; + let StatementKind::Assign(box (target, ref mut rvalue)) = stmt.kind else { bug!() }; + assert_eq!(target.as_local(), Some(local)); + f(local, rvalue, loc) + } + } + } + /// Compute the equivalence classes for locals, based on copy statements. /// /// The returned vector maps each local to the one it copies. In the following case: diff --git a/src/tools/miri/tests/pass/function_pointers.rs b/src/tools/miri/tests/pass/function_pointers.rs index b66826e3fcdfb..1c99a96feda94 100644 --- a/src/tools/miri/tests/pass/function_pointers.rs +++ b/src/tools/miri/tests/pass/function_pointers.rs @@ -23,6 +23,10 @@ fn h(i: i32, j: i32) -> i32 { j * i * 7 } +fn i() -> i32 { + 73 +} + fn return_fn_ptr(f: fn() -> i32) -> fn() -> i32 { f } @@ -72,10 +76,18 @@ fn main() { assert_eq!(indirect3(h), 210); assert_eq!(indirect_mut3(h), 210); assert_eq!(indirect_once3(h), 210); - let g = f as fn() -> i32; - assert!(return_fn_ptr(g) == g); - assert!(return_fn_ptr(g) as unsafe fn() -> i32 == g as fn() -> i32 as unsafe fn() -> i32); - assert!(return_fn_ptr(f) != f); + // Check that `i` always has the same address. This is not guaranteed + // but Miri currently uses a fixed address for monomorphic functions. + assert!(return_fn_ptr(i) == i); + assert!(return_fn_ptr(i) as unsafe fn() -> i32 == i as fn() -> i32 as unsafe fn() -> i32); + // We don't check anything for `f`. Miri gives it many different addresses + // but mir-opts can turn them into the same address. + let _val = return_fn_ptr(f) != f; + // However, if we only turn `f` into a function pointer and use that pointer, + // it is equal to itself. + let f2 = f as fn() -> i32; + assert!(return_fn_ptr(f2) == f2); + assert!(return_fn_ptr(f2) as unsafe fn() -> i32 == f2 as fn() -> i32 as unsafe fn() -> i32); // Any non-null value is okay for function pointers. unsafe { diff --git a/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff b/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff new file mode 100644 index 0000000000000..3f5173c189e12 --- /dev/null +++ b/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff @@ -0,0 +1,342 @@ +- // MIR for `arithmetic` before GVN ++ // MIR for `arithmetic` after GVN + + fn arithmetic(_1: u64) -> () { + debug x => _1; + let mut _0: (); + let _2: (); + let mut _3: u64; + let mut _4: u64; + let _5: (); + let mut _6: u64; + let mut _7: u64; + let _8: (); + let mut _9: u64; + let mut _10: u64; + let _11: (); + let mut _12: u64; + let mut _13: u64; + let _14: (); + let mut _15: u64; + let mut _16: u64; + let mut _17: bool; + let _18: (); + let mut _19: u64; + let mut _20: u64; + let mut _21: bool; + let _22: (); + let mut _23: u64; + let mut _24: u64; + let mut _25: bool; + let _26: (); + let mut _27: u64; + let mut _28: u64; + let mut _29: bool; + let _30: (); + let mut _31: u64; + let mut _32: u64; + let mut _33: bool; + let _34: (); + let mut _35: u64; + let mut _36: u64; + let mut _37: bool; + let _38: (); + let mut _39: u64; + let mut _40: u64; + let mut _41: bool; + let _42: (); + let mut _43: u64; + let mut _44: u64; + let mut _45: bool; + let _46: (); + let mut _47: u64; + let mut _48: u64; + let _49: (); + let mut _50: u64; + let mut _51: u64; + let _52: (); + let mut _53: u64; + let mut _54: u64; + let _55: (); + let mut _56: u64; + let mut _57: u64; + let _58: (); + let mut _59: u64; + let mut _60: u64; + + bb0: { + StorageLive(_2); + StorageLive(_3); +- StorageLive(_4); +- _4 = _1; +- _3 = Add(move _4, const 0_u64); +- StorageDead(_4); ++ _3 = Add(_1, const 0_u64); + _2 = opaque::(move _3) -> [return: bb1, unwind unreachable]; + } + + bb1: { + StorageDead(_3); + StorageDead(_2); + StorageLive(_5); + StorageLive(_6); +- StorageLive(_7); +- _7 = _1; +- _6 = Sub(move _7, const 0_u64); +- StorageDead(_7); ++ _6 = Sub(_1, const 0_u64); + _5 = opaque::(move _6) -> [return: bb2, unwind unreachable]; + } + + bb2: { + StorageDead(_6); + StorageDead(_5); + StorageLive(_8); + StorageLive(_9); +- StorageLive(_10); +- _10 = _1; +- _9 = Mul(move _10, const 0_u64); +- StorageDead(_10); ++ _9 = Mul(_1, const 0_u64); + _8 = opaque::(move _9) -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_11); + StorageLive(_12); +- StorageLive(_13); +- _13 = _1; +- _12 = Mul(move _13, const 1_u64); +- StorageDead(_13); ++ _12 = Mul(_1, const 1_u64); + _11 = opaque::(move _12) -> [return: bb4, unwind unreachable]; + } + + bb4: { + StorageDead(_12); + StorageDead(_11); + StorageLive(_14); + StorageLive(_15); +- StorageLive(_16); +- _16 = _1; + _17 = Eq(const 0_u64, const 0_u64); +- assert(!move _17, "attempt to divide `{}` by zero", _16) -> [success: bb5, unwind unreachable]; ++ assert(!_17, "attempt to divide `{}` by zero", _1) -> [success: bb5, unwind unreachable]; + } + + bb5: { +- _15 = Div(move _16, const 0_u64); +- StorageDead(_16); ++ _15 = Div(_1, const 0_u64); + _14 = opaque::(move _15) -> [return: bb6, unwind unreachable]; + } + + bb6: { + StorageDead(_15); + StorageDead(_14); + StorageLive(_18); + StorageLive(_19); +- StorageLive(_20); +- _20 = _1; + _21 = Eq(const 1_u64, const 0_u64); +- assert(!move _21, "attempt to divide `{}` by zero", _20) -> [success: bb7, unwind unreachable]; ++ assert(!_21, "attempt to divide `{}` by zero", _1) -> [success: bb7, unwind unreachable]; + } + + bb7: { +- _19 = Div(move _20, const 1_u64); +- StorageDead(_20); ++ _19 = Div(_1, const 1_u64); + _18 = opaque::(move _19) -> [return: bb8, unwind unreachable]; + } + + bb8: { + StorageDead(_19); + StorageDead(_18); + StorageLive(_22); + StorageLive(_23); +- StorageLive(_24); +- _24 = _1; +- _25 = Eq(_24, const 0_u64); +- assert(!move _25, "attempt to divide `{}` by zero", const 0_u64) -> [success: bb9, unwind unreachable]; ++ _25 = Eq(_1, const 0_u64); ++ assert(!_25, "attempt to divide `{}` by zero", const 0_u64) -> [success: bb9, unwind unreachable]; + } + + bb9: { +- _23 = Div(const 0_u64, move _24); +- StorageDead(_24); ++ _23 = Div(const 0_u64, _1); + _22 = opaque::(move _23) -> [return: bb10, unwind unreachable]; + } + + bb10: { + StorageDead(_23); + StorageDead(_22); + StorageLive(_26); + StorageLive(_27); +- StorageLive(_28); +- _28 = _1; +- _29 = Eq(_28, const 0_u64); +- assert(!move _29, "attempt to divide `{}` by zero", const 1_u64) -> [success: bb11, unwind unreachable]; ++ assert(!_25, "attempt to divide `{}` by zero", const 1_u64) -> [success: bb11, unwind unreachable]; + } + + bb11: { +- _27 = Div(const 1_u64, move _28); +- StorageDead(_28); ++ _27 = Div(const 1_u64, _1); + _26 = opaque::(move _27) -> [return: bb12, unwind unreachable]; + } + + bb12: { + StorageDead(_27); + StorageDead(_26); + StorageLive(_30); + StorageLive(_31); +- StorageLive(_32); +- _32 = _1; +- _33 = Eq(const 0_u64, const 0_u64); +- assert(!move _33, "attempt to calculate the remainder of `{}` with a divisor of zero", _32) -> [success: bb13, unwind unreachable]; ++ assert(!_17, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb13, unwind unreachable]; + } + + bb13: { +- _31 = Rem(move _32, const 0_u64); +- StorageDead(_32); ++ _31 = Rem(_1, const 0_u64); + _30 = opaque::(move _31) -> [return: bb14, unwind unreachable]; + } + + bb14: { + StorageDead(_31); + StorageDead(_30); + StorageLive(_34); + StorageLive(_35); +- StorageLive(_36); +- _36 = _1; +- _37 = Eq(const 1_u64, const 0_u64); +- assert(!move _37, "attempt to calculate the remainder of `{}` with a divisor of zero", _36) -> [success: bb15, unwind unreachable]; ++ assert(!_21, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb15, unwind unreachable]; + } + + bb15: { +- _35 = Rem(move _36, const 1_u64); +- StorageDead(_36); ++ _35 = Rem(_1, const 1_u64); + _34 = opaque::(move _35) -> [return: bb16, unwind unreachable]; + } + + bb16: { + StorageDead(_35); + StorageDead(_34); + StorageLive(_38); + StorageLive(_39); +- StorageLive(_40); +- _40 = _1; +- _41 = Eq(_40, const 0_u64); +- assert(!move _41, "attempt to calculate the remainder of `{}` with a divisor of zero", const 0_u64) -> [success: bb17, unwind unreachable]; ++ assert(!_25, "attempt to calculate the remainder of `{}` with a divisor of zero", const 0_u64) -> [success: bb17, unwind unreachable]; + } + + bb17: { +- _39 = Rem(const 0_u64, move _40); +- StorageDead(_40); ++ _39 = Rem(const 0_u64, _1); + _38 = opaque::(move _39) -> [return: bb18, unwind unreachable]; + } + + bb18: { + StorageDead(_39); + StorageDead(_38); + StorageLive(_42); + StorageLive(_43); +- StorageLive(_44); +- _44 = _1; +- _45 = Eq(_44, const 0_u64); +- assert(!move _45, "attempt to calculate the remainder of `{}` with a divisor of zero", const 1_u64) -> [success: bb19, unwind unreachable]; ++ assert(!_25, "attempt to calculate the remainder of `{}` with a divisor of zero", const 1_u64) -> [success: bb19, unwind unreachable]; + } + + bb19: { +- _43 = Rem(const 1_u64, move _44); +- StorageDead(_44); ++ _43 = Rem(const 1_u64, _1); + _42 = opaque::(move _43) -> [return: bb20, unwind unreachable]; + } + + bb20: { + StorageDead(_43); + StorageDead(_42); + StorageLive(_46); + StorageLive(_47); +- StorageLive(_48); +- _48 = _1; +- _47 = BitAnd(move _48, const 0_u64); +- StorageDead(_48); ++ _47 = BitAnd(_1, const 0_u64); + _46 = opaque::(move _47) -> [return: bb21, unwind unreachable]; + } + + bb21: { + StorageDead(_47); + StorageDead(_46); + StorageLive(_49); + StorageLive(_50); +- StorageLive(_51); +- _51 = _1; +- _50 = BitOr(move _51, const 0_u64); +- StorageDead(_51); ++ _50 = BitOr(_1, const 0_u64); + _49 = opaque::(move _50) -> [return: bb22, unwind unreachable]; + } + + bb22: { + StorageDead(_50); + StorageDead(_49); + StorageLive(_52); + StorageLive(_53); +- StorageLive(_54); +- _54 = _1; +- _53 = BitXor(move _54, const 0_u64); +- StorageDead(_54); ++ _53 = BitXor(_1, const 0_u64); + _52 = opaque::(move _53) -> [return: bb23, unwind unreachable]; + } + + bb23: { + StorageDead(_53); + StorageDead(_52); + StorageLive(_55); + StorageLive(_56); +- StorageLive(_57); +- _57 = _1; +- _56 = Shr(move _57, const 0_i32); +- StorageDead(_57); ++ _56 = Shr(_1, const 0_i32); + _55 = opaque::(move _56) -> [return: bb24, unwind unreachable]; + } + + bb24: { + StorageDead(_56); + StorageDead(_55); + StorageLive(_58); + StorageLive(_59); +- StorageLive(_60); +- _60 = _1; +- _59 = Shl(move _60, const 0_i32); +- StorageDead(_60); ++ _59 = Shl(_1, const 0_i32); + _58 = opaque::(move _59) -> [return: bb25, unwind unreachable]; + } + + bb25: { + StorageDead(_59); + StorageDead(_58); + _0 = const (); + return; + } + } + diff --git a/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff b/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..38da21d91d41d --- /dev/null +++ b/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff @@ -0,0 +1,342 @@ +- // MIR for `arithmetic` before GVN ++ // MIR for `arithmetic` after GVN + + fn arithmetic(_1: u64) -> () { + debug x => _1; + let mut _0: (); + let _2: (); + let mut _3: u64; + let mut _4: u64; + let _5: (); + let mut _6: u64; + let mut _7: u64; + let _8: (); + let mut _9: u64; + let mut _10: u64; + let _11: (); + let mut _12: u64; + let mut _13: u64; + let _14: (); + let mut _15: u64; + let mut _16: u64; + let mut _17: bool; + let _18: (); + let mut _19: u64; + let mut _20: u64; + let mut _21: bool; + let _22: (); + let mut _23: u64; + let mut _24: u64; + let mut _25: bool; + let _26: (); + let mut _27: u64; + let mut _28: u64; + let mut _29: bool; + let _30: (); + let mut _31: u64; + let mut _32: u64; + let mut _33: bool; + let _34: (); + let mut _35: u64; + let mut _36: u64; + let mut _37: bool; + let _38: (); + let mut _39: u64; + let mut _40: u64; + let mut _41: bool; + let _42: (); + let mut _43: u64; + let mut _44: u64; + let mut _45: bool; + let _46: (); + let mut _47: u64; + let mut _48: u64; + let _49: (); + let mut _50: u64; + let mut _51: u64; + let _52: (); + let mut _53: u64; + let mut _54: u64; + let _55: (); + let mut _56: u64; + let mut _57: u64; + let _58: (); + let mut _59: u64; + let mut _60: u64; + + bb0: { + StorageLive(_2); + StorageLive(_3); +- StorageLive(_4); +- _4 = _1; +- _3 = Add(move _4, const 0_u64); +- StorageDead(_4); ++ _3 = Add(_1, const 0_u64); + _2 = opaque::(move _3) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageDead(_3); + StorageDead(_2); + StorageLive(_5); + StorageLive(_6); +- StorageLive(_7); +- _7 = _1; +- _6 = Sub(move _7, const 0_u64); +- StorageDead(_7); ++ _6 = Sub(_1, const 0_u64); + _5 = opaque::(move _6) -> [return: bb2, unwind continue]; + } + + bb2: { + StorageDead(_6); + StorageDead(_5); + StorageLive(_8); + StorageLive(_9); +- StorageLive(_10); +- _10 = _1; +- _9 = Mul(move _10, const 0_u64); +- StorageDead(_10); ++ _9 = Mul(_1, const 0_u64); + _8 = opaque::(move _9) -> [return: bb3, unwind continue]; + } + + bb3: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_11); + StorageLive(_12); +- StorageLive(_13); +- _13 = _1; +- _12 = Mul(move _13, const 1_u64); +- StorageDead(_13); ++ _12 = Mul(_1, const 1_u64); + _11 = opaque::(move _12) -> [return: bb4, unwind continue]; + } + + bb4: { + StorageDead(_12); + StorageDead(_11); + StorageLive(_14); + StorageLive(_15); +- StorageLive(_16); +- _16 = _1; + _17 = Eq(const 0_u64, const 0_u64); +- assert(!move _17, "attempt to divide `{}` by zero", _16) -> [success: bb5, unwind continue]; ++ assert(!_17, "attempt to divide `{}` by zero", _1) -> [success: bb5, unwind continue]; + } + + bb5: { +- _15 = Div(move _16, const 0_u64); +- StorageDead(_16); ++ _15 = Div(_1, const 0_u64); + _14 = opaque::(move _15) -> [return: bb6, unwind continue]; + } + + bb6: { + StorageDead(_15); + StorageDead(_14); + StorageLive(_18); + StorageLive(_19); +- StorageLive(_20); +- _20 = _1; + _21 = Eq(const 1_u64, const 0_u64); +- assert(!move _21, "attempt to divide `{}` by zero", _20) -> [success: bb7, unwind continue]; ++ assert(!_21, "attempt to divide `{}` by zero", _1) -> [success: bb7, unwind continue]; + } + + bb7: { +- _19 = Div(move _20, const 1_u64); +- StorageDead(_20); ++ _19 = Div(_1, const 1_u64); + _18 = opaque::(move _19) -> [return: bb8, unwind continue]; + } + + bb8: { + StorageDead(_19); + StorageDead(_18); + StorageLive(_22); + StorageLive(_23); +- StorageLive(_24); +- _24 = _1; +- _25 = Eq(_24, const 0_u64); +- assert(!move _25, "attempt to divide `{}` by zero", const 0_u64) -> [success: bb9, unwind continue]; ++ _25 = Eq(_1, const 0_u64); ++ assert(!_25, "attempt to divide `{}` by zero", const 0_u64) -> [success: bb9, unwind continue]; + } + + bb9: { +- _23 = Div(const 0_u64, move _24); +- StorageDead(_24); ++ _23 = Div(const 0_u64, _1); + _22 = opaque::(move _23) -> [return: bb10, unwind continue]; + } + + bb10: { + StorageDead(_23); + StorageDead(_22); + StorageLive(_26); + StorageLive(_27); +- StorageLive(_28); +- _28 = _1; +- _29 = Eq(_28, const 0_u64); +- assert(!move _29, "attempt to divide `{}` by zero", const 1_u64) -> [success: bb11, unwind continue]; ++ assert(!_25, "attempt to divide `{}` by zero", const 1_u64) -> [success: bb11, unwind continue]; + } + + bb11: { +- _27 = Div(const 1_u64, move _28); +- StorageDead(_28); ++ _27 = Div(const 1_u64, _1); + _26 = opaque::(move _27) -> [return: bb12, unwind continue]; + } + + bb12: { + StorageDead(_27); + StorageDead(_26); + StorageLive(_30); + StorageLive(_31); +- StorageLive(_32); +- _32 = _1; +- _33 = Eq(const 0_u64, const 0_u64); +- assert(!move _33, "attempt to calculate the remainder of `{}` with a divisor of zero", _32) -> [success: bb13, unwind continue]; ++ assert(!_17, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb13, unwind continue]; + } + + bb13: { +- _31 = Rem(move _32, const 0_u64); +- StorageDead(_32); ++ _31 = Rem(_1, const 0_u64); + _30 = opaque::(move _31) -> [return: bb14, unwind continue]; + } + + bb14: { + StorageDead(_31); + StorageDead(_30); + StorageLive(_34); + StorageLive(_35); +- StorageLive(_36); +- _36 = _1; +- _37 = Eq(const 1_u64, const 0_u64); +- assert(!move _37, "attempt to calculate the remainder of `{}` with a divisor of zero", _36) -> [success: bb15, unwind continue]; ++ assert(!_21, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb15, unwind continue]; + } + + bb15: { +- _35 = Rem(move _36, const 1_u64); +- StorageDead(_36); ++ _35 = Rem(_1, const 1_u64); + _34 = opaque::(move _35) -> [return: bb16, unwind continue]; + } + + bb16: { + StorageDead(_35); + StorageDead(_34); + StorageLive(_38); + StorageLive(_39); +- StorageLive(_40); +- _40 = _1; +- _41 = Eq(_40, const 0_u64); +- assert(!move _41, "attempt to calculate the remainder of `{}` with a divisor of zero", const 0_u64) -> [success: bb17, unwind continue]; ++ assert(!_25, "attempt to calculate the remainder of `{}` with a divisor of zero", const 0_u64) -> [success: bb17, unwind continue]; + } + + bb17: { +- _39 = Rem(const 0_u64, move _40); +- StorageDead(_40); ++ _39 = Rem(const 0_u64, _1); + _38 = opaque::(move _39) -> [return: bb18, unwind continue]; + } + + bb18: { + StorageDead(_39); + StorageDead(_38); + StorageLive(_42); + StorageLive(_43); +- StorageLive(_44); +- _44 = _1; +- _45 = Eq(_44, const 0_u64); +- assert(!move _45, "attempt to calculate the remainder of `{}` with a divisor of zero", const 1_u64) -> [success: bb19, unwind continue]; ++ assert(!_25, "attempt to calculate the remainder of `{}` with a divisor of zero", const 1_u64) -> [success: bb19, unwind continue]; + } + + bb19: { +- _43 = Rem(const 1_u64, move _44); +- StorageDead(_44); ++ _43 = Rem(const 1_u64, _1); + _42 = opaque::(move _43) -> [return: bb20, unwind continue]; + } + + bb20: { + StorageDead(_43); + StorageDead(_42); + StorageLive(_46); + StorageLive(_47); +- StorageLive(_48); +- _48 = _1; +- _47 = BitAnd(move _48, const 0_u64); +- StorageDead(_48); ++ _47 = BitAnd(_1, const 0_u64); + _46 = opaque::(move _47) -> [return: bb21, unwind continue]; + } + + bb21: { + StorageDead(_47); + StorageDead(_46); + StorageLive(_49); + StorageLive(_50); +- StorageLive(_51); +- _51 = _1; +- _50 = BitOr(move _51, const 0_u64); +- StorageDead(_51); ++ _50 = BitOr(_1, const 0_u64); + _49 = opaque::(move _50) -> [return: bb22, unwind continue]; + } + + bb22: { + StorageDead(_50); + StorageDead(_49); + StorageLive(_52); + StorageLive(_53); +- StorageLive(_54); +- _54 = _1; +- _53 = BitXor(move _54, const 0_u64); +- StorageDead(_54); ++ _53 = BitXor(_1, const 0_u64); + _52 = opaque::(move _53) -> [return: bb23, unwind continue]; + } + + bb23: { + StorageDead(_53); + StorageDead(_52); + StorageLive(_55); + StorageLive(_56); +- StorageLive(_57); +- _57 = _1; +- _56 = Shr(move _57, const 0_i32); +- StorageDead(_57); ++ _56 = Shr(_1, const 0_i32); + _55 = opaque::(move _56) -> [return: bb24, unwind continue]; + } + + bb24: { + StorageDead(_56); + StorageDead(_55); + StorageLive(_58); + StorageLive(_59); +- StorageLive(_60); +- _60 = _1; +- _59 = Shl(move _60, const 0_i32); +- StorageDead(_60); ++ _59 = Shl(_1, const 0_i32); + _58 = opaque::(move _59) -> [return: bb25, unwind continue]; + } + + bb25: { + StorageDead(_59); + StorageDead(_58); + _0 = const (); + return; + } + } + diff --git a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff new file mode 100644 index 0000000000000..0c342799e0794 --- /dev/null +++ b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff @@ -0,0 +1,389 @@ +- // MIR for `arithmetic_checked` before GVN ++ // MIR for `arithmetic_checked` after GVN + + fn arithmetic_checked(_1: u64) -> () { + debug x => _1; + let mut _0: (); + let _2: (); + let mut _3: u64; + let mut _4: u64; + let mut _5: (u64, bool); + let _6: (); + let mut _7: u64; + let mut _8: u64; + let mut _9: (u64, bool); + let _10: (); + let mut _11: u64; + let mut _12: u64; + let mut _13: (u64, bool); + let _14: (); + let mut _15: u64; + let mut _16: u64; + let mut _17: (u64, bool); + let _18: (); + let mut _19: u64; + let mut _20: u64; + let mut _21: bool; + let _22: (); + let mut _23: u64; + let mut _24: u64; + let mut _25: bool; + let _26: (); + let mut _27: u64; + let mut _28: u64; + let mut _29: bool; + let _30: (); + let mut _31: u64; + let mut _32: u64; + let mut _33: bool; + let _34: (); + let mut _35: u64; + let mut _36: u64; + let mut _37: bool; + let _38: (); + let mut _39: u64; + let mut _40: u64; + let mut _41: bool; + let _42: (); + let mut _43: u64; + let mut _44: u64; + let mut _45: bool; + let _46: (); + let mut _47: u64; + let mut _48: u64; + let mut _49: bool; + let _50: (); + let mut _51: u64; + let mut _52: u64; + let _53: (); + let mut _54: u64; + let mut _55: u64; + let _56: (); + let mut _57: u64; + let mut _58: u64; + let _59: (); + let mut _60: u64; + let mut _61: u64; + let mut _62: u32; + let mut _63: bool; + let _64: (); + let mut _65: u64; + let mut _66: u64; + let mut _67: u32; + let mut _68: bool; + + bb0: { + StorageLive(_2); + StorageLive(_3); +- StorageLive(_4); +- _4 = _1; +- _5 = CheckedAdd(_4, const 0_u64); +- assert(!move (_5.1: bool), "attempt to compute `{} + {}`, which would overflow", move _4, const 0_u64) -> [success: bb1, unwind unreachable]; ++ _5 = CheckedAdd(_1, const 0_u64); ++ assert(!move (_5.1: bool), "attempt to compute `{} + {}`, which would overflow", _1, const 0_u64) -> [success: bb1, unwind unreachable]; + } + + bb1: { + _3 = move (_5.0: u64); +- StorageDead(_4); + _2 = opaque::(move _3) -> [return: bb2, unwind unreachable]; + } + + bb2: { + StorageDead(_3); + StorageDead(_2); + StorageLive(_6); + StorageLive(_7); +- StorageLive(_8); +- _8 = _1; +- _9 = CheckedSub(_8, const 0_u64); +- assert(!move (_9.1: bool), "attempt to compute `{} - {}`, which would overflow", move _8, const 0_u64) -> [success: bb3, unwind unreachable]; ++ _9 = CheckedSub(_1, const 0_u64); ++ assert(!move (_9.1: bool), "attempt to compute `{} - {}`, which would overflow", _1, const 0_u64) -> [success: bb3, unwind unreachable]; + } + + bb3: { + _7 = move (_9.0: u64); +- StorageDead(_8); + _6 = opaque::(move _7) -> [return: bb4, unwind unreachable]; + } + + bb4: { + StorageDead(_7); + StorageDead(_6); + StorageLive(_10); + StorageLive(_11); +- StorageLive(_12); +- _12 = _1; +- _13 = CheckedMul(_12, const 0_u64); +- assert(!move (_13.1: bool), "attempt to compute `{} * {}`, which would overflow", move _12, const 0_u64) -> [success: bb5, unwind unreachable]; ++ _13 = CheckedMul(_1, const 0_u64); ++ assert(!move (_13.1: bool), "attempt to compute `{} * {}`, which would overflow", _1, const 0_u64) -> [success: bb5, unwind unreachable]; + } + + bb5: { + _11 = move (_13.0: u64); +- StorageDead(_12); + _10 = opaque::(move _11) -> [return: bb6, unwind unreachable]; + } + + bb6: { + StorageDead(_11); + StorageDead(_10); + StorageLive(_14); + StorageLive(_15); +- StorageLive(_16); +- _16 = _1; +- _17 = CheckedMul(_16, const 1_u64); +- assert(!move (_17.1: bool), "attempt to compute `{} * {}`, which would overflow", move _16, const 1_u64) -> [success: bb7, unwind unreachable]; ++ _17 = CheckedMul(_1, const 1_u64); ++ assert(!move (_17.1: bool), "attempt to compute `{} * {}`, which would overflow", _1, const 1_u64) -> [success: bb7, unwind unreachable]; + } + + bb7: { + _15 = move (_17.0: u64); +- StorageDead(_16); + _14 = opaque::(move _15) -> [return: bb8, unwind unreachable]; + } + + bb8: { + StorageDead(_15); + StorageDead(_14); + StorageLive(_18); + StorageLive(_19); +- StorageLive(_20); +- _20 = _1; + _21 = Eq(const 0_u64, const 0_u64); +- assert(!move _21, "attempt to divide `{}` by zero", _20) -> [success: bb9, unwind unreachable]; ++ assert(!_21, "attempt to divide `{}` by zero", _1) -> [success: bb9, unwind unreachable]; + } + + bb9: { +- _19 = Div(move _20, const 0_u64); +- StorageDead(_20); ++ _19 = Div(_1, const 0_u64); + _18 = opaque::(move _19) -> [return: bb10, unwind unreachable]; + } + + bb10: { + StorageDead(_19); + StorageDead(_18); + StorageLive(_22); + StorageLive(_23); +- StorageLive(_24); +- _24 = _1; + _25 = Eq(const 1_u64, const 0_u64); +- assert(!move _25, "attempt to divide `{}` by zero", _24) -> [success: bb11, unwind unreachable]; ++ assert(!_25, "attempt to divide `{}` by zero", _1) -> [success: bb11, unwind unreachable]; + } + + bb11: { +- _23 = Div(move _24, const 1_u64); +- StorageDead(_24); ++ _23 = Div(_1, const 1_u64); + _22 = opaque::(move _23) -> [return: bb12, unwind unreachable]; + } + + bb12: { + StorageDead(_23); + StorageDead(_22); + StorageLive(_26); + StorageLive(_27); +- StorageLive(_28); +- _28 = _1; +- _29 = Eq(_28, const 0_u64); +- assert(!move _29, "attempt to divide `{}` by zero", const 0_u64) -> [success: bb13, unwind unreachable]; ++ _29 = Eq(_1, const 0_u64); ++ assert(!_29, "attempt to divide `{}` by zero", const 0_u64) -> [success: bb13, unwind unreachable]; + } + + bb13: { +- _27 = Div(const 0_u64, move _28); +- StorageDead(_28); ++ _27 = Div(const 0_u64, _1); + _26 = opaque::(move _27) -> [return: bb14, unwind unreachable]; + } + + bb14: { + StorageDead(_27); + StorageDead(_26); + StorageLive(_30); + StorageLive(_31); +- StorageLive(_32); +- _32 = _1; +- _33 = Eq(_32, const 0_u64); +- assert(!move _33, "attempt to divide `{}` by zero", const 1_u64) -> [success: bb15, unwind unreachable]; ++ assert(!_29, "attempt to divide `{}` by zero", const 1_u64) -> [success: bb15, unwind unreachable]; + } + + bb15: { +- _31 = Div(const 1_u64, move _32); +- StorageDead(_32); ++ _31 = Div(const 1_u64, _1); + _30 = opaque::(move _31) -> [return: bb16, unwind unreachable]; + } + + bb16: { + StorageDead(_31); + StorageDead(_30); + StorageLive(_34); + StorageLive(_35); +- StorageLive(_36); +- _36 = _1; +- _37 = Eq(const 0_u64, const 0_u64); +- assert(!move _37, "attempt to calculate the remainder of `{}` with a divisor of zero", _36) -> [success: bb17, unwind unreachable]; ++ assert(!_21, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb17, unwind unreachable]; + } + + bb17: { +- _35 = Rem(move _36, const 0_u64); +- StorageDead(_36); ++ _35 = Rem(_1, const 0_u64); + _34 = opaque::(move _35) -> [return: bb18, unwind unreachable]; + } + + bb18: { + StorageDead(_35); + StorageDead(_34); + StorageLive(_38); + StorageLive(_39); +- StorageLive(_40); +- _40 = _1; +- _41 = Eq(const 1_u64, const 0_u64); +- assert(!move _41, "attempt to calculate the remainder of `{}` with a divisor of zero", _40) -> [success: bb19, unwind unreachable]; ++ assert(!_25, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb19, unwind unreachable]; + } + + bb19: { +- _39 = Rem(move _40, const 1_u64); +- StorageDead(_40); ++ _39 = Rem(_1, const 1_u64); + _38 = opaque::(move _39) -> [return: bb20, unwind unreachable]; + } + + bb20: { + StorageDead(_39); + StorageDead(_38); + StorageLive(_42); + StorageLive(_43); +- StorageLive(_44); +- _44 = _1; +- _45 = Eq(_44, const 0_u64); +- assert(!move _45, "attempt to calculate the remainder of `{}` with a divisor of zero", const 0_u64) -> [success: bb21, unwind unreachable]; ++ assert(!_29, "attempt to calculate the remainder of `{}` with a divisor of zero", const 0_u64) -> [success: bb21, unwind unreachable]; + } + + bb21: { +- _43 = Rem(const 0_u64, move _44); +- StorageDead(_44); ++ _43 = Rem(const 0_u64, _1); + _42 = opaque::(move _43) -> [return: bb22, unwind unreachable]; + } + + bb22: { + StorageDead(_43); + StorageDead(_42); + StorageLive(_46); + StorageLive(_47); +- StorageLive(_48); +- _48 = _1; +- _49 = Eq(_48, const 0_u64); +- assert(!move _49, "attempt to calculate the remainder of `{}` with a divisor of zero", const 1_u64) -> [success: bb23, unwind unreachable]; ++ assert(!_29, "attempt to calculate the remainder of `{}` with a divisor of zero", const 1_u64) -> [success: bb23, unwind unreachable]; + } + + bb23: { +- _47 = Rem(const 1_u64, move _48); +- StorageDead(_48); ++ _47 = Rem(const 1_u64, _1); + _46 = opaque::(move _47) -> [return: bb24, unwind unreachable]; + } + + bb24: { + StorageDead(_47); + StorageDead(_46); + StorageLive(_50); + StorageLive(_51); +- StorageLive(_52); +- _52 = _1; +- _51 = BitAnd(move _52, const 0_u64); +- StorageDead(_52); ++ _51 = BitAnd(_1, const 0_u64); + _50 = opaque::(move _51) -> [return: bb25, unwind unreachable]; + } + + bb25: { + StorageDead(_51); + StorageDead(_50); + StorageLive(_53); + StorageLive(_54); +- StorageLive(_55); +- _55 = _1; +- _54 = BitOr(move _55, const 0_u64); +- StorageDead(_55); ++ _54 = BitOr(_1, const 0_u64); + _53 = opaque::(move _54) -> [return: bb26, unwind unreachable]; + } + + bb26: { + StorageDead(_54); + StorageDead(_53); + StorageLive(_56); + StorageLive(_57); +- StorageLive(_58); +- _58 = _1; +- _57 = BitXor(move _58, const 0_u64); +- StorageDead(_58); ++ _57 = BitXor(_1, const 0_u64); + _56 = opaque::(move _57) -> [return: bb27, unwind unreachable]; + } + + bb27: { + StorageDead(_57); + StorageDead(_56); + StorageLive(_59); + StorageLive(_60); +- StorageLive(_61); +- _61 = _1; + _62 = const 0_i32 as u32 (IntToInt); +- _63 = Lt(move _62, const 64_u32); +- assert(move _63, "attempt to shift right by `{}`, which would overflow", const 0_i32) -> [success: bb28, unwind unreachable]; ++ _63 = Lt(_62, const 64_u32); ++ assert(_63, "attempt to shift right by `{}`, which would overflow", const 0_i32) -> [success: bb28, unwind unreachable]; + } + + bb28: { +- _60 = Shr(move _61, const 0_i32); +- StorageDead(_61); ++ _60 = Shr(_1, const 0_i32); + _59 = opaque::(move _60) -> [return: bb29, unwind unreachable]; + } + + bb29: { + StorageDead(_60); + StorageDead(_59); + StorageLive(_64); + StorageLive(_65); +- StorageLive(_66); +- _66 = _1; +- _67 = const 0_i32 as u32 (IntToInt); +- _68 = Lt(move _67, const 64_u32); +- assert(move _68, "attempt to shift left by `{}`, which would overflow", const 0_i32) -> [success: bb30, unwind unreachable]; ++ assert(_63, "attempt to shift left by `{}`, which would overflow", const 0_i32) -> [success: bb30, unwind unreachable]; + } + + bb30: { +- _65 = Shl(move _66, const 0_i32); +- StorageDead(_66); ++ _65 = Shl(_1, const 0_i32); + _64 = opaque::(move _65) -> [return: bb31, unwind unreachable]; + } + + bb31: { + StorageDead(_65); + StorageDead(_64); + _0 = const (); + return; + } + } + diff --git a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..7813c29b962d2 --- /dev/null +++ b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff @@ -0,0 +1,389 @@ +- // MIR for `arithmetic_checked` before GVN ++ // MIR for `arithmetic_checked` after GVN + + fn arithmetic_checked(_1: u64) -> () { + debug x => _1; + let mut _0: (); + let _2: (); + let mut _3: u64; + let mut _4: u64; + let mut _5: (u64, bool); + let _6: (); + let mut _7: u64; + let mut _8: u64; + let mut _9: (u64, bool); + let _10: (); + let mut _11: u64; + let mut _12: u64; + let mut _13: (u64, bool); + let _14: (); + let mut _15: u64; + let mut _16: u64; + let mut _17: (u64, bool); + let _18: (); + let mut _19: u64; + let mut _20: u64; + let mut _21: bool; + let _22: (); + let mut _23: u64; + let mut _24: u64; + let mut _25: bool; + let _26: (); + let mut _27: u64; + let mut _28: u64; + let mut _29: bool; + let _30: (); + let mut _31: u64; + let mut _32: u64; + let mut _33: bool; + let _34: (); + let mut _35: u64; + let mut _36: u64; + let mut _37: bool; + let _38: (); + let mut _39: u64; + let mut _40: u64; + let mut _41: bool; + let _42: (); + let mut _43: u64; + let mut _44: u64; + let mut _45: bool; + let _46: (); + let mut _47: u64; + let mut _48: u64; + let mut _49: bool; + let _50: (); + let mut _51: u64; + let mut _52: u64; + let _53: (); + let mut _54: u64; + let mut _55: u64; + let _56: (); + let mut _57: u64; + let mut _58: u64; + let _59: (); + let mut _60: u64; + let mut _61: u64; + let mut _62: u32; + let mut _63: bool; + let _64: (); + let mut _65: u64; + let mut _66: u64; + let mut _67: u32; + let mut _68: bool; + + bb0: { + StorageLive(_2); + StorageLive(_3); +- StorageLive(_4); +- _4 = _1; +- _5 = CheckedAdd(_4, const 0_u64); +- assert(!move (_5.1: bool), "attempt to compute `{} + {}`, which would overflow", move _4, const 0_u64) -> [success: bb1, unwind continue]; ++ _5 = CheckedAdd(_1, const 0_u64); ++ assert(!move (_5.1: bool), "attempt to compute `{} + {}`, which would overflow", _1, const 0_u64) -> [success: bb1, unwind continue]; + } + + bb1: { + _3 = move (_5.0: u64); +- StorageDead(_4); + _2 = opaque::(move _3) -> [return: bb2, unwind continue]; + } + + bb2: { + StorageDead(_3); + StorageDead(_2); + StorageLive(_6); + StorageLive(_7); +- StorageLive(_8); +- _8 = _1; +- _9 = CheckedSub(_8, const 0_u64); +- assert(!move (_9.1: bool), "attempt to compute `{} - {}`, which would overflow", move _8, const 0_u64) -> [success: bb3, unwind continue]; ++ _9 = CheckedSub(_1, const 0_u64); ++ assert(!move (_9.1: bool), "attempt to compute `{} - {}`, which would overflow", _1, const 0_u64) -> [success: bb3, unwind continue]; + } + + bb3: { + _7 = move (_9.0: u64); +- StorageDead(_8); + _6 = opaque::(move _7) -> [return: bb4, unwind continue]; + } + + bb4: { + StorageDead(_7); + StorageDead(_6); + StorageLive(_10); + StorageLive(_11); +- StorageLive(_12); +- _12 = _1; +- _13 = CheckedMul(_12, const 0_u64); +- assert(!move (_13.1: bool), "attempt to compute `{} * {}`, which would overflow", move _12, const 0_u64) -> [success: bb5, unwind continue]; ++ _13 = CheckedMul(_1, const 0_u64); ++ assert(!move (_13.1: bool), "attempt to compute `{} * {}`, which would overflow", _1, const 0_u64) -> [success: bb5, unwind continue]; + } + + bb5: { + _11 = move (_13.0: u64); +- StorageDead(_12); + _10 = opaque::(move _11) -> [return: bb6, unwind continue]; + } + + bb6: { + StorageDead(_11); + StorageDead(_10); + StorageLive(_14); + StorageLive(_15); +- StorageLive(_16); +- _16 = _1; +- _17 = CheckedMul(_16, const 1_u64); +- assert(!move (_17.1: bool), "attempt to compute `{} * {}`, which would overflow", move _16, const 1_u64) -> [success: bb7, unwind continue]; ++ _17 = CheckedMul(_1, const 1_u64); ++ assert(!move (_17.1: bool), "attempt to compute `{} * {}`, which would overflow", _1, const 1_u64) -> [success: bb7, unwind continue]; + } + + bb7: { + _15 = move (_17.0: u64); +- StorageDead(_16); + _14 = opaque::(move _15) -> [return: bb8, unwind continue]; + } + + bb8: { + StorageDead(_15); + StorageDead(_14); + StorageLive(_18); + StorageLive(_19); +- StorageLive(_20); +- _20 = _1; + _21 = Eq(const 0_u64, const 0_u64); +- assert(!move _21, "attempt to divide `{}` by zero", _20) -> [success: bb9, unwind continue]; ++ assert(!_21, "attempt to divide `{}` by zero", _1) -> [success: bb9, unwind continue]; + } + + bb9: { +- _19 = Div(move _20, const 0_u64); +- StorageDead(_20); ++ _19 = Div(_1, const 0_u64); + _18 = opaque::(move _19) -> [return: bb10, unwind continue]; + } + + bb10: { + StorageDead(_19); + StorageDead(_18); + StorageLive(_22); + StorageLive(_23); +- StorageLive(_24); +- _24 = _1; + _25 = Eq(const 1_u64, const 0_u64); +- assert(!move _25, "attempt to divide `{}` by zero", _24) -> [success: bb11, unwind continue]; ++ assert(!_25, "attempt to divide `{}` by zero", _1) -> [success: bb11, unwind continue]; + } + + bb11: { +- _23 = Div(move _24, const 1_u64); +- StorageDead(_24); ++ _23 = Div(_1, const 1_u64); + _22 = opaque::(move _23) -> [return: bb12, unwind continue]; + } + + bb12: { + StorageDead(_23); + StorageDead(_22); + StorageLive(_26); + StorageLive(_27); +- StorageLive(_28); +- _28 = _1; +- _29 = Eq(_28, const 0_u64); +- assert(!move _29, "attempt to divide `{}` by zero", const 0_u64) -> [success: bb13, unwind continue]; ++ _29 = Eq(_1, const 0_u64); ++ assert(!_29, "attempt to divide `{}` by zero", const 0_u64) -> [success: bb13, unwind continue]; + } + + bb13: { +- _27 = Div(const 0_u64, move _28); +- StorageDead(_28); ++ _27 = Div(const 0_u64, _1); + _26 = opaque::(move _27) -> [return: bb14, unwind continue]; + } + + bb14: { + StorageDead(_27); + StorageDead(_26); + StorageLive(_30); + StorageLive(_31); +- StorageLive(_32); +- _32 = _1; +- _33 = Eq(_32, const 0_u64); +- assert(!move _33, "attempt to divide `{}` by zero", const 1_u64) -> [success: bb15, unwind continue]; ++ assert(!_29, "attempt to divide `{}` by zero", const 1_u64) -> [success: bb15, unwind continue]; + } + + bb15: { +- _31 = Div(const 1_u64, move _32); +- StorageDead(_32); ++ _31 = Div(const 1_u64, _1); + _30 = opaque::(move _31) -> [return: bb16, unwind continue]; + } + + bb16: { + StorageDead(_31); + StorageDead(_30); + StorageLive(_34); + StorageLive(_35); +- StorageLive(_36); +- _36 = _1; +- _37 = Eq(const 0_u64, const 0_u64); +- assert(!move _37, "attempt to calculate the remainder of `{}` with a divisor of zero", _36) -> [success: bb17, unwind continue]; ++ assert(!_21, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb17, unwind continue]; + } + + bb17: { +- _35 = Rem(move _36, const 0_u64); +- StorageDead(_36); ++ _35 = Rem(_1, const 0_u64); + _34 = opaque::(move _35) -> [return: bb18, unwind continue]; + } + + bb18: { + StorageDead(_35); + StorageDead(_34); + StorageLive(_38); + StorageLive(_39); +- StorageLive(_40); +- _40 = _1; +- _41 = Eq(const 1_u64, const 0_u64); +- assert(!move _41, "attempt to calculate the remainder of `{}` with a divisor of zero", _40) -> [success: bb19, unwind continue]; ++ assert(!_25, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb19, unwind continue]; + } + + bb19: { +- _39 = Rem(move _40, const 1_u64); +- StorageDead(_40); ++ _39 = Rem(_1, const 1_u64); + _38 = opaque::(move _39) -> [return: bb20, unwind continue]; + } + + bb20: { + StorageDead(_39); + StorageDead(_38); + StorageLive(_42); + StorageLive(_43); +- StorageLive(_44); +- _44 = _1; +- _45 = Eq(_44, const 0_u64); +- assert(!move _45, "attempt to calculate the remainder of `{}` with a divisor of zero", const 0_u64) -> [success: bb21, unwind continue]; ++ assert(!_29, "attempt to calculate the remainder of `{}` with a divisor of zero", const 0_u64) -> [success: bb21, unwind continue]; + } + + bb21: { +- _43 = Rem(const 0_u64, move _44); +- StorageDead(_44); ++ _43 = Rem(const 0_u64, _1); + _42 = opaque::(move _43) -> [return: bb22, unwind continue]; + } + + bb22: { + StorageDead(_43); + StorageDead(_42); + StorageLive(_46); + StorageLive(_47); +- StorageLive(_48); +- _48 = _1; +- _49 = Eq(_48, const 0_u64); +- assert(!move _49, "attempt to calculate the remainder of `{}` with a divisor of zero", const 1_u64) -> [success: bb23, unwind continue]; ++ assert(!_29, "attempt to calculate the remainder of `{}` with a divisor of zero", const 1_u64) -> [success: bb23, unwind continue]; + } + + bb23: { +- _47 = Rem(const 1_u64, move _48); +- StorageDead(_48); ++ _47 = Rem(const 1_u64, _1); + _46 = opaque::(move _47) -> [return: bb24, unwind continue]; + } + + bb24: { + StorageDead(_47); + StorageDead(_46); + StorageLive(_50); + StorageLive(_51); +- StorageLive(_52); +- _52 = _1; +- _51 = BitAnd(move _52, const 0_u64); +- StorageDead(_52); ++ _51 = BitAnd(_1, const 0_u64); + _50 = opaque::(move _51) -> [return: bb25, unwind continue]; + } + + bb25: { + StorageDead(_51); + StorageDead(_50); + StorageLive(_53); + StorageLive(_54); +- StorageLive(_55); +- _55 = _1; +- _54 = BitOr(move _55, const 0_u64); +- StorageDead(_55); ++ _54 = BitOr(_1, const 0_u64); + _53 = opaque::(move _54) -> [return: bb26, unwind continue]; + } + + bb26: { + StorageDead(_54); + StorageDead(_53); + StorageLive(_56); + StorageLive(_57); +- StorageLive(_58); +- _58 = _1; +- _57 = BitXor(move _58, const 0_u64); +- StorageDead(_58); ++ _57 = BitXor(_1, const 0_u64); + _56 = opaque::(move _57) -> [return: bb27, unwind continue]; + } + + bb27: { + StorageDead(_57); + StorageDead(_56); + StorageLive(_59); + StorageLive(_60); +- StorageLive(_61); +- _61 = _1; + _62 = const 0_i32 as u32 (IntToInt); +- _63 = Lt(move _62, const 64_u32); +- assert(move _63, "attempt to shift right by `{}`, which would overflow", const 0_i32) -> [success: bb28, unwind continue]; ++ _63 = Lt(_62, const 64_u32); ++ assert(_63, "attempt to shift right by `{}`, which would overflow", const 0_i32) -> [success: bb28, unwind continue]; + } + + bb28: { +- _60 = Shr(move _61, const 0_i32); +- StorageDead(_61); ++ _60 = Shr(_1, const 0_i32); + _59 = opaque::(move _60) -> [return: bb29, unwind continue]; + } + + bb29: { + StorageDead(_60); + StorageDead(_59); + StorageLive(_64); + StorageLive(_65); +- StorageLive(_66); +- _66 = _1; +- _67 = const 0_i32 as u32 (IntToInt); +- _68 = Lt(move _67, const 64_u32); +- assert(move _68, "attempt to shift left by `{}`, which would overflow", const 0_i32) -> [success: bb30, unwind continue]; ++ assert(_63, "attempt to shift left by `{}`, which would overflow", const 0_i32) -> [success: bb30, unwind continue]; + } + + bb30: { +- _65 = Shl(move _66, const 0_i32); +- StorageDead(_66); ++ _65 = Shl(_1, const 0_i32); + _64 = opaque::(move _65) -> [return: bb31, unwind continue]; + } + + bb31: { + StorageDead(_65); + StorageDead(_64); + _0 = const (); + return; + } + } + diff --git a/tests/mir-opt/gvn.arithmetic_float.GVN.panic-abort.diff b/tests/mir-opt/gvn.arithmetic_float.GVN.panic-abort.diff new file mode 100644 index 0000000000000..7d5ac8353fe43 --- /dev/null +++ b/tests/mir-opt/gvn.arithmetic_float.GVN.panic-abort.diff @@ -0,0 +1,165 @@ +- // MIR for `arithmetic_float` before GVN ++ // MIR for `arithmetic_float` after GVN + + fn arithmetic_float(_1: f64) -> () { + debug x => _1; + let mut _0: (); + let _2: (); + let mut _3: f64; + let mut _4: f64; + let _5: (); + let mut _6: f64; + let mut _7: f64; + let _8: (); + let mut _9: f64; + let mut _10: f64; + let _11: (); + let mut _12: f64; + let mut _13: f64; + let _14: (); + let mut _15: f64; + let mut _16: f64; + let _17: (); + let mut _18: f64; + let mut _19: f64; + let _20: (); + let mut _21: f64; + let mut _22: f64; + let _23: (); + let mut _24: bool; + let mut _25: f64; + let mut _26: f64; + let _27: (); + let mut _28: bool; + let mut _29: f64; + let mut _30: f64; + + bb0: { + StorageLive(_2); + StorageLive(_3); +- StorageLive(_4); +- _4 = _1; +- _3 = Add(move _4, const 0f64); +- StorageDead(_4); ++ _3 = Add(_1, const 0f64); + _2 = opaque::(move _3) -> [return: bb1, unwind unreachable]; + } + + bb1: { + StorageDead(_3); + StorageDead(_2); + StorageLive(_5); + StorageLive(_6); +- StorageLive(_7); +- _7 = _1; +- _6 = Sub(move _7, const 0f64); +- StorageDead(_7); ++ _6 = Sub(_1, const 0f64); + _5 = opaque::(move _6) -> [return: bb2, unwind unreachable]; + } + + bb2: { + StorageDead(_6); + StorageDead(_5); + StorageLive(_8); + StorageLive(_9); +- StorageLive(_10); +- _10 = _1; +- _9 = Mul(move _10, const 0f64); +- StorageDead(_10); ++ _9 = Mul(_1, const 0f64); + _8 = opaque::(move _9) -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_11); + StorageLive(_12); +- StorageLive(_13); +- _13 = _1; +- _12 = Div(move _13, const 0f64); +- StorageDead(_13); ++ _12 = Div(_1, const 0f64); + _11 = opaque::(move _12) -> [return: bb4, unwind unreachable]; + } + + bb4: { + StorageDead(_12); + StorageDead(_11); + StorageLive(_14); + StorageLive(_15); +- StorageLive(_16); +- _16 = _1; +- _15 = Div(const 0f64, move _16); +- StorageDead(_16); ++ _15 = Div(const 0f64, _1); + _14 = opaque::(move _15) -> [return: bb5, unwind unreachable]; + } + + bb5: { + StorageDead(_15); + StorageDead(_14); + StorageLive(_17); + StorageLive(_18); +- StorageLive(_19); +- _19 = _1; +- _18 = Rem(move _19, const 0f64); +- StorageDead(_19); ++ _18 = Rem(_1, const 0f64); + _17 = opaque::(move _18) -> [return: bb6, unwind unreachable]; + } + + bb6: { + StorageDead(_18); + StorageDead(_17); + StorageLive(_20); + StorageLive(_21); +- StorageLive(_22); +- _22 = _1; +- _21 = Rem(const 0f64, move _22); +- StorageDead(_22); ++ _21 = Rem(const 0f64, _1); + _20 = opaque::(move _21) -> [return: bb7, unwind unreachable]; + } + + bb7: { + StorageDead(_21); + StorageDead(_20); + StorageLive(_23); + StorageLive(_24); +- StorageLive(_25); +- _25 = _1; +- StorageLive(_26); +- _26 = _1; +- _24 = Eq(move _25, move _26); +- StorageDead(_26); +- StorageDead(_25); ++ _24 = Eq(_1, _1); + _23 = opaque::(move _24) -> [return: bb8, unwind unreachable]; + } + + bb8: { + StorageDead(_24); + StorageDead(_23); + StorageLive(_27); + StorageLive(_28); +- StorageLive(_29); +- _29 = _1; +- StorageLive(_30); +- _30 = _1; +- _28 = Ne(move _29, move _30); +- StorageDead(_30); +- StorageDead(_29); ++ _28 = Ne(_1, _1); + _27 = opaque::(move _28) -> [return: bb9, unwind unreachable]; + } + + bb9: { + StorageDead(_28); + StorageDead(_27); + _0 = const (); + return; + } + } + diff --git a/tests/mir-opt/gvn.arithmetic_float.GVN.panic-unwind.diff b/tests/mir-opt/gvn.arithmetic_float.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..36c26dc66051b --- /dev/null +++ b/tests/mir-opt/gvn.arithmetic_float.GVN.panic-unwind.diff @@ -0,0 +1,165 @@ +- // MIR for `arithmetic_float` before GVN ++ // MIR for `arithmetic_float` after GVN + + fn arithmetic_float(_1: f64) -> () { + debug x => _1; + let mut _0: (); + let _2: (); + let mut _3: f64; + let mut _4: f64; + let _5: (); + let mut _6: f64; + let mut _7: f64; + let _8: (); + let mut _9: f64; + let mut _10: f64; + let _11: (); + let mut _12: f64; + let mut _13: f64; + let _14: (); + let mut _15: f64; + let mut _16: f64; + let _17: (); + let mut _18: f64; + let mut _19: f64; + let _20: (); + let mut _21: f64; + let mut _22: f64; + let _23: (); + let mut _24: bool; + let mut _25: f64; + let mut _26: f64; + let _27: (); + let mut _28: bool; + let mut _29: f64; + let mut _30: f64; + + bb0: { + StorageLive(_2); + StorageLive(_3); +- StorageLive(_4); +- _4 = _1; +- _3 = Add(move _4, const 0f64); +- StorageDead(_4); ++ _3 = Add(_1, const 0f64); + _2 = opaque::(move _3) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageDead(_3); + StorageDead(_2); + StorageLive(_5); + StorageLive(_6); +- StorageLive(_7); +- _7 = _1; +- _6 = Sub(move _7, const 0f64); +- StorageDead(_7); ++ _6 = Sub(_1, const 0f64); + _5 = opaque::(move _6) -> [return: bb2, unwind continue]; + } + + bb2: { + StorageDead(_6); + StorageDead(_5); + StorageLive(_8); + StorageLive(_9); +- StorageLive(_10); +- _10 = _1; +- _9 = Mul(move _10, const 0f64); +- StorageDead(_10); ++ _9 = Mul(_1, const 0f64); + _8 = opaque::(move _9) -> [return: bb3, unwind continue]; + } + + bb3: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_11); + StorageLive(_12); +- StorageLive(_13); +- _13 = _1; +- _12 = Div(move _13, const 0f64); +- StorageDead(_13); ++ _12 = Div(_1, const 0f64); + _11 = opaque::(move _12) -> [return: bb4, unwind continue]; + } + + bb4: { + StorageDead(_12); + StorageDead(_11); + StorageLive(_14); + StorageLive(_15); +- StorageLive(_16); +- _16 = _1; +- _15 = Div(const 0f64, move _16); +- StorageDead(_16); ++ _15 = Div(const 0f64, _1); + _14 = opaque::(move _15) -> [return: bb5, unwind continue]; + } + + bb5: { + StorageDead(_15); + StorageDead(_14); + StorageLive(_17); + StorageLive(_18); +- StorageLive(_19); +- _19 = _1; +- _18 = Rem(move _19, const 0f64); +- StorageDead(_19); ++ _18 = Rem(_1, const 0f64); + _17 = opaque::(move _18) -> [return: bb6, unwind continue]; + } + + bb6: { + StorageDead(_18); + StorageDead(_17); + StorageLive(_20); + StorageLive(_21); +- StorageLive(_22); +- _22 = _1; +- _21 = Rem(const 0f64, move _22); +- StorageDead(_22); ++ _21 = Rem(const 0f64, _1); + _20 = opaque::(move _21) -> [return: bb7, unwind continue]; + } + + bb7: { + StorageDead(_21); + StorageDead(_20); + StorageLive(_23); + StorageLive(_24); +- StorageLive(_25); +- _25 = _1; +- StorageLive(_26); +- _26 = _1; +- _24 = Eq(move _25, move _26); +- StorageDead(_26); +- StorageDead(_25); ++ _24 = Eq(_1, _1); + _23 = opaque::(move _24) -> [return: bb8, unwind continue]; + } + + bb8: { + StorageDead(_24); + StorageDead(_23); + StorageLive(_27); + StorageLive(_28); +- StorageLive(_29); +- _29 = _1; +- StorageLive(_30); +- _30 = _1; +- _28 = Ne(move _29, move _30); +- StorageDead(_30); +- StorageDead(_29); ++ _28 = Ne(_1, _1); + _27 = opaque::(move _28) -> [return: bb9, unwind continue]; + } + + bb9: { + StorageDead(_28); + StorageDead(_27); + _0 = const (); + return; + } + } + diff --git a/tests/mir-opt/gvn.cast.GVN.panic-abort.diff b/tests/mir-opt/gvn.cast.GVN.panic-abort.diff new file mode 100644 index 0000000000000..513fe60b65d93 --- /dev/null +++ b/tests/mir-opt/gvn.cast.GVN.panic-abort.diff @@ -0,0 +1,501 @@ +- // MIR for `cast` before GVN ++ // MIR for `cast` after GVN + + fn cast() -> () { + let mut _0: (); + let _1: i64; + let _4: (); + let mut _5: u8; + let mut _6: i64; + let _7: (); + let mut _8: u16; + let mut _9: i64; + let _10: (); + let mut _11: u32; + let mut _12: i64; + let _13: (); + let mut _14: u64; + let mut _15: i64; + let _16: (); + let mut _17: i8; + let mut _18: i64; + let _19: (); + let mut _20: i16; + let mut _21: i64; + let _22: (); + let mut _23: i32; + let mut _24: i64; + let _25: (); + let mut _26: i64; + let _27: (); + let mut _28: f32; + let mut _29: i64; + let _30: (); + let mut _31: f64; + let mut _32: i64; + let _33: (); + let mut _34: u8; + let mut _35: u64; + let _36: (); + let mut _37: u16; + let mut _38: u64; + let _39: (); + let mut _40: u32; + let mut _41: u64; + let _42: (); + let mut _43: u64; + let _44: (); + let mut _45: i8; + let mut _46: u64; + let _47: (); + let mut _48: i16; + let mut _49: u64; + let _50: (); + let mut _51: i32; + let mut _52: u64; + let _53: (); + let mut _54: i64; + let mut _55: u64; + let _56: (); + let mut _57: f32; + let mut _58: u64; + let _59: (); + let mut _60: f64; + let mut _61: u64; + let _62: (); + let mut _63: u8; + let mut _64: f64; + let _65: (); + let mut _66: u16; + let mut _67: f64; + let _68: (); + let mut _69: u32; + let mut _70: f64; + let _71: (); + let mut _72: u64; + let mut _73: f64; + let _74: (); + let mut _75: i8; + let mut _76: f64; + let _77: (); + let mut _78: i16; + let mut _79: f64; + let _80: (); + let mut _81: i32; + let mut _82: f64; + let _83: (); + let mut _84: i64; + let mut _85: f64; + let _86: (); + let mut _87: f32; + let mut _88: f64; + let _89: (); + let mut _90: f64; + scope 1 { + debug i => _1; + let _2: u64; + scope 2 { + debug u => _2; + let _3: f64; + scope 3 { + debug f => _3; + } + } + } + + bb0: { +- StorageLive(_1); + _1 = const 1_i64; +- StorageLive(_2); + _2 = const 1_u64; +- StorageLive(_3); + _3 = const 1f64; + StorageLive(_4); + StorageLive(_5); +- StorageLive(_6); +- _6 = _1; +- _5 = move _6 as u8 (IntToInt); +- StorageDead(_6); ++ _5 = const 1_i64 as u8 (IntToInt); + _4 = opaque::(move _5) -> [return: bb1, unwind unreachable]; + } + + bb1: { + StorageDead(_5); + StorageDead(_4); + StorageLive(_7); + StorageLive(_8); +- StorageLive(_9); +- _9 = _1; +- _8 = move _9 as u16 (IntToInt); +- StorageDead(_9); ++ _8 = const 1_i64 as u16 (IntToInt); + _7 = opaque::(move _8) -> [return: bb2, unwind unreachable]; + } + + bb2: { + StorageDead(_8); + StorageDead(_7); + StorageLive(_10); + StorageLive(_11); +- StorageLive(_12); +- _12 = _1; +- _11 = move _12 as u32 (IntToInt); +- StorageDead(_12); ++ _11 = const 1_i64 as u32 (IntToInt); + _10 = opaque::(move _11) -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_11); + StorageDead(_10); + StorageLive(_13); + StorageLive(_14); +- StorageLive(_15); +- _15 = _1; +- _14 = move _15 as u64 (IntToInt); +- StorageDead(_15); ++ _14 = const 1_i64 as u64 (IntToInt); + _13 = opaque::(move _14) -> [return: bb4, unwind unreachable]; + } + + bb4: { + StorageDead(_14); + StorageDead(_13); + StorageLive(_16); + StorageLive(_17); +- StorageLive(_18); +- _18 = _1; +- _17 = move _18 as i8 (IntToInt); +- StorageDead(_18); ++ _17 = const 1_i64 as i8 (IntToInt); + _16 = opaque::(move _17) -> [return: bb5, unwind unreachable]; + } + + bb5: { + StorageDead(_17); + StorageDead(_16); + StorageLive(_19); + StorageLive(_20); +- StorageLive(_21); +- _21 = _1; +- _20 = move _21 as i16 (IntToInt); +- StorageDead(_21); ++ _20 = const 1_i64 as i16 (IntToInt); + _19 = opaque::(move _20) -> [return: bb6, unwind unreachable]; + } + + bb6: { + StorageDead(_20); + StorageDead(_19); + StorageLive(_22); + StorageLive(_23); +- StorageLive(_24); +- _24 = _1; +- _23 = move _24 as i32 (IntToInt); +- StorageDead(_24); ++ _23 = const 1_i64 as i32 (IntToInt); + _22 = opaque::(move _23) -> [return: bb7, unwind unreachable]; + } + + bb7: { + StorageDead(_23); + StorageDead(_22); + StorageLive(_25); +- StorageLive(_26); +- _26 = _1; +- _25 = opaque::(move _26) -> [return: bb8, unwind unreachable]; ++ _25 = opaque::(const 1_i64) -> [return: bb8, unwind unreachable]; + } + + bb8: { +- StorageDead(_26); + StorageDead(_25); + StorageLive(_27); + StorageLive(_28); +- StorageLive(_29); +- _29 = _1; +- _28 = move _29 as f32 (IntToFloat); +- StorageDead(_29); ++ _28 = const 1_i64 as f32 (IntToFloat); + _27 = opaque::(move _28) -> [return: bb9, unwind unreachable]; + } + + bb9: { + StorageDead(_28); + StorageDead(_27); + StorageLive(_30); + StorageLive(_31); +- StorageLive(_32); +- _32 = _1; +- _31 = move _32 as f64 (IntToFloat); +- StorageDead(_32); ++ _31 = const 1_i64 as f64 (IntToFloat); + _30 = opaque::(move _31) -> [return: bb10, unwind unreachable]; + } + + bb10: { + StorageDead(_31); + StorageDead(_30); + StorageLive(_33); + StorageLive(_34); +- StorageLive(_35); +- _35 = _2; +- _34 = move _35 as u8 (IntToInt); +- StorageDead(_35); ++ _34 = const 1_u64 as u8 (IntToInt); + _33 = opaque::(move _34) -> [return: bb11, unwind unreachable]; + } + + bb11: { + StorageDead(_34); + StorageDead(_33); + StorageLive(_36); + StorageLive(_37); +- StorageLive(_38); +- _38 = _2; +- _37 = move _38 as u16 (IntToInt); +- StorageDead(_38); ++ _37 = const 1_u64 as u16 (IntToInt); + _36 = opaque::(move _37) -> [return: bb12, unwind unreachable]; + } + + bb12: { + StorageDead(_37); + StorageDead(_36); + StorageLive(_39); + StorageLive(_40); +- StorageLive(_41); +- _41 = _2; +- _40 = move _41 as u32 (IntToInt); +- StorageDead(_41); ++ _40 = const 1_u64 as u32 (IntToInt); + _39 = opaque::(move _40) -> [return: bb13, unwind unreachable]; + } + + bb13: { + StorageDead(_40); + StorageDead(_39); + StorageLive(_42); +- StorageLive(_43); +- _43 = _2; +- _42 = opaque::(move _43) -> [return: bb14, unwind unreachable]; ++ _42 = opaque::(const 1_u64) -> [return: bb14, unwind unreachable]; + } + + bb14: { +- StorageDead(_43); + StorageDead(_42); + StorageLive(_44); + StorageLive(_45); +- StorageLive(_46); +- _46 = _2; +- _45 = move _46 as i8 (IntToInt); +- StorageDead(_46); ++ _45 = const 1_u64 as i8 (IntToInt); + _44 = opaque::(move _45) -> [return: bb15, unwind unreachable]; + } + + bb15: { + StorageDead(_45); + StorageDead(_44); + StorageLive(_47); + StorageLive(_48); +- StorageLive(_49); +- _49 = _2; +- _48 = move _49 as i16 (IntToInt); +- StorageDead(_49); ++ _48 = const 1_u64 as i16 (IntToInt); + _47 = opaque::(move _48) -> [return: bb16, unwind unreachable]; + } + + bb16: { + StorageDead(_48); + StorageDead(_47); + StorageLive(_50); + StorageLive(_51); +- StorageLive(_52); +- _52 = _2; +- _51 = move _52 as i32 (IntToInt); +- StorageDead(_52); ++ _51 = const 1_u64 as i32 (IntToInt); + _50 = opaque::(move _51) -> [return: bb17, unwind unreachable]; + } + + bb17: { + StorageDead(_51); + StorageDead(_50); + StorageLive(_53); + StorageLive(_54); +- StorageLive(_55); +- _55 = _2; +- _54 = move _55 as i64 (IntToInt); +- StorageDead(_55); ++ _54 = const 1_u64 as i64 (IntToInt); + _53 = opaque::(move _54) -> [return: bb18, unwind unreachable]; + } + + bb18: { + StorageDead(_54); + StorageDead(_53); + StorageLive(_56); + StorageLive(_57); +- StorageLive(_58); +- _58 = _2; +- _57 = move _58 as f32 (IntToFloat); +- StorageDead(_58); ++ _57 = const 1_u64 as f32 (IntToFloat); + _56 = opaque::(move _57) -> [return: bb19, unwind unreachable]; + } + + bb19: { + StorageDead(_57); + StorageDead(_56); + StorageLive(_59); + StorageLive(_60); +- StorageLive(_61); +- _61 = _2; +- _60 = move _61 as f64 (IntToFloat); +- StorageDead(_61); ++ _60 = const 1_u64 as f64 (IntToFloat); + _59 = opaque::(move _60) -> [return: bb20, unwind unreachable]; + } + + bb20: { + StorageDead(_60); + StorageDead(_59); + StorageLive(_62); + StorageLive(_63); +- StorageLive(_64); +- _64 = _3; +- _63 = move _64 as u8 (FloatToInt); +- StorageDead(_64); ++ _63 = const 1f64 as u8 (FloatToInt); + _62 = opaque::(move _63) -> [return: bb21, unwind unreachable]; + } + + bb21: { + StorageDead(_63); + StorageDead(_62); + StorageLive(_65); + StorageLive(_66); +- StorageLive(_67); +- _67 = _3; +- _66 = move _67 as u16 (FloatToInt); +- StorageDead(_67); ++ _66 = const 1f64 as u16 (FloatToInt); + _65 = opaque::(move _66) -> [return: bb22, unwind unreachable]; + } + + bb22: { + StorageDead(_66); + StorageDead(_65); + StorageLive(_68); + StorageLive(_69); +- StorageLive(_70); +- _70 = _3; +- _69 = move _70 as u32 (FloatToInt); +- StorageDead(_70); ++ _69 = const 1f64 as u32 (FloatToInt); + _68 = opaque::(move _69) -> [return: bb23, unwind unreachable]; + } + + bb23: { + StorageDead(_69); + StorageDead(_68); + StorageLive(_71); + StorageLive(_72); +- StorageLive(_73); +- _73 = _3; +- _72 = move _73 as u64 (FloatToInt); +- StorageDead(_73); ++ _72 = const 1f64 as u64 (FloatToInt); + _71 = opaque::(move _72) -> [return: bb24, unwind unreachable]; + } + + bb24: { + StorageDead(_72); + StorageDead(_71); + StorageLive(_74); + StorageLive(_75); +- StorageLive(_76); +- _76 = _3; +- _75 = move _76 as i8 (FloatToInt); +- StorageDead(_76); ++ _75 = const 1f64 as i8 (FloatToInt); + _74 = opaque::(move _75) -> [return: bb25, unwind unreachable]; + } + + bb25: { + StorageDead(_75); + StorageDead(_74); + StorageLive(_77); + StorageLive(_78); +- StorageLive(_79); +- _79 = _3; +- _78 = move _79 as i16 (FloatToInt); +- StorageDead(_79); ++ _78 = const 1f64 as i16 (FloatToInt); + _77 = opaque::(move _78) -> [return: bb26, unwind unreachable]; + } + + bb26: { + StorageDead(_78); + StorageDead(_77); + StorageLive(_80); + StorageLive(_81); +- StorageLive(_82); +- _82 = _3; +- _81 = move _82 as i32 (FloatToInt); +- StorageDead(_82); ++ _81 = const 1f64 as i32 (FloatToInt); + _80 = opaque::(move _81) -> [return: bb27, unwind unreachable]; + } + + bb27: { + StorageDead(_81); + StorageDead(_80); + StorageLive(_83); + StorageLive(_84); +- StorageLive(_85); +- _85 = _3; +- _84 = move _85 as i64 (FloatToInt); +- StorageDead(_85); ++ _84 = const 1f64 as i64 (FloatToInt); + _83 = opaque::(move _84) -> [return: bb28, unwind unreachable]; + } + + bb28: { + StorageDead(_84); + StorageDead(_83); + StorageLive(_86); + StorageLive(_87); +- StorageLive(_88); +- _88 = _3; +- _87 = move _88 as f32 (FloatToFloat); +- StorageDead(_88); ++ _87 = const 1f64 as f32 (FloatToFloat); + _86 = opaque::(move _87) -> [return: bb29, unwind unreachable]; + } + + bb29: { + StorageDead(_87); + StorageDead(_86); + StorageLive(_89); +- StorageLive(_90); +- _90 = _3; +- _89 = opaque::(move _90) -> [return: bb30, unwind unreachable]; ++ _89 = opaque::(const 1f64) -> [return: bb30, unwind unreachable]; + } + + bb30: { +- StorageDead(_90); + StorageDead(_89); + _0 = const (); +- StorageDead(_3); +- StorageDead(_2); +- StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff b/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..33192ed8de033 --- /dev/null +++ b/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff @@ -0,0 +1,501 @@ +- // MIR for `cast` before GVN ++ // MIR for `cast` after GVN + + fn cast() -> () { + let mut _0: (); + let _1: i64; + let _4: (); + let mut _5: u8; + let mut _6: i64; + let _7: (); + let mut _8: u16; + let mut _9: i64; + let _10: (); + let mut _11: u32; + let mut _12: i64; + let _13: (); + let mut _14: u64; + let mut _15: i64; + let _16: (); + let mut _17: i8; + let mut _18: i64; + let _19: (); + let mut _20: i16; + let mut _21: i64; + let _22: (); + let mut _23: i32; + let mut _24: i64; + let _25: (); + let mut _26: i64; + let _27: (); + let mut _28: f32; + let mut _29: i64; + let _30: (); + let mut _31: f64; + let mut _32: i64; + let _33: (); + let mut _34: u8; + let mut _35: u64; + let _36: (); + let mut _37: u16; + let mut _38: u64; + let _39: (); + let mut _40: u32; + let mut _41: u64; + let _42: (); + let mut _43: u64; + let _44: (); + let mut _45: i8; + let mut _46: u64; + let _47: (); + let mut _48: i16; + let mut _49: u64; + let _50: (); + let mut _51: i32; + let mut _52: u64; + let _53: (); + let mut _54: i64; + let mut _55: u64; + let _56: (); + let mut _57: f32; + let mut _58: u64; + let _59: (); + let mut _60: f64; + let mut _61: u64; + let _62: (); + let mut _63: u8; + let mut _64: f64; + let _65: (); + let mut _66: u16; + let mut _67: f64; + let _68: (); + let mut _69: u32; + let mut _70: f64; + let _71: (); + let mut _72: u64; + let mut _73: f64; + let _74: (); + let mut _75: i8; + let mut _76: f64; + let _77: (); + let mut _78: i16; + let mut _79: f64; + let _80: (); + let mut _81: i32; + let mut _82: f64; + let _83: (); + let mut _84: i64; + let mut _85: f64; + let _86: (); + let mut _87: f32; + let mut _88: f64; + let _89: (); + let mut _90: f64; + scope 1 { + debug i => _1; + let _2: u64; + scope 2 { + debug u => _2; + let _3: f64; + scope 3 { + debug f => _3; + } + } + } + + bb0: { +- StorageLive(_1); + _1 = const 1_i64; +- StorageLive(_2); + _2 = const 1_u64; +- StorageLive(_3); + _3 = const 1f64; + StorageLive(_4); + StorageLive(_5); +- StorageLive(_6); +- _6 = _1; +- _5 = move _6 as u8 (IntToInt); +- StorageDead(_6); ++ _5 = const 1_i64 as u8 (IntToInt); + _4 = opaque::(move _5) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageDead(_5); + StorageDead(_4); + StorageLive(_7); + StorageLive(_8); +- StorageLive(_9); +- _9 = _1; +- _8 = move _9 as u16 (IntToInt); +- StorageDead(_9); ++ _8 = const 1_i64 as u16 (IntToInt); + _7 = opaque::(move _8) -> [return: bb2, unwind continue]; + } + + bb2: { + StorageDead(_8); + StorageDead(_7); + StorageLive(_10); + StorageLive(_11); +- StorageLive(_12); +- _12 = _1; +- _11 = move _12 as u32 (IntToInt); +- StorageDead(_12); ++ _11 = const 1_i64 as u32 (IntToInt); + _10 = opaque::(move _11) -> [return: bb3, unwind continue]; + } + + bb3: { + StorageDead(_11); + StorageDead(_10); + StorageLive(_13); + StorageLive(_14); +- StorageLive(_15); +- _15 = _1; +- _14 = move _15 as u64 (IntToInt); +- StorageDead(_15); ++ _14 = const 1_i64 as u64 (IntToInt); + _13 = opaque::(move _14) -> [return: bb4, unwind continue]; + } + + bb4: { + StorageDead(_14); + StorageDead(_13); + StorageLive(_16); + StorageLive(_17); +- StorageLive(_18); +- _18 = _1; +- _17 = move _18 as i8 (IntToInt); +- StorageDead(_18); ++ _17 = const 1_i64 as i8 (IntToInt); + _16 = opaque::(move _17) -> [return: bb5, unwind continue]; + } + + bb5: { + StorageDead(_17); + StorageDead(_16); + StorageLive(_19); + StorageLive(_20); +- StorageLive(_21); +- _21 = _1; +- _20 = move _21 as i16 (IntToInt); +- StorageDead(_21); ++ _20 = const 1_i64 as i16 (IntToInt); + _19 = opaque::(move _20) -> [return: bb6, unwind continue]; + } + + bb6: { + StorageDead(_20); + StorageDead(_19); + StorageLive(_22); + StorageLive(_23); +- StorageLive(_24); +- _24 = _1; +- _23 = move _24 as i32 (IntToInt); +- StorageDead(_24); ++ _23 = const 1_i64 as i32 (IntToInt); + _22 = opaque::(move _23) -> [return: bb7, unwind continue]; + } + + bb7: { + StorageDead(_23); + StorageDead(_22); + StorageLive(_25); +- StorageLive(_26); +- _26 = _1; +- _25 = opaque::(move _26) -> [return: bb8, unwind continue]; ++ _25 = opaque::(const 1_i64) -> [return: bb8, unwind continue]; + } + + bb8: { +- StorageDead(_26); + StorageDead(_25); + StorageLive(_27); + StorageLive(_28); +- StorageLive(_29); +- _29 = _1; +- _28 = move _29 as f32 (IntToFloat); +- StorageDead(_29); ++ _28 = const 1_i64 as f32 (IntToFloat); + _27 = opaque::(move _28) -> [return: bb9, unwind continue]; + } + + bb9: { + StorageDead(_28); + StorageDead(_27); + StorageLive(_30); + StorageLive(_31); +- StorageLive(_32); +- _32 = _1; +- _31 = move _32 as f64 (IntToFloat); +- StorageDead(_32); ++ _31 = const 1_i64 as f64 (IntToFloat); + _30 = opaque::(move _31) -> [return: bb10, unwind continue]; + } + + bb10: { + StorageDead(_31); + StorageDead(_30); + StorageLive(_33); + StorageLive(_34); +- StorageLive(_35); +- _35 = _2; +- _34 = move _35 as u8 (IntToInt); +- StorageDead(_35); ++ _34 = const 1_u64 as u8 (IntToInt); + _33 = opaque::(move _34) -> [return: bb11, unwind continue]; + } + + bb11: { + StorageDead(_34); + StorageDead(_33); + StorageLive(_36); + StorageLive(_37); +- StorageLive(_38); +- _38 = _2; +- _37 = move _38 as u16 (IntToInt); +- StorageDead(_38); ++ _37 = const 1_u64 as u16 (IntToInt); + _36 = opaque::(move _37) -> [return: bb12, unwind continue]; + } + + bb12: { + StorageDead(_37); + StorageDead(_36); + StorageLive(_39); + StorageLive(_40); +- StorageLive(_41); +- _41 = _2; +- _40 = move _41 as u32 (IntToInt); +- StorageDead(_41); ++ _40 = const 1_u64 as u32 (IntToInt); + _39 = opaque::(move _40) -> [return: bb13, unwind continue]; + } + + bb13: { + StorageDead(_40); + StorageDead(_39); + StorageLive(_42); +- StorageLive(_43); +- _43 = _2; +- _42 = opaque::(move _43) -> [return: bb14, unwind continue]; ++ _42 = opaque::(const 1_u64) -> [return: bb14, unwind continue]; + } + + bb14: { +- StorageDead(_43); + StorageDead(_42); + StorageLive(_44); + StorageLive(_45); +- StorageLive(_46); +- _46 = _2; +- _45 = move _46 as i8 (IntToInt); +- StorageDead(_46); ++ _45 = const 1_u64 as i8 (IntToInt); + _44 = opaque::(move _45) -> [return: bb15, unwind continue]; + } + + bb15: { + StorageDead(_45); + StorageDead(_44); + StorageLive(_47); + StorageLive(_48); +- StorageLive(_49); +- _49 = _2; +- _48 = move _49 as i16 (IntToInt); +- StorageDead(_49); ++ _48 = const 1_u64 as i16 (IntToInt); + _47 = opaque::(move _48) -> [return: bb16, unwind continue]; + } + + bb16: { + StorageDead(_48); + StorageDead(_47); + StorageLive(_50); + StorageLive(_51); +- StorageLive(_52); +- _52 = _2; +- _51 = move _52 as i32 (IntToInt); +- StorageDead(_52); ++ _51 = const 1_u64 as i32 (IntToInt); + _50 = opaque::(move _51) -> [return: bb17, unwind continue]; + } + + bb17: { + StorageDead(_51); + StorageDead(_50); + StorageLive(_53); + StorageLive(_54); +- StorageLive(_55); +- _55 = _2; +- _54 = move _55 as i64 (IntToInt); +- StorageDead(_55); ++ _54 = const 1_u64 as i64 (IntToInt); + _53 = opaque::(move _54) -> [return: bb18, unwind continue]; + } + + bb18: { + StorageDead(_54); + StorageDead(_53); + StorageLive(_56); + StorageLive(_57); +- StorageLive(_58); +- _58 = _2; +- _57 = move _58 as f32 (IntToFloat); +- StorageDead(_58); ++ _57 = const 1_u64 as f32 (IntToFloat); + _56 = opaque::(move _57) -> [return: bb19, unwind continue]; + } + + bb19: { + StorageDead(_57); + StorageDead(_56); + StorageLive(_59); + StorageLive(_60); +- StorageLive(_61); +- _61 = _2; +- _60 = move _61 as f64 (IntToFloat); +- StorageDead(_61); ++ _60 = const 1_u64 as f64 (IntToFloat); + _59 = opaque::(move _60) -> [return: bb20, unwind continue]; + } + + bb20: { + StorageDead(_60); + StorageDead(_59); + StorageLive(_62); + StorageLive(_63); +- StorageLive(_64); +- _64 = _3; +- _63 = move _64 as u8 (FloatToInt); +- StorageDead(_64); ++ _63 = const 1f64 as u8 (FloatToInt); + _62 = opaque::(move _63) -> [return: bb21, unwind continue]; + } + + bb21: { + StorageDead(_63); + StorageDead(_62); + StorageLive(_65); + StorageLive(_66); +- StorageLive(_67); +- _67 = _3; +- _66 = move _67 as u16 (FloatToInt); +- StorageDead(_67); ++ _66 = const 1f64 as u16 (FloatToInt); + _65 = opaque::(move _66) -> [return: bb22, unwind continue]; + } + + bb22: { + StorageDead(_66); + StorageDead(_65); + StorageLive(_68); + StorageLive(_69); +- StorageLive(_70); +- _70 = _3; +- _69 = move _70 as u32 (FloatToInt); +- StorageDead(_70); ++ _69 = const 1f64 as u32 (FloatToInt); + _68 = opaque::(move _69) -> [return: bb23, unwind continue]; + } + + bb23: { + StorageDead(_69); + StorageDead(_68); + StorageLive(_71); + StorageLive(_72); +- StorageLive(_73); +- _73 = _3; +- _72 = move _73 as u64 (FloatToInt); +- StorageDead(_73); ++ _72 = const 1f64 as u64 (FloatToInt); + _71 = opaque::(move _72) -> [return: bb24, unwind continue]; + } + + bb24: { + StorageDead(_72); + StorageDead(_71); + StorageLive(_74); + StorageLive(_75); +- StorageLive(_76); +- _76 = _3; +- _75 = move _76 as i8 (FloatToInt); +- StorageDead(_76); ++ _75 = const 1f64 as i8 (FloatToInt); + _74 = opaque::(move _75) -> [return: bb25, unwind continue]; + } + + bb25: { + StorageDead(_75); + StorageDead(_74); + StorageLive(_77); + StorageLive(_78); +- StorageLive(_79); +- _79 = _3; +- _78 = move _79 as i16 (FloatToInt); +- StorageDead(_79); ++ _78 = const 1f64 as i16 (FloatToInt); + _77 = opaque::(move _78) -> [return: bb26, unwind continue]; + } + + bb26: { + StorageDead(_78); + StorageDead(_77); + StorageLive(_80); + StorageLive(_81); +- StorageLive(_82); +- _82 = _3; +- _81 = move _82 as i32 (FloatToInt); +- StorageDead(_82); ++ _81 = const 1f64 as i32 (FloatToInt); + _80 = opaque::(move _81) -> [return: bb27, unwind continue]; + } + + bb27: { + StorageDead(_81); + StorageDead(_80); + StorageLive(_83); + StorageLive(_84); +- StorageLive(_85); +- _85 = _3; +- _84 = move _85 as i64 (FloatToInt); +- StorageDead(_85); ++ _84 = const 1f64 as i64 (FloatToInt); + _83 = opaque::(move _84) -> [return: bb28, unwind continue]; + } + + bb28: { + StorageDead(_84); + StorageDead(_83); + StorageLive(_86); + StorageLive(_87); +- StorageLive(_88); +- _88 = _3; +- _87 = move _88 as f32 (FloatToFloat); +- StorageDead(_88); ++ _87 = const 1f64 as f32 (FloatToFloat); + _86 = opaque::(move _87) -> [return: bb29, unwind continue]; + } + + bb29: { + StorageDead(_87); + StorageDead(_86); + StorageLive(_89); +- StorageLive(_90); +- _90 = _3; +- _89 = opaque::(move _90) -> [return: bb30, unwind continue]; ++ _89 = opaque::(const 1f64) -> [return: bb30, unwind continue]; + } + + bb30: { +- StorageDead(_90); + StorageDead(_89); + _0 = const (); +- StorageDead(_3); +- StorageDead(_2); +- StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/gvn.dereferences.GVN.panic-abort.diff b/tests/mir-opt/gvn.dereferences.GVN.panic-abort.diff new file mode 100644 index 0000000000000..ee320cf678701 --- /dev/null +++ b/tests/mir-opt/gvn.dereferences.GVN.panic-abort.diff @@ -0,0 +1,191 @@ +- // MIR for `dereferences` before GVN ++ // MIR for `dereferences` after GVN + + fn dereferences(_1: &mut u32, _2: &impl Copy, _3: &S) -> () { + debug t => _1; + debug u => _2; + debug s => _3; + let mut _0: (); + let _4: (); + let mut _5: u32; + let _6: (); + let mut _7: u32; + let _8: *const u32; + let _9: (); + let mut _10: u32; + let _11: (); + let mut _12: u32; + let _14: (); + let mut _15: u32; + let _16: (); + let mut _17: u32; + let _19: (); + let mut _20: u32; + let _21: (); + let mut _22: u32; + let _23: (); + let mut _24: &u32; + let _25: (); + let mut _26: impl Copy; + let _27: (); + let mut _28: impl Copy; + let _29: (); + let mut _30: u32; + let _31: (); + let mut _32: u32; + scope 1 { + debug z => _8; + let _13: *mut u32; + scope 2 { + } + scope 3 { + } + scope 4 { + debug z => _13; + let _18: &u32; + scope 5 { + } + scope 6 { + } + scope 7 { + debug z => _18; + } + } + } + + bb0: { + StorageLive(_4); + StorageLive(_5); + _5 = (*_1); + _4 = opaque::(move _5) -> [return: bb1, unwind unreachable]; + } + + bb1: { + StorageDead(_5); + StorageDead(_4); + StorageLive(_6); + StorageLive(_7); + _7 = (*_1); + _6 = opaque::(move _7) -> [return: bb2, unwind unreachable]; + } + + bb2: { + StorageDead(_7); + StorageDead(_6); + StorageLive(_8); + _8 = &raw const (*_1); + StorageLive(_9); + StorageLive(_10); + _10 = (*_8); + _9 = opaque::(move _10) -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_10); + StorageDead(_9); + StorageLive(_11); + StorageLive(_12); + _12 = (*_8); + _11 = opaque::(move _12) -> [return: bb4, unwind unreachable]; + } + + bb4: { + StorageDead(_12); + StorageDead(_11); + StorageLive(_13); + _13 = &raw mut (*_1); + StorageLive(_14); + StorageLive(_15); + _15 = (*_13); + _14 = opaque::(move _15) -> [return: bb5, unwind unreachable]; + } + + bb5: { + StorageDead(_15); + StorageDead(_14); + StorageLive(_16); + StorageLive(_17); + _17 = (*_13); + _16 = opaque::(move _17) -> [return: bb6, unwind unreachable]; + } + + bb6: { + StorageDead(_17); + StorageDead(_16); + StorageLive(_18); + _18 = &(*_1); + StorageLive(_19); +- StorageLive(_20); + _20 = (*_18); +- _19 = opaque::(move _20) -> [return: bb7, unwind unreachable]; ++ _19 = opaque::(_20) -> [return: bb7, unwind unreachable]; + } + + bb7: { +- StorageDead(_20); + StorageDead(_19); + StorageLive(_21); +- StorageLive(_22); +- _22 = (*_18); +- _21 = opaque::(move _22) -> [return: bb8, unwind unreachable]; ++ _21 = opaque::(_20) -> [return: bb8, unwind unreachable]; + } + + bb8: { +- StorageDead(_22); + StorageDead(_21); + StorageLive(_23); + StorageLive(_24); + _24 = &(*_18); + _23 = opaque::<&u32>(move _24) -> [return: bb9, unwind unreachable]; + } + + bb9: { + StorageDead(_24); + StorageDead(_23); + StorageLive(_25); + StorageLive(_26); + _26 = (*_2); + _25 = opaque::(move _26) -> [return: bb10, unwind unreachable]; + } + + bb10: { + StorageDead(_26); + StorageDead(_25); + StorageLive(_27); + StorageLive(_28); + _28 = (*_2); + _27 = opaque::(move _28) -> [return: bb11, unwind unreachable]; + } + + bb11: { + StorageDead(_28); + StorageDead(_27); + StorageLive(_29); +- StorageLive(_30); + _30 = ((*_3).0: u32); +- _29 = opaque::(move _30) -> [return: bb12, unwind unreachable]; ++ _29 = opaque::(_30) -> [return: bb12, unwind unreachable]; + } + + bb12: { +- StorageDead(_30); + StorageDead(_29); + StorageLive(_31); +- StorageLive(_32); +- _32 = ((*_3).0: u32); +- _31 = opaque::(move _32) -> [return: bb13, unwind unreachable]; ++ _31 = opaque::(_30) -> [return: bb13, unwind unreachable]; + } + + bb13: { +- StorageDead(_32); + StorageDead(_31); + _0 = const (); + StorageDead(_18); + StorageDead(_13); + StorageDead(_8); + return; + } + } + diff --git a/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff b/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..f627b4d59887a --- /dev/null +++ b/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff @@ -0,0 +1,191 @@ +- // MIR for `dereferences` before GVN ++ // MIR for `dereferences` after GVN + + fn dereferences(_1: &mut u32, _2: &impl Copy, _3: &S) -> () { + debug t => _1; + debug u => _2; + debug s => _3; + let mut _0: (); + let _4: (); + let mut _5: u32; + let _6: (); + let mut _7: u32; + let _8: *const u32; + let _9: (); + let mut _10: u32; + let _11: (); + let mut _12: u32; + let _14: (); + let mut _15: u32; + let _16: (); + let mut _17: u32; + let _19: (); + let mut _20: u32; + let _21: (); + let mut _22: u32; + let _23: (); + let mut _24: &u32; + let _25: (); + let mut _26: impl Copy; + let _27: (); + let mut _28: impl Copy; + let _29: (); + let mut _30: u32; + let _31: (); + let mut _32: u32; + scope 1 { + debug z => _8; + let _13: *mut u32; + scope 2 { + } + scope 3 { + } + scope 4 { + debug z => _13; + let _18: &u32; + scope 5 { + } + scope 6 { + } + scope 7 { + debug z => _18; + } + } + } + + bb0: { + StorageLive(_4); + StorageLive(_5); + _5 = (*_1); + _4 = opaque::(move _5) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageDead(_5); + StorageDead(_4); + StorageLive(_6); + StorageLive(_7); + _7 = (*_1); + _6 = opaque::(move _7) -> [return: bb2, unwind continue]; + } + + bb2: { + StorageDead(_7); + StorageDead(_6); + StorageLive(_8); + _8 = &raw const (*_1); + StorageLive(_9); + StorageLive(_10); + _10 = (*_8); + _9 = opaque::(move _10) -> [return: bb3, unwind continue]; + } + + bb3: { + StorageDead(_10); + StorageDead(_9); + StorageLive(_11); + StorageLive(_12); + _12 = (*_8); + _11 = opaque::(move _12) -> [return: bb4, unwind continue]; + } + + bb4: { + StorageDead(_12); + StorageDead(_11); + StorageLive(_13); + _13 = &raw mut (*_1); + StorageLive(_14); + StorageLive(_15); + _15 = (*_13); + _14 = opaque::(move _15) -> [return: bb5, unwind continue]; + } + + bb5: { + StorageDead(_15); + StorageDead(_14); + StorageLive(_16); + StorageLive(_17); + _17 = (*_13); + _16 = opaque::(move _17) -> [return: bb6, unwind continue]; + } + + bb6: { + StorageDead(_17); + StorageDead(_16); + StorageLive(_18); + _18 = &(*_1); + StorageLive(_19); +- StorageLive(_20); + _20 = (*_18); +- _19 = opaque::(move _20) -> [return: bb7, unwind continue]; ++ _19 = opaque::(_20) -> [return: bb7, unwind continue]; + } + + bb7: { +- StorageDead(_20); + StorageDead(_19); + StorageLive(_21); +- StorageLive(_22); +- _22 = (*_18); +- _21 = opaque::(move _22) -> [return: bb8, unwind continue]; ++ _21 = opaque::(_20) -> [return: bb8, unwind continue]; + } + + bb8: { +- StorageDead(_22); + StorageDead(_21); + StorageLive(_23); + StorageLive(_24); + _24 = &(*_18); + _23 = opaque::<&u32>(move _24) -> [return: bb9, unwind continue]; + } + + bb9: { + StorageDead(_24); + StorageDead(_23); + StorageLive(_25); + StorageLive(_26); + _26 = (*_2); + _25 = opaque::(move _26) -> [return: bb10, unwind continue]; + } + + bb10: { + StorageDead(_26); + StorageDead(_25); + StorageLive(_27); + StorageLive(_28); + _28 = (*_2); + _27 = opaque::(move _28) -> [return: bb11, unwind continue]; + } + + bb11: { + StorageDead(_28); + StorageDead(_27); + StorageLive(_29); +- StorageLive(_30); + _30 = ((*_3).0: u32); +- _29 = opaque::(move _30) -> [return: bb12, unwind continue]; ++ _29 = opaque::(_30) -> [return: bb12, unwind continue]; + } + + bb12: { +- StorageDead(_30); + StorageDead(_29); + StorageLive(_31); +- StorageLive(_32); +- _32 = ((*_3).0: u32); +- _31 = opaque::(move _32) -> [return: bb13, unwind continue]; ++ _31 = opaque::(_30) -> [return: bb13, unwind continue]; + } + + bb13: { +- StorageDead(_32); + StorageDead(_31); + _0 = const (); + StorageDead(_18); + StorageDead(_13); + StorageDead(_8); + return; + } + } + diff --git a/tests/mir-opt/gvn.multiple_branches.GVN.panic-abort.diff b/tests/mir-opt/gvn.multiple_branches.GVN.panic-abort.diff new file mode 100644 index 0000000000000..0a66900283b61 --- /dev/null +++ b/tests/mir-opt/gvn.multiple_branches.GVN.panic-abort.diff @@ -0,0 +1,198 @@ +- // MIR for `multiple_branches` before GVN ++ // MIR for `multiple_branches` after GVN + + fn multiple_branches(_1: bool, _2: u8, _3: u8) -> () { + debug t => _1; + debug x => _2; + debug y => _3; + let mut _0: (); + let _4: (); + let mut _5: bool; + let _6: (); + let mut _7: u8; + let mut _8: u8; + let mut _9: u8; + let _10: (); + let mut _11: u8; + let mut _12: u8; + let mut _13: u8; + let _14: (); + let mut _15: u8; + let mut _16: u8; + let mut _17: u8; + let _18: (); + let mut _19: u8; + let mut _20: u8; + let mut _21: u8; + let _22: (); + let mut _23: u8; + let mut _24: u8; + let mut _25: u8; + let mut _26: bool; + let _27: (); + let mut _28: u8; + let mut _29: u8; + let mut _30: u8; + let _31: (); + let mut _32: u8; + let mut _33: u8; + let mut _34: u8; + + bb0: { +- StorageLive(_4); +- StorageLive(_5); +- _5 = _1; +- switchInt(move _5) -> [0: bb4, otherwise: bb1]; ++ switchInt(_1) -> [0: bb4, otherwise: bb1]; + } + + bb1: { + StorageLive(_6); +- StorageLive(_7); +- StorageLive(_8); +- _8 = _2; +- StorageLive(_9); +- _9 = _3; +- _7 = Add(move _8, move _9); +- StorageDead(_9); +- StorageDead(_8); +- _6 = opaque::(move _7) -> [return: bb2, unwind unreachable]; ++ _7 = Add(_2, _3); ++ _6 = opaque::(_7) -> [return: bb2, unwind unreachable]; + } + + bb2: { +- StorageDead(_7); + StorageDead(_6); + StorageLive(_10); +- StorageLive(_11); +- StorageLive(_12); +- _12 = _2; +- StorageLive(_13); +- _13 = _3; +- _11 = Add(move _12, move _13); +- StorageDead(_13); +- StorageDead(_12); +- _10 = opaque::(move _11) -> [return: bb3, unwind unreachable]; ++ _10 = opaque::(_7) -> [return: bb3, unwind unreachable]; + } + + bb3: { +- StorageDead(_11); + StorageDead(_10); +- _4 = const (); + goto -> bb7; + } + + bb4: { + StorageLive(_14); +- StorageLive(_15); +- StorageLive(_16); +- _16 = _2; +- StorageLive(_17); +- _17 = _3; +- _15 = Add(move _16, move _17); +- StorageDead(_17); +- StorageDead(_16); +- _14 = opaque::(move _15) -> [return: bb5, unwind unreachable]; ++ _15 = Add(_2, _3); ++ _14 = opaque::(_15) -> [return: bb5, unwind unreachable]; + } + + bb5: { +- StorageDead(_15); + StorageDead(_14); + StorageLive(_18); +- StorageLive(_19); +- StorageLive(_20); +- _20 = _2; +- StorageLive(_21); +- _21 = _3; +- _19 = Add(move _20, move _21); +- StorageDead(_21); +- StorageDead(_20); +- _18 = opaque::(move _19) -> [return: bb6, unwind unreachable]; ++ _18 = opaque::(_15) -> [return: bb6, unwind unreachable]; + } + + bb6: { +- StorageDead(_19); + StorageDead(_18); +- _4 = const (); + goto -> bb7; + } + + bb7: { +- StorageDead(_5); +- StorageDead(_4); + StorageLive(_22); +- StorageLive(_23); +- StorageLive(_24); +- _24 = _2; +- StorageLive(_25); +- _25 = _3; +- _23 = Add(move _24, move _25); +- StorageDead(_25); +- StorageDead(_24); +- _22 = opaque::(move _23) -> [return: bb8, unwind unreachable]; ++ _23 = Add(_2, _3); ++ _22 = opaque::(_23) -> [return: bb8, unwind unreachable]; + } + + bb8: { +- StorageDead(_23); + StorageDead(_22); +- StorageLive(_26); +- _26 = _1; +- switchInt(move _26) -> [0: bb11, otherwise: bb9]; ++ switchInt(_1) -> [0: bb11, otherwise: bb9]; + } + + bb9: { + StorageLive(_27); +- StorageLive(_28); +- StorageLive(_29); +- _29 = _2; +- StorageLive(_30); +- _30 = _3; +- _28 = Add(move _29, move _30); +- StorageDead(_30); +- StorageDead(_29); +- _27 = opaque::(move _28) -> [return: bb10, unwind unreachable]; ++ _27 = opaque::(_23) -> [return: bb10, unwind unreachable]; + } + + bb10: { +- StorageDead(_28); + StorageDead(_27); + _0 = const (); + goto -> bb13; + } + + bb11: { + StorageLive(_31); +- StorageLive(_32); +- StorageLive(_33); +- _33 = _2; +- StorageLive(_34); +- _34 = _3; +- _32 = Add(move _33, move _34); +- StorageDead(_34); +- StorageDead(_33); +- _31 = opaque::(move _32) -> [return: bb12, unwind unreachable]; ++ _31 = opaque::(_23) -> [return: bb12, unwind unreachable]; + } + + bb12: { +- StorageDead(_32); + StorageDead(_31); + _0 = const (); + goto -> bb13; + } + + bb13: { +- StorageDead(_26); + return; + } + } + diff --git a/tests/mir-opt/gvn.multiple_branches.GVN.panic-unwind.diff b/tests/mir-opt/gvn.multiple_branches.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..0199f2720a989 --- /dev/null +++ b/tests/mir-opt/gvn.multiple_branches.GVN.panic-unwind.diff @@ -0,0 +1,198 @@ +- // MIR for `multiple_branches` before GVN ++ // MIR for `multiple_branches` after GVN + + fn multiple_branches(_1: bool, _2: u8, _3: u8) -> () { + debug t => _1; + debug x => _2; + debug y => _3; + let mut _0: (); + let _4: (); + let mut _5: bool; + let _6: (); + let mut _7: u8; + let mut _8: u8; + let mut _9: u8; + let _10: (); + let mut _11: u8; + let mut _12: u8; + let mut _13: u8; + let _14: (); + let mut _15: u8; + let mut _16: u8; + let mut _17: u8; + let _18: (); + let mut _19: u8; + let mut _20: u8; + let mut _21: u8; + let _22: (); + let mut _23: u8; + let mut _24: u8; + let mut _25: u8; + let mut _26: bool; + let _27: (); + let mut _28: u8; + let mut _29: u8; + let mut _30: u8; + let _31: (); + let mut _32: u8; + let mut _33: u8; + let mut _34: u8; + + bb0: { +- StorageLive(_4); +- StorageLive(_5); +- _5 = _1; +- switchInt(move _5) -> [0: bb4, otherwise: bb1]; ++ switchInt(_1) -> [0: bb4, otherwise: bb1]; + } + + bb1: { + StorageLive(_6); +- StorageLive(_7); +- StorageLive(_8); +- _8 = _2; +- StorageLive(_9); +- _9 = _3; +- _7 = Add(move _8, move _9); +- StorageDead(_9); +- StorageDead(_8); +- _6 = opaque::(move _7) -> [return: bb2, unwind continue]; ++ _7 = Add(_2, _3); ++ _6 = opaque::(_7) -> [return: bb2, unwind continue]; + } + + bb2: { +- StorageDead(_7); + StorageDead(_6); + StorageLive(_10); +- StorageLive(_11); +- StorageLive(_12); +- _12 = _2; +- StorageLive(_13); +- _13 = _3; +- _11 = Add(move _12, move _13); +- StorageDead(_13); +- StorageDead(_12); +- _10 = opaque::(move _11) -> [return: bb3, unwind continue]; ++ _10 = opaque::(_7) -> [return: bb3, unwind continue]; + } + + bb3: { +- StorageDead(_11); + StorageDead(_10); +- _4 = const (); + goto -> bb7; + } + + bb4: { + StorageLive(_14); +- StorageLive(_15); +- StorageLive(_16); +- _16 = _2; +- StorageLive(_17); +- _17 = _3; +- _15 = Add(move _16, move _17); +- StorageDead(_17); +- StorageDead(_16); +- _14 = opaque::(move _15) -> [return: bb5, unwind continue]; ++ _15 = Add(_2, _3); ++ _14 = opaque::(_15) -> [return: bb5, unwind continue]; + } + + bb5: { +- StorageDead(_15); + StorageDead(_14); + StorageLive(_18); +- StorageLive(_19); +- StorageLive(_20); +- _20 = _2; +- StorageLive(_21); +- _21 = _3; +- _19 = Add(move _20, move _21); +- StorageDead(_21); +- StorageDead(_20); +- _18 = opaque::(move _19) -> [return: bb6, unwind continue]; ++ _18 = opaque::(_15) -> [return: bb6, unwind continue]; + } + + bb6: { +- StorageDead(_19); + StorageDead(_18); +- _4 = const (); + goto -> bb7; + } + + bb7: { +- StorageDead(_5); +- StorageDead(_4); + StorageLive(_22); +- StorageLive(_23); +- StorageLive(_24); +- _24 = _2; +- StorageLive(_25); +- _25 = _3; +- _23 = Add(move _24, move _25); +- StorageDead(_25); +- StorageDead(_24); +- _22 = opaque::(move _23) -> [return: bb8, unwind continue]; ++ _23 = Add(_2, _3); ++ _22 = opaque::(_23) -> [return: bb8, unwind continue]; + } + + bb8: { +- StorageDead(_23); + StorageDead(_22); +- StorageLive(_26); +- _26 = _1; +- switchInt(move _26) -> [0: bb11, otherwise: bb9]; ++ switchInt(_1) -> [0: bb11, otherwise: bb9]; + } + + bb9: { + StorageLive(_27); +- StorageLive(_28); +- StorageLive(_29); +- _29 = _2; +- StorageLive(_30); +- _30 = _3; +- _28 = Add(move _29, move _30); +- StorageDead(_30); +- StorageDead(_29); +- _27 = opaque::(move _28) -> [return: bb10, unwind continue]; ++ _27 = opaque::(_23) -> [return: bb10, unwind continue]; + } + + bb10: { +- StorageDead(_28); + StorageDead(_27); + _0 = const (); + goto -> bb13; + } + + bb11: { + StorageLive(_31); +- StorageLive(_32); +- StorageLive(_33); +- _33 = _2; +- StorageLive(_34); +- _34 = _3; +- _32 = Add(move _33, move _34); +- StorageDead(_34); +- StorageDead(_33); +- _31 = opaque::(move _32) -> [return: bb12, unwind continue]; ++ _31 = opaque::(_23) -> [return: bb12, unwind continue]; + } + + bb12: { +- StorageDead(_32); + StorageDead(_31); + _0 = const (); + goto -> bb13; + } + + bb13: { +- StorageDead(_26); + return; + } + } + diff --git a/tests/mir-opt/gvn.references.GVN.panic-abort.diff b/tests/mir-opt/gvn.references.GVN.panic-abort.diff new file mode 100644 index 0000000000000..b7ad4ab1fd3d8 --- /dev/null +++ b/tests/mir-opt/gvn.references.GVN.panic-abort.diff @@ -0,0 +1,105 @@ +- // MIR for `references` before GVN ++ // MIR for `references` after GVN + + fn references(_1: impl Sized) -> () { + debug x => _1; + let mut _0: (); + let _2: (); + let mut _3: &impl Sized; + let _4: (); + let mut _5: &impl Sized; + let _6: (); + let mut _7: &mut impl Sized; + let _8: (); + let mut _9: &mut impl Sized; + let _10: (); + let mut _11: *const impl Sized; + let _12: (); + let mut _13: *const impl Sized; + let _14: (); + let mut _15: *mut impl Sized; + let _16: (); + let mut _17: *mut impl Sized; + + bb0: { + StorageLive(_2); + StorageLive(_3); + _3 = &_1; + _2 = opaque::<&impl Sized>(move _3) -> [return: bb1, unwind unreachable]; + } + + bb1: { + StorageDead(_3); + StorageDead(_2); + StorageLive(_4); + StorageLive(_5); + _5 = &_1; + _4 = opaque::<&impl Sized>(move _5) -> [return: bb2, unwind unreachable]; + } + + bb2: { + StorageDead(_5); + StorageDead(_4); + StorageLive(_6); + StorageLive(_7); + _7 = &mut _1; + _6 = opaque::<&mut impl Sized>(move _7) -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_7); + StorageDead(_6); + StorageLive(_8); + StorageLive(_9); + _9 = &mut _1; + _8 = opaque::<&mut impl Sized>(move _9) -> [return: bb4, unwind unreachable]; + } + + bb4: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_10); + StorageLive(_11); + _11 = &raw const _1; + _10 = opaque::<*const impl Sized>(move _11) -> [return: bb5, unwind unreachable]; + } + + bb5: { + StorageDead(_11); + StorageDead(_10); + StorageLive(_12); + StorageLive(_13); + _13 = &raw const _1; + _12 = opaque::<*const impl Sized>(move _13) -> [return: bb6, unwind unreachable]; + } + + bb6: { + StorageDead(_13); + StorageDead(_12); + StorageLive(_14); + StorageLive(_15); + _15 = &raw mut _1; + _14 = opaque::<*mut impl Sized>(move _15) -> [return: bb7, unwind unreachable]; + } + + bb7: { + StorageDead(_15); + StorageDead(_14); + StorageLive(_16); + StorageLive(_17); + _17 = &raw mut _1; + _16 = opaque::<*mut impl Sized>(move _17) -> [return: bb8, unwind unreachable]; + } + + bb8: { + StorageDead(_17); + StorageDead(_16); + _0 = const (); + drop(_1) -> [return: bb9, unwind unreachable]; + } + + bb9: { + return; + } + } + diff --git a/tests/mir-opt/gvn.references.GVN.panic-unwind.diff b/tests/mir-opt/gvn.references.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..08ed4c629a6dd --- /dev/null +++ b/tests/mir-opt/gvn.references.GVN.panic-unwind.diff @@ -0,0 +1,113 @@ +- // MIR for `references` before GVN ++ // MIR for `references` after GVN + + fn references(_1: impl Sized) -> () { + debug x => _1; + let mut _0: (); + let _2: (); + let mut _3: &impl Sized; + let _4: (); + let mut _5: &impl Sized; + let _6: (); + let mut _7: &mut impl Sized; + let _8: (); + let mut _9: &mut impl Sized; + let _10: (); + let mut _11: *const impl Sized; + let _12: (); + let mut _13: *const impl Sized; + let _14: (); + let mut _15: *mut impl Sized; + let _16: (); + let mut _17: *mut impl Sized; + + bb0: { + StorageLive(_2); + StorageLive(_3); + _3 = &_1; + _2 = opaque::<&impl Sized>(move _3) -> [return: bb1, unwind: bb10]; + } + + bb1: { + StorageDead(_3); + StorageDead(_2); + StorageLive(_4); + StorageLive(_5); + _5 = &_1; + _4 = opaque::<&impl Sized>(move _5) -> [return: bb2, unwind: bb10]; + } + + bb2: { + StorageDead(_5); + StorageDead(_4); + StorageLive(_6); + StorageLive(_7); + _7 = &mut _1; + _6 = opaque::<&mut impl Sized>(move _7) -> [return: bb3, unwind: bb10]; + } + + bb3: { + StorageDead(_7); + StorageDead(_6); + StorageLive(_8); + StorageLive(_9); + _9 = &mut _1; + _8 = opaque::<&mut impl Sized>(move _9) -> [return: bb4, unwind: bb10]; + } + + bb4: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_10); + StorageLive(_11); + _11 = &raw const _1; + _10 = opaque::<*const impl Sized>(move _11) -> [return: bb5, unwind: bb10]; + } + + bb5: { + StorageDead(_11); + StorageDead(_10); + StorageLive(_12); + StorageLive(_13); + _13 = &raw const _1; + _12 = opaque::<*const impl Sized>(move _13) -> [return: bb6, unwind: bb10]; + } + + bb6: { + StorageDead(_13); + StorageDead(_12); + StorageLive(_14); + StorageLive(_15); + _15 = &raw mut _1; + _14 = opaque::<*mut impl Sized>(move _15) -> [return: bb7, unwind: bb10]; + } + + bb7: { + StorageDead(_15); + StorageDead(_14); + StorageLive(_16); + StorageLive(_17); + _17 = &raw mut _1; + _16 = opaque::<*mut impl Sized>(move _17) -> [return: bb8, unwind: bb10]; + } + + bb8: { + StorageDead(_17); + StorageDead(_16); + _0 = const (); + drop(_1) -> [return: bb9, unwind: bb11]; + } + + bb9: { + return; + } + + bb10 (cleanup): { + drop(_1) -> [return: bb11, unwind terminate(cleanup)]; + } + + bb11 (cleanup): { + resume; + } + } + diff --git a/tests/mir-opt/gvn.repeated_index.GVN.panic-abort.diff b/tests/mir-opt/gvn.repeated_index.GVN.panic-abort.diff new file mode 100644 index 0000000000000..4c29523d6b282 --- /dev/null +++ b/tests/mir-opt/gvn.repeated_index.GVN.panic-abort.diff @@ -0,0 +1,76 @@ +- // MIR for `repeated_index` before GVN ++ // MIR for `repeated_index` after GVN + + fn repeated_index(_1: T, _2: usize) -> () { + debug x => _1; + debug idx => _2; + let mut _0: (); + let _3: [T; N]; + let mut _4: T; + let _5: (); + let mut _6: T; + let _7: usize; + let mut _8: usize; + let mut _9: bool; + let _10: (); + let mut _11: T; + let _12: usize; + let mut _13: usize; + let mut _14: bool; + scope 1 { + debug a => _3; + } + + bb0: { + StorageLive(_3); +- StorageLive(_4); +- _4 = _1; +- _3 = [move _4; N]; +- StorageDead(_4); ++ _3 = [_1; N]; + StorageLive(_5); + StorageLive(_6); + StorageLive(_7); + _7 = const 0_usize; + _8 = Len(_3); +- _9 = Lt(_7, _8); +- assert(move _9, "index out of bounds: the length is {} but the index is {}", move _8, _7) -> [success: bb1, unwind unreachable]; ++ _9 = Lt(const 0_usize, _8); ++ assert(move _9, "index out of bounds: the length is {} but the index is {}", _8, const 0_usize) -> [success: bb1, unwind unreachable]; + } + + bb1: { + _6 = _3[_7]; + _5 = opaque::(move _6) -> [return: bb2, unwind unreachable]; + } + + bb2: { + StorageDead(_6); + StorageDead(_7); + StorageDead(_5); + StorageLive(_10); + StorageLive(_11); + StorageLive(_12); + _12 = _2; +- _13 = Len(_3); +- _14 = Lt(_12, _13); +- assert(move _14, "index out of bounds: the length is {} but the index is {}", move _13, _12) -> [success: bb3, unwind unreachable]; ++ _14 = Lt(_2, _8); ++ assert(move _14, "index out of bounds: the length is {} but the index is {}", _8, _2) -> [success: bb3, unwind unreachable]; + } + + bb3: { + _11 = _3[_12]; + _10 = opaque::(move _11) -> [return: bb4, unwind unreachable]; + } + + bb4: { + StorageDead(_11); + StorageDead(_12); + StorageDead(_10); + _0 = const (); + StorageDead(_3); + return; + } + } + diff --git a/tests/mir-opt/gvn.repeated_index.GVN.panic-unwind.diff b/tests/mir-opt/gvn.repeated_index.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..e44f54cf3cf3c --- /dev/null +++ b/tests/mir-opt/gvn.repeated_index.GVN.panic-unwind.diff @@ -0,0 +1,76 @@ +- // MIR for `repeated_index` before GVN ++ // MIR for `repeated_index` after GVN + + fn repeated_index(_1: T, _2: usize) -> () { + debug x => _1; + debug idx => _2; + let mut _0: (); + let _3: [T; N]; + let mut _4: T; + let _5: (); + let mut _6: T; + let _7: usize; + let mut _8: usize; + let mut _9: bool; + let _10: (); + let mut _11: T; + let _12: usize; + let mut _13: usize; + let mut _14: bool; + scope 1 { + debug a => _3; + } + + bb0: { + StorageLive(_3); +- StorageLive(_4); +- _4 = _1; +- _3 = [move _4; N]; +- StorageDead(_4); ++ _3 = [_1; N]; + StorageLive(_5); + StorageLive(_6); + StorageLive(_7); + _7 = const 0_usize; + _8 = Len(_3); +- _9 = Lt(_7, _8); +- assert(move _9, "index out of bounds: the length is {} but the index is {}", move _8, _7) -> [success: bb1, unwind continue]; ++ _9 = Lt(const 0_usize, _8); ++ assert(move _9, "index out of bounds: the length is {} but the index is {}", _8, const 0_usize) -> [success: bb1, unwind continue]; + } + + bb1: { + _6 = _3[_7]; + _5 = opaque::(move _6) -> [return: bb2, unwind continue]; + } + + bb2: { + StorageDead(_6); + StorageDead(_7); + StorageDead(_5); + StorageLive(_10); + StorageLive(_11); + StorageLive(_12); + _12 = _2; +- _13 = Len(_3); +- _14 = Lt(_12, _13); +- assert(move _14, "index out of bounds: the length is {} but the index is {}", move _13, _12) -> [success: bb3, unwind continue]; ++ _14 = Lt(_2, _8); ++ assert(move _14, "index out of bounds: the length is {} but the index is {}", _8, _2) -> [success: bb3, unwind continue]; + } + + bb3: { + _11 = _3[_12]; + _10 = opaque::(move _11) -> [return: bb4, unwind continue]; + } + + bb4: { + StorageDead(_11); + StorageDead(_12); + StorageDead(_10); + _0 = const (); + StorageDead(_3); + return; + } + } + diff --git a/tests/mir-opt/gvn.rs b/tests/mir-opt/gvn.rs new file mode 100644 index 0000000000000..a85e2ae368b41 --- /dev/null +++ b/tests/mir-opt/gvn.rs @@ -0,0 +1,253 @@ +// unit-test: GVN +// EMIT_MIR_FOR_EACH_PANIC_STRATEGY + +#![feature(raw_ref_op)] +#![feature(rustc_attrs)] +#![allow(unconditional_panic)] + +struct S(T); + +fn subexpression_elimination(x: u64, y: u64, mut z: u64) { + opaque(x + y); + opaque(x * y); + opaque(x - y); + opaque(x / y); + opaque(x % y); + opaque(x & y); + opaque(x | y); + opaque(x ^ y); + opaque(x << y); + opaque(x >> y); + opaque(x as u32); + opaque(x as f32); + opaque(S(x)); + opaque(S(x).0); + + // Those are duplicates to substitute somehow. + opaque((x + y) + z); + opaque((x * y) + z); + opaque((x - y) + z); + opaque((x / y) + z); + opaque((x % y) + z); + opaque((x & y) + z); + opaque((x | y) + z); + opaque((x ^ y) + z); + opaque((x << y) + z); + opaque((x >> y) + z); + opaque(S(x)); + opaque(S(x).0); + + // We can substitute through an immutable reference too. + let a = &z; + opaque(*a + x); + opaque(*a + x); + + // But not through a mutable reference or a pointer. + let b = &mut z; + opaque(*b + x); + opaque(*b + x); + unsafe { + let c = &raw const z; + opaque(*c + x); + opaque(*c + x); + let d = &raw mut z; + opaque(*d + x); + opaque(*d + x); + } + + // We can substitute again, but not with the earlier computations. + // Important: `e` is not `a`! + let e = &z; + opaque(*e + x); + opaque(*e + x); + +} + +fn wrap_unwrap(x: T) -> T { + match Some(x) { + Some(y) => y, + None => panic!(), + } +} + +fn repeated_index(x: T, idx: usize) { + let a = [x; N]; + opaque(a[0]); + opaque(a[idx]); +} + +fn arithmetic(x: u64) { + opaque(x + 0); + opaque(x - 0); + opaque(x * 0); + opaque(x * 1); + opaque(x / 0); + opaque(x / 1); + opaque(0 / x); + opaque(1 / x); + opaque(x % 0); + opaque(x % 1); + opaque(0 % x); + opaque(1 % x); + opaque(x & 0); + opaque(x | 0); + opaque(x ^ 0); + opaque(x >> 0); + opaque(x << 0); +} + +#[rustc_inherit_overflow_checks] +fn arithmetic_checked(x: u64) { + opaque(x + 0); + opaque(x - 0); + opaque(x * 0); + opaque(x * 1); + opaque(x / 0); + opaque(x / 1); + opaque(0 / x); + opaque(1 / x); + opaque(x % 0); + opaque(x % 1); + opaque(0 % x); + opaque(1 % x); + opaque(x & 0); + opaque(x | 0); + opaque(x ^ 0); + opaque(x >> 0); + opaque(x << 0); +} + +fn arithmetic_float(x: f64) { + opaque(x + 0.); + opaque(x - 0.); + opaque(x * 0.); + opaque(x / 0.); + opaque(0. / x); + opaque(x % 0.); + opaque(0. % x); + // Those are not simplifiable to `true`/`false`, thanks to NaNs. + opaque(x == x); + opaque(x != x); +} + +fn cast() { + let i = 1_i64; + let u = 1_u64; + let f = 1_f64; + opaque(i as u8); + opaque(i as u16); + opaque(i as u32); + opaque(i as u64); + opaque(i as i8); + opaque(i as i16); + opaque(i as i32); + opaque(i as i64); + opaque(i as f32); + opaque(i as f64); + opaque(u as u8); + opaque(u as u16); + opaque(u as u32); + opaque(u as u64); + opaque(u as i8); + opaque(u as i16); + opaque(u as i32); + opaque(u as i64); + opaque(u as f32); + opaque(u as f64); + opaque(f as u8); + opaque(f as u16); + opaque(f as u32); + opaque(f as u64); + opaque(f as i8); + opaque(f as i16); + opaque(f as i32); + opaque(f as i64); + opaque(f as f32); + opaque(f as f64); +} + +fn multiple_branches(t: bool, x: u8, y: u8) { + if t { + opaque(x + y); // a + opaque(x + y); // should reuse a + } else { + opaque(x + y); // b + opaque(x + y); // shoud reuse b + } + opaque(x + y); // c + if t { + opaque(x + y); // should reuse c + } else { + opaque(x + y); // should reuse c + } +} + +fn references(mut x: impl Sized) { + opaque(&x); + opaque(&x); // should not reuse a + opaque(&mut x); + opaque(&mut x); // should not reuse a + opaque(&raw const x); + opaque(&raw const x); // should not reuse a + opaque(&raw mut x); + opaque(&raw mut x); // should not reuse a +} + +fn dereferences(t: &mut u32, u: &impl Copy, s: &S) { + opaque(*t); + opaque(*t); // this cannot reuse a, as x is &mut. + let z = &raw const *t; + unsafe { opaque(*z) }; + unsafe { opaque(*z) }; // this cannot reuse a, as x is *const. + let z = &raw mut *t; + unsafe { opaque(*z) }; + unsafe { opaque(*z) }; // this cannot reuse a, as x is *mut. + let z = &*t; + opaque(*z); + opaque(*z); // this can reuse, as `z` is immutable ref, Freeze and Copy. + opaque(&*z); // but not for a reborrow. + opaque(*u); + opaque(*u); // this cannot reuse, as `z` is not Freeze. + opaque(s.0); + opaque(s.0); // *s is not Copy, by (*s).0 is, so we can reuse. +} + +fn slices() { + let s = "my favourite slice"; // This is a `Const::Slice` in MIR. + opaque(s); + let t = s; // This should be the same pointer, so cannot be a `Const::Slice`. + opaque(t); + assert_eq!(s.as_ptr(), t.as_ptr()); + let u = unsafe { std::mem::transmute::<&str, &[u8]>(s) }; + opaque(u); + assert_eq!(s.as_ptr(), u.as_ptr()); +} + +fn main() { + subexpression_elimination(2, 4, 5); + wrap_unwrap(5); + repeated_index::(5, 3); + arithmetic(5); + arithmetic_checked(5); + arithmetic_float(5.); + cast(); + multiple_branches(true, 5, 9); + references(5); + dereferences(&mut 5, &6, &S(7)); + slices(); +} + +#[inline(never)] +fn opaque(_: impl Sized) {} + +// EMIT_MIR gvn.subexpression_elimination.GVN.diff +// EMIT_MIR gvn.wrap_unwrap.GVN.diff +// EMIT_MIR gvn.repeated_index.GVN.diff +// EMIT_MIR gvn.arithmetic.GVN.diff +// EMIT_MIR gvn.arithmetic_checked.GVN.diff +// EMIT_MIR gvn.arithmetic_float.GVN.diff +// EMIT_MIR gvn.cast.GVN.diff +// EMIT_MIR gvn.multiple_branches.GVN.diff +// EMIT_MIR gvn.references.GVN.diff +// EMIT_MIR gvn.dereferences.GVN.diff +// EMIT_MIR gvn.slices.GVN.diff diff --git a/tests/mir-opt/gvn.slices.GVN.panic-abort.diff b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff new file mode 100644 index 0000000000000..de3d28d057594 --- /dev/null +++ b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff @@ -0,0 +1,275 @@ +- // MIR for `slices` before GVN ++ // MIR for `slices` after GVN + + fn slices() -> () { + let mut _0: (); + let _1: &str; + let _2: (); + let mut _3: &str; + let _5: (); + let mut _6: &str; + let _7: (); + let mut _8: (&*const u8, &*const u8); + let mut _9: &*const u8; + let _10: *const u8; + let mut _11: &str; + let mut _12: &*const u8; + let _13: *const u8; + let mut _14: &str; + let mut _17: bool; + let mut _18: *const u8; + let mut _19: *const u8; + let mut _20: !; + let _22: !; + let mut _23: core::panicking::AssertKind; + let mut _24: &*const u8; + let _25: &*const u8; + let mut _26: &*const u8; + let _27: &*const u8; + let mut _28: std::option::Option>; + let mut _30: &str; + let _31: (); + let mut _32: &[u8]; + let _33: (); + let mut _34: (&*const u8, &*const u8); + let mut _35: &*const u8; + let _36: *const u8; + let mut _37: &str; + let mut _38: &*const u8; + let _39: *const u8; + let mut _40: &[u8]; + let mut _43: bool; + let mut _44: *const u8; + let mut _45: *const u8; + let mut _46: !; + let _48: !; + let mut _49: core::panicking::AssertKind; + let mut _50: &*const u8; + let _51: &*const u8; + let mut _52: &*const u8; + let _53: &*const u8; + let mut _54: std::option::Option>; + scope 1 { + debug s => _1; + let _4: &str; + scope 2 { + debug t => _4; + let _15: &*const u8; + let _16: &*const u8; + let _29: &[u8]; + scope 3 { + debug left_val => _15; + debug right_val => _16; + let _21: core::panicking::AssertKind; + scope 4 { + debug kind => _21; + } + } + scope 5 { + debug u => _29; + let _41: &*const u8; + let _42: &*const u8; + scope 7 { + debug left_val => _41; + debug right_val => _42; + let _47: core::panicking::AssertKind; + scope 8 { + debug kind => _47; + } + } + } + scope 6 { + } + } + } + + bb0: { +- StorageLive(_1); + _1 = const "my favourite slice"; + StorageLive(_2); +- StorageLive(_3); +- _3 = _1; +- _2 = opaque::<&str>(move _3) -> [return: bb1, unwind unreachable]; ++ _2 = opaque::<&str>(_1) -> [return: bb1, unwind unreachable]; + } + + bb1: { +- StorageDead(_3); + StorageDead(_2); + StorageLive(_4); + _4 = _1; + StorageLive(_5); +- StorageLive(_6); +- _6 = _4; +- _5 = opaque::<&str>(move _6) -> [return: bb2, unwind unreachable]; ++ _5 = opaque::<&str>(_1) -> [return: bb2, unwind unreachable]; + } + + bb2: { +- StorageDead(_6); + StorageDead(_5); +- StorageLive(_7); + StorageLive(_8); + StorageLive(_9); + StorageLive(_10); + StorageLive(_11); + _11 = &(*_1); + _10 = core::str::::as_ptr(move _11) -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_11); + _9 = &_10; + StorageLive(_12); + StorageLive(_13); + StorageLive(_14); + _14 = &(*_4); + _13 = core::str::::as_ptr(move _14) -> [return: bb4, unwind unreachable]; + } + + bb4: { + StorageDead(_14); + _12 = &_13; + _8 = (move _9, move _12); + StorageDead(_12); + StorageDead(_9); + StorageLive(_15); + _15 = (_8.0: &*const u8); + StorageLive(_16); + _16 = (_8.1: &*const u8); + StorageLive(_17); + StorageLive(_18); + _18 = (*_15); + StorageLive(_19); + _19 = (*_16); + _17 = Eq(move _18, move _19); + switchInt(move _17) -> [0: bb6, otherwise: bb5]; + } + + bb5: { + StorageDead(_19); + StorageDead(_18); +- _7 = const (); + StorageDead(_17); + StorageDead(_16); + StorageDead(_15); + StorageDead(_13); + StorageDead(_10); + StorageDead(_8); +- StorageDead(_7); +- StorageLive(_29); + StorageLive(_30); + _30 = &(*_1); + _29 = move _30 as &[u8] (Transmute); + StorageDead(_30); + StorageLive(_31); +- StorageLive(_32); +- _32 = _29; +- _31 = opaque::<&[u8]>(move _32) -> [return: bb7, unwind unreachable]; ++ _31 = opaque::<&[u8]>(_29) -> [return: bb7, unwind unreachable]; + } + + bb6: { + StorageDead(_19); + StorageDead(_18); +- StorageLive(_21); + _21 = core::panicking::AssertKind::Eq; + StorageLive(_22); +- StorageLive(_23); +- _23 = move _21; + StorageLive(_24); + StorageLive(_25); + _25 = &(*_15); + _24 = &(*_25); + StorageLive(_26); + StorageLive(_27); + _27 = &(*_16); + _26 = &(*_27); + StorageLive(_28); + _28 = Option::>::None; +- _22 = core::panicking::assert_failed::<*const u8, *const u8>(move _23, move _24, move _26, move _28) -> unwind unreachable; ++ _22 = core::panicking::assert_failed::<*const u8, *const u8>(_21, move _24, move _26, move _28) -> unwind unreachable; + } + + bb7: { +- StorageDead(_32); + StorageDead(_31); +- StorageLive(_33); + StorageLive(_34); + StorageLive(_35); + StorageLive(_36); + StorageLive(_37); + _37 = &(*_1); + _36 = core::str::::as_ptr(move _37) -> [return: bb8, unwind unreachable]; + } + + bb8: { + StorageDead(_37); + _35 = &_36; + StorageLive(_38); + StorageLive(_39); + StorageLive(_40); + _40 = &(*_29); + _39 = core::slice::::as_ptr(move _40) -> [return: bb9, unwind unreachable]; + } + + bb9: { + StorageDead(_40); + _38 = &_39; + _34 = (move _35, move _38); + StorageDead(_38); + StorageDead(_35); + StorageLive(_41); + _41 = (_34.0: &*const u8); + StorageLive(_42); + _42 = (_34.1: &*const u8); + StorageLive(_43); + StorageLive(_44); + _44 = (*_41); + StorageLive(_45); + _45 = (*_42); + _43 = Eq(move _44, move _45); + switchInt(move _43) -> [0: bb11, otherwise: bb10]; + } + + bb10: { + StorageDead(_45); + StorageDead(_44); +- _33 = const (); + StorageDead(_43); + StorageDead(_42); + StorageDead(_41); + StorageDead(_39); + StorageDead(_36); + StorageDead(_34); +- StorageDead(_33); + _0 = const (); +- StorageDead(_29); + StorageDead(_4); +- StorageDead(_1); + return; + } + + bb11: { + StorageDead(_45); + StorageDead(_44); +- StorageLive(_47); + _47 = core::panicking::AssertKind::Eq; + StorageLive(_48); +- StorageLive(_49); +- _49 = move _47; + StorageLive(_50); + StorageLive(_51); + _51 = &(*_41); + _50 = &(*_51); + StorageLive(_52); + StorageLive(_53); + _53 = &(*_42); + _52 = &(*_53); + StorageLive(_54); + _54 = Option::>::None; +- _48 = core::panicking::assert_failed::<*const u8, *const u8>(move _49, move _50, move _52, move _54) -> unwind unreachable; ++ _48 = core::panicking::assert_failed::<*const u8, *const u8>(_47, move _50, move _52, move _54) -> unwind unreachable; + } + } + diff --git a/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff b/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..f22bb25436f05 --- /dev/null +++ b/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff @@ -0,0 +1,275 @@ +- // MIR for `slices` before GVN ++ // MIR for `slices` after GVN + + fn slices() -> () { + let mut _0: (); + let _1: &str; + let _2: (); + let mut _3: &str; + let _5: (); + let mut _6: &str; + let _7: (); + let mut _8: (&*const u8, &*const u8); + let mut _9: &*const u8; + let _10: *const u8; + let mut _11: &str; + let mut _12: &*const u8; + let _13: *const u8; + let mut _14: &str; + let mut _17: bool; + let mut _18: *const u8; + let mut _19: *const u8; + let mut _20: !; + let _22: !; + let mut _23: core::panicking::AssertKind; + let mut _24: &*const u8; + let _25: &*const u8; + let mut _26: &*const u8; + let _27: &*const u8; + let mut _28: std::option::Option>; + let mut _30: &str; + let _31: (); + let mut _32: &[u8]; + let _33: (); + let mut _34: (&*const u8, &*const u8); + let mut _35: &*const u8; + let _36: *const u8; + let mut _37: &str; + let mut _38: &*const u8; + let _39: *const u8; + let mut _40: &[u8]; + let mut _43: bool; + let mut _44: *const u8; + let mut _45: *const u8; + let mut _46: !; + let _48: !; + let mut _49: core::panicking::AssertKind; + let mut _50: &*const u8; + let _51: &*const u8; + let mut _52: &*const u8; + let _53: &*const u8; + let mut _54: std::option::Option>; + scope 1 { + debug s => _1; + let _4: &str; + scope 2 { + debug t => _4; + let _15: &*const u8; + let _16: &*const u8; + let _29: &[u8]; + scope 3 { + debug left_val => _15; + debug right_val => _16; + let _21: core::panicking::AssertKind; + scope 4 { + debug kind => _21; + } + } + scope 5 { + debug u => _29; + let _41: &*const u8; + let _42: &*const u8; + scope 7 { + debug left_val => _41; + debug right_val => _42; + let _47: core::panicking::AssertKind; + scope 8 { + debug kind => _47; + } + } + } + scope 6 { + } + } + } + + bb0: { +- StorageLive(_1); + _1 = const "my favourite slice"; + StorageLive(_2); +- StorageLive(_3); +- _3 = _1; +- _2 = opaque::<&str>(move _3) -> [return: bb1, unwind continue]; ++ _2 = opaque::<&str>(_1) -> [return: bb1, unwind continue]; + } + + bb1: { +- StorageDead(_3); + StorageDead(_2); + StorageLive(_4); + _4 = _1; + StorageLive(_5); +- StorageLive(_6); +- _6 = _4; +- _5 = opaque::<&str>(move _6) -> [return: bb2, unwind continue]; ++ _5 = opaque::<&str>(_1) -> [return: bb2, unwind continue]; + } + + bb2: { +- StorageDead(_6); + StorageDead(_5); +- StorageLive(_7); + StorageLive(_8); + StorageLive(_9); + StorageLive(_10); + StorageLive(_11); + _11 = &(*_1); + _10 = core::str::::as_ptr(move _11) -> [return: bb3, unwind continue]; + } + + bb3: { + StorageDead(_11); + _9 = &_10; + StorageLive(_12); + StorageLive(_13); + StorageLive(_14); + _14 = &(*_4); + _13 = core::str::::as_ptr(move _14) -> [return: bb4, unwind continue]; + } + + bb4: { + StorageDead(_14); + _12 = &_13; + _8 = (move _9, move _12); + StorageDead(_12); + StorageDead(_9); + StorageLive(_15); + _15 = (_8.0: &*const u8); + StorageLive(_16); + _16 = (_8.1: &*const u8); + StorageLive(_17); + StorageLive(_18); + _18 = (*_15); + StorageLive(_19); + _19 = (*_16); + _17 = Eq(move _18, move _19); + switchInt(move _17) -> [0: bb6, otherwise: bb5]; + } + + bb5: { + StorageDead(_19); + StorageDead(_18); +- _7 = const (); + StorageDead(_17); + StorageDead(_16); + StorageDead(_15); + StorageDead(_13); + StorageDead(_10); + StorageDead(_8); +- StorageDead(_7); +- StorageLive(_29); + StorageLive(_30); + _30 = &(*_1); + _29 = move _30 as &[u8] (Transmute); + StorageDead(_30); + StorageLive(_31); +- StorageLive(_32); +- _32 = _29; +- _31 = opaque::<&[u8]>(move _32) -> [return: bb7, unwind continue]; ++ _31 = opaque::<&[u8]>(_29) -> [return: bb7, unwind continue]; + } + + bb6: { + StorageDead(_19); + StorageDead(_18); +- StorageLive(_21); + _21 = core::panicking::AssertKind::Eq; + StorageLive(_22); +- StorageLive(_23); +- _23 = move _21; + StorageLive(_24); + StorageLive(_25); + _25 = &(*_15); + _24 = &(*_25); + StorageLive(_26); + StorageLive(_27); + _27 = &(*_16); + _26 = &(*_27); + StorageLive(_28); + _28 = Option::>::None; +- _22 = core::panicking::assert_failed::<*const u8, *const u8>(move _23, move _24, move _26, move _28) -> unwind continue; ++ _22 = core::panicking::assert_failed::<*const u8, *const u8>(_21, move _24, move _26, move _28) -> unwind continue; + } + + bb7: { +- StorageDead(_32); + StorageDead(_31); +- StorageLive(_33); + StorageLive(_34); + StorageLive(_35); + StorageLive(_36); + StorageLive(_37); + _37 = &(*_1); + _36 = core::str::::as_ptr(move _37) -> [return: bb8, unwind continue]; + } + + bb8: { + StorageDead(_37); + _35 = &_36; + StorageLive(_38); + StorageLive(_39); + StorageLive(_40); + _40 = &(*_29); + _39 = core::slice::::as_ptr(move _40) -> [return: bb9, unwind continue]; + } + + bb9: { + StorageDead(_40); + _38 = &_39; + _34 = (move _35, move _38); + StorageDead(_38); + StorageDead(_35); + StorageLive(_41); + _41 = (_34.0: &*const u8); + StorageLive(_42); + _42 = (_34.1: &*const u8); + StorageLive(_43); + StorageLive(_44); + _44 = (*_41); + StorageLive(_45); + _45 = (*_42); + _43 = Eq(move _44, move _45); + switchInt(move _43) -> [0: bb11, otherwise: bb10]; + } + + bb10: { + StorageDead(_45); + StorageDead(_44); +- _33 = const (); + StorageDead(_43); + StorageDead(_42); + StorageDead(_41); + StorageDead(_39); + StorageDead(_36); + StorageDead(_34); +- StorageDead(_33); + _0 = const (); +- StorageDead(_29); + StorageDead(_4); +- StorageDead(_1); + return; + } + + bb11: { + StorageDead(_45); + StorageDead(_44); +- StorageLive(_47); + _47 = core::panicking::AssertKind::Eq; + StorageLive(_48); +- StorageLive(_49); +- _49 = move _47; + StorageLive(_50); + StorageLive(_51); + _51 = &(*_41); + _50 = &(*_51); + StorageLive(_52); + StorageLive(_53); + _53 = &(*_42); + _52 = &(*_53); + StorageLive(_54); + _54 = Option::>::None; +- _48 = core::panicking::assert_failed::<*const u8, *const u8>(move _49, move _50, move _52, move _54) -> unwind continue; ++ _48 = core::panicking::assert_failed::<*const u8, *const u8>(_47, move _50, move _52, move _54) -> unwind continue; + } + } + diff --git a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff new file mode 100644 index 0000000000000..bf866e2f4d22f --- /dev/null +++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff @@ -0,0 +1,883 @@ +- // MIR for `subexpression_elimination` before GVN ++ // MIR for `subexpression_elimination` after GVN + + fn subexpression_elimination(_1: u64, _2: u64, _3: u64) -> () { + debug x => _1; + debug y => _2; + debug z => _3; + let mut _0: (); + let _4: (); + let mut _5: u64; + let mut _6: u64; + let mut _7: u64; + let _8: (); + let mut _9: u64; + let mut _10: u64; + let mut _11: u64; + let _12: (); + let mut _13: u64; + let mut _14: u64; + let mut _15: u64; + let _16: (); + let mut _17: u64; + let mut _18: u64; + let mut _19: u64; + let mut _20: bool; + let _21: (); + let mut _22: u64; + let mut _23: u64; + let mut _24: u64; + let mut _25: bool; + let _26: (); + let mut _27: u64; + let mut _28: u64; + let mut _29: u64; + let _30: (); + let mut _31: u64; + let mut _32: u64; + let mut _33: u64; + let _34: (); + let mut _35: u64; + let mut _36: u64; + let mut _37: u64; + let _38: (); + let mut _39: u64; + let mut _40: u64; + let mut _41: u64; + let _42: (); + let mut _43: u64; + let mut _44: u64; + let mut _45: u64; + let _46: (); + let mut _47: u32; + let mut _48: u64; + let _49: (); + let mut _50: f32; + let mut _51: u64; + let _52: (); + let mut _53: S; + let mut _54: u64; + let _55: (); + let mut _56: u64; + let mut _57: S; + let mut _58: u64; + let _59: (); + let mut _60: u64; + let mut _61: u64; + let mut _62: u64; + let mut _63: u64; + let mut _64: u64; + let _65: (); + let mut _66: u64; + let mut _67: u64; + let mut _68: u64; + let mut _69: u64; + let mut _70: u64; + let _71: (); + let mut _72: u64; + let mut _73: u64; + let mut _74: u64; + let mut _75: u64; + let mut _76: u64; + let _77: (); + let mut _78: u64; + let mut _79: u64; + let mut _80: u64; + let mut _81: u64; + let mut _82: bool; + let mut _83: u64; + let _84: (); + let mut _85: u64; + let mut _86: u64; + let mut _87: u64; + let mut _88: u64; + let mut _89: bool; + let mut _90: u64; + let _91: (); + let mut _92: u64; + let mut _93: u64; + let mut _94: u64; + let mut _95: u64; + let mut _96: u64; + let _97: (); + let mut _98: u64; + let mut _99: u64; + let mut _100: u64; + let mut _101: u64; + let mut _102: u64; + let _103: (); + let mut _104: u64; + let mut _105: u64; + let mut _106: u64; + let mut _107: u64; + let mut _108: u64; + let _109: (); + let mut _110: u64; + let mut _111: u64; + let mut _112: u64; + let mut _113: u64; + let mut _114: u64; + let _115: (); + let mut _116: u64; + let mut _117: u64; + let mut _118: u64; + let mut _119: u64; + let mut _120: u64; + let _121: (); + let mut _122: S; + let mut _123: u64; + let _124: (); + let mut _125: u64; + let mut _126: S; + let mut _127: u64; + let _128: &u64; + let _129: (); + let mut _130: u64; + let mut _131: u64; + let mut _132: u64; + let _133: (); + let mut _134: u64; + let mut _135: u64; + let mut _136: u64; + let _138: (); + let mut _139: u64; + let mut _140: u64; + let mut _141: u64; + let _142: (); + let mut _143: u64; + let mut _144: u64; + let mut _145: u64; + let _146: (); + let _148: (); + let mut _149: u64; + let mut _150: u64; + let mut _151: u64; + let _152: (); + let mut _153: u64; + let mut _154: u64; + let mut _155: u64; + let _157: (); + let mut _158: u64; + let mut _159: u64; + let mut _160: u64; + let _161: (); + let mut _162: u64; + let mut _163: u64; + let mut _164: u64; + let _166: (); + let mut _167: u64; + let mut _168: u64; + let mut _169: u64; + let _170: (); + let mut _171: u64; + let mut _172: u64; + let mut _173: u64; + scope 1 { + debug a => _128; + let _137: &mut u64; + scope 2 { + debug b => _137; + let _165: &u64; + scope 3 { + let _147: *const u64; + scope 4 { + debug c => _147; + let _156: *mut u64; + scope 5 { + debug d => _156; + } + } + } + scope 6 { + debug e => _165; + } + } + } + + bb0: { + StorageLive(_4); +- StorageLive(_5); +- StorageLive(_6); +- _6 = _1; +- StorageLive(_7); +- _7 = _2; +- _5 = Add(move _6, move _7); +- StorageDead(_7); +- StorageDead(_6); +- _4 = opaque::(move _5) -> [return: bb1, unwind unreachable]; ++ _5 = Add(_1, _2); ++ _4 = opaque::(_5) -> [return: bb1, unwind unreachable]; + } + + bb1: { +- StorageDead(_5); + StorageDead(_4); + StorageLive(_8); +- StorageLive(_9); +- StorageLive(_10); +- _10 = _1; +- StorageLive(_11); +- _11 = _2; +- _9 = Mul(move _10, move _11); +- StorageDead(_11); +- StorageDead(_10); +- _8 = opaque::(move _9) -> [return: bb2, unwind unreachable]; ++ _9 = Mul(_1, _2); ++ _8 = opaque::(_9) -> [return: bb2, unwind unreachable]; + } + + bb2: { +- StorageDead(_9); + StorageDead(_8); + StorageLive(_12); +- StorageLive(_13); +- StorageLive(_14); +- _14 = _1; +- StorageLive(_15); +- _15 = _2; +- _13 = Sub(move _14, move _15); +- StorageDead(_15); +- StorageDead(_14); +- _12 = opaque::(move _13) -> [return: bb3, unwind unreachable]; ++ _13 = Sub(_1, _2); ++ _12 = opaque::(_13) -> [return: bb3, unwind unreachable]; + } + + bb3: { +- StorageDead(_13); + StorageDead(_12); + StorageLive(_16); +- StorageLive(_17); +- StorageLive(_18); +- _18 = _1; +- StorageLive(_19); +- _19 = _2; +- _20 = Eq(_19, const 0_u64); +- assert(!move _20, "attempt to divide `{}` by zero", _18) -> [success: bb4, unwind unreachable]; ++ _20 = Eq(_2, const 0_u64); ++ assert(!_20, "attempt to divide `{}` by zero", _1) -> [success: bb4, unwind unreachable]; + } + + bb4: { +- _17 = Div(move _18, move _19); +- StorageDead(_19); +- StorageDead(_18); +- _16 = opaque::(move _17) -> [return: bb5, unwind unreachable]; ++ _17 = Div(_1, _2); ++ _16 = opaque::(_17) -> [return: bb5, unwind unreachable]; + } + + bb5: { +- StorageDead(_17); + StorageDead(_16); + StorageLive(_21); +- StorageLive(_22); +- StorageLive(_23); +- _23 = _1; +- StorageLive(_24); +- _24 = _2; +- _25 = Eq(_24, const 0_u64); +- assert(!move _25, "attempt to calculate the remainder of `{}` with a divisor of zero", _23) -> [success: bb6, unwind unreachable]; ++ assert(!_20, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb6, unwind unreachable]; + } + + bb6: { +- _22 = Rem(move _23, move _24); +- StorageDead(_24); +- StorageDead(_23); +- _21 = opaque::(move _22) -> [return: bb7, unwind unreachable]; ++ _22 = Rem(_1, _2); ++ _21 = opaque::(_22) -> [return: bb7, unwind unreachable]; + } + + bb7: { +- StorageDead(_22); + StorageDead(_21); + StorageLive(_26); +- StorageLive(_27); +- StorageLive(_28); +- _28 = _1; +- StorageLive(_29); +- _29 = _2; +- _27 = BitAnd(move _28, move _29); +- StorageDead(_29); +- StorageDead(_28); +- _26 = opaque::(move _27) -> [return: bb8, unwind unreachable]; ++ _27 = BitAnd(_1, _2); ++ _26 = opaque::(_27) -> [return: bb8, unwind unreachable]; + } + + bb8: { +- StorageDead(_27); + StorageDead(_26); + StorageLive(_30); +- StorageLive(_31); +- StorageLive(_32); +- _32 = _1; +- StorageLive(_33); +- _33 = _2; +- _31 = BitOr(move _32, move _33); +- StorageDead(_33); +- StorageDead(_32); +- _30 = opaque::(move _31) -> [return: bb9, unwind unreachable]; ++ _31 = BitOr(_1, _2); ++ _30 = opaque::(_31) -> [return: bb9, unwind unreachable]; + } + + bb9: { +- StorageDead(_31); + StorageDead(_30); + StorageLive(_34); +- StorageLive(_35); +- StorageLive(_36); +- _36 = _1; +- StorageLive(_37); +- _37 = _2; +- _35 = BitXor(move _36, move _37); +- StorageDead(_37); +- StorageDead(_36); +- _34 = opaque::(move _35) -> [return: bb10, unwind unreachable]; ++ _35 = BitXor(_1, _2); ++ _34 = opaque::(_35) -> [return: bb10, unwind unreachable]; + } + + bb10: { +- StorageDead(_35); + StorageDead(_34); + StorageLive(_38); +- StorageLive(_39); +- StorageLive(_40); +- _40 = _1; +- StorageLive(_41); +- _41 = _2; +- _39 = Shl(move _40, move _41); +- StorageDead(_41); +- StorageDead(_40); +- _38 = opaque::(move _39) -> [return: bb11, unwind unreachable]; ++ _39 = Shl(_1, _2); ++ _38 = opaque::(_39) -> [return: bb11, unwind unreachable]; + } + + bb11: { +- StorageDead(_39); + StorageDead(_38); + StorageLive(_42); +- StorageLive(_43); +- StorageLive(_44); +- _44 = _1; +- StorageLive(_45); +- _45 = _2; +- _43 = Shr(move _44, move _45); +- StorageDead(_45); +- StorageDead(_44); +- _42 = opaque::(move _43) -> [return: bb12, unwind unreachable]; ++ _43 = Shr(_1, _2); ++ _42 = opaque::(_43) -> [return: bb12, unwind unreachable]; + } + + bb12: { +- StorageDead(_43); + StorageDead(_42); + StorageLive(_46); + StorageLive(_47); +- StorageLive(_48); +- _48 = _1; +- _47 = move _48 as u32 (IntToInt); +- StorageDead(_48); ++ _47 = _1 as u32 (IntToInt); + _46 = opaque::(move _47) -> [return: bb13, unwind unreachable]; + } + + bb13: { + StorageDead(_47); + StorageDead(_46); + StorageLive(_49); + StorageLive(_50); +- StorageLive(_51); +- _51 = _1; +- _50 = move _51 as f32 (IntToFloat); +- StorageDead(_51); ++ _50 = _1 as f32 (IntToFloat); + _49 = opaque::(move _50) -> [return: bb14, unwind unreachable]; + } + + bb14: { + StorageDead(_50); + StorageDead(_49); + StorageLive(_52); +- StorageLive(_53); +- StorageLive(_54); +- _54 = _1; +- _53 = S::(move _54); +- StorageDead(_54); +- _52 = opaque::>(move _53) -> [return: bb15, unwind unreachable]; ++ _53 = S::(_1); ++ _52 = opaque::>(_53) -> [return: bb15, unwind unreachable]; + } + + bb15: { +- StorageDead(_53); + StorageDead(_52); + StorageLive(_55); +- StorageLive(_56); +- StorageLive(_57); +- StorageLive(_58); +- _58 = _1; +- _57 = S::(move _58); +- StorageDead(_58); +- _56 = (_57.0: u64); +- _55 = opaque::(move _56) -> [return: bb16, unwind unreachable]; ++ _56 = (_53.0: u64); ++ _55 = opaque::(_56) -> [return: bb16, unwind unreachable]; + } + + bb16: { +- StorageDead(_56); +- StorageDead(_57); + StorageDead(_55); + StorageLive(_59); + StorageLive(_60); +- StorageLive(_61); +- StorageLive(_62); +- _62 = _1; +- StorageLive(_63); +- _63 = _2; +- _61 = Add(move _62, move _63); +- StorageDead(_63); +- StorageDead(_62); + StorageLive(_64); + _64 = _3; +- _60 = Add(move _61, move _64); ++ _60 = Add(_5, move _64); + StorageDead(_64); +- StorageDead(_61); + _59 = opaque::(move _60) -> [return: bb17, unwind unreachable]; + } + + bb17: { + StorageDead(_60); + StorageDead(_59); + StorageLive(_65); + StorageLive(_66); +- StorageLive(_67); +- StorageLive(_68); +- _68 = _1; +- StorageLive(_69); +- _69 = _2; +- _67 = Mul(move _68, move _69); +- StorageDead(_69); +- StorageDead(_68); + StorageLive(_70); + _70 = _3; +- _66 = Add(move _67, move _70); ++ _66 = Add(_9, move _70); + StorageDead(_70); +- StorageDead(_67); + _65 = opaque::(move _66) -> [return: bb18, unwind unreachable]; + } + + bb18: { + StorageDead(_66); + StorageDead(_65); + StorageLive(_71); + StorageLive(_72); +- StorageLive(_73); +- StorageLive(_74); +- _74 = _1; +- StorageLive(_75); +- _75 = _2; +- _73 = Sub(move _74, move _75); +- StorageDead(_75); +- StorageDead(_74); + StorageLive(_76); + _76 = _3; +- _72 = Add(move _73, move _76); ++ _72 = Add(_13, move _76); + StorageDead(_76); +- StorageDead(_73); + _71 = opaque::(move _72) -> [return: bb19, unwind unreachable]; + } + + bb19: { + StorageDead(_72); + StorageDead(_71); + StorageLive(_77); + StorageLive(_78); +- StorageLive(_79); +- StorageLive(_80); +- _80 = _1; +- StorageLive(_81); +- _81 = _2; +- _82 = Eq(_81, const 0_u64); +- assert(!move _82, "attempt to divide `{}` by zero", _80) -> [success: bb20, unwind unreachable]; ++ assert(!_20, "attempt to divide `{}` by zero", _1) -> [success: bb20, unwind unreachable]; + } + + bb20: { +- _79 = Div(move _80, move _81); +- StorageDead(_81); +- StorageDead(_80); + StorageLive(_83); + _83 = _3; +- _78 = Add(move _79, move _83); ++ _78 = Add(_17, move _83); + StorageDead(_83); +- StorageDead(_79); + _77 = opaque::(move _78) -> [return: bb21, unwind unreachable]; + } + + bb21: { + StorageDead(_78); + StorageDead(_77); + StorageLive(_84); + StorageLive(_85); +- StorageLive(_86); +- StorageLive(_87); +- _87 = _1; +- StorageLive(_88); +- _88 = _2; +- _89 = Eq(_88, const 0_u64); +- assert(!move _89, "attempt to calculate the remainder of `{}` with a divisor of zero", _87) -> [success: bb22, unwind unreachable]; ++ assert(!_20, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb22, unwind unreachable]; + } + + bb22: { +- _86 = Rem(move _87, move _88); +- StorageDead(_88); +- StorageDead(_87); + StorageLive(_90); + _90 = _3; +- _85 = Add(move _86, move _90); ++ _85 = Add(_22, move _90); + StorageDead(_90); +- StorageDead(_86); + _84 = opaque::(move _85) -> [return: bb23, unwind unreachable]; + } + + bb23: { + StorageDead(_85); + StorageDead(_84); + StorageLive(_91); + StorageLive(_92); +- StorageLive(_93); +- StorageLive(_94); +- _94 = _1; +- StorageLive(_95); +- _95 = _2; +- _93 = BitAnd(move _94, move _95); +- StorageDead(_95); +- StorageDead(_94); + StorageLive(_96); + _96 = _3; +- _92 = Add(move _93, move _96); ++ _92 = Add(_27, move _96); + StorageDead(_96); +- StorageDead(_93); + _91 = opaque::(move _92) -> [return: bb24, unwind unreachable]; + } + + bb24: { + StorageDead(_92); + StorageDead(_91); + StorageLive(_97); + StorageLive(_98); +- StorageLive(_99); +- StorageLive(_100); +- _100 = _1; +- StorageLive(_101); +- _101 = _2; +- _99 = BitOr(move _100, move _101); +- StorageDead(_101); +- StorageDead(_100); + StorageLive(_102); + _102 = _3; +- _98 = Add(move _99, move _102); ++ _98 = Add(_31, move _102); + StorageDead(_102); +- StorageDead(_99); + _97 = opaque::(move _98) -> [return: bb25, unwind unreachable]; + } + + bb25: { + StorageDead(_98); + StorageDead(_97); + StorageLive(_103); + StorageLive(_104); +- StorageLive(_105); +- StorageLive(_106); +- _106 = _1; +- StorageLive(_107); +- _107 = _2; +- _105 = BitXor(move _106, move _107); +- StorageDead(_107); +- StorageDead(_106); + StorageLive(_108); + _108 = _3; +- _104 = Add(move _105, move _108); ++ _104 = Add(_35, move _108); + StorageDead(_108); +- StorageDead(_105); + _103 = opaque::(move _104) -> [return: bb26, unwind unreachable]; + } + + bb26: { + StorageDead(_104); + StorageDead(_103); + StorageLive(_109); + StorageLive(_110); +- StorageLive(_111); +- StorageLive(_112); +- _112 = _1; +- StorageLive(_113); +- _113 = _2; +- _111 = Shl(move _112, move _113); +- StorageDead(_113); +- StorageDead(_112); + StorageLive(_114); + _114 = _3; +- _110 = Add(move _111, move _114); ++ _110 = Add(_39, move _114); + StorageDead(_114); +- StorageDead(_111); + _109 = opaque::(move _110) -> [return: bb27, unwind unreachable]; + } + + bb27: { + StorageDead(_110); + StorageDead(_109); + StorageLive(_115); + StorageLive(_116); +- StorageLive(_117); +- StorageLive(_118); +- _118 = _1; +- StorageLive(_119); +- _119 = _2; +- _117 = Shr(move _118, move _119); +- StorageDead(_119); +- StorageDead(_118); + StorageLive(_120); + _120 = _3; +- _116 = Add(move _117, move _120); ++ _116 = Add(_43, move _120); + StorageDead(_120); +- StorageDead(_117); + _115 = opaque::(move _116) -> [return: bb28, unwind unreachable]; + } + + bb28: { + StorageDead(_116); + StorageDead(_115); + StorageLive(_121); +- StorageLive(_122); +- StorageLive(_123); +- _123 = _1; +- _122 = S::(move _123); +- StorageDead(_123); +- _121 = opaque::>(move _122) -> [return: bb29, unwind unreachable]; ++ _121 = opaque::>(_53) -> [return: bb29, unwind unreachable]; + } + + bb29: { +- StorageDead(_122); + StorageDead(_121); + StorageLive(_124); +- StorageLive(_125); +- StorageLive(_126); +- StorageLive(_127); +- _127 = _1; +- _126 = S::(move _127); +- StorageDead(_127); +- _125 = (_126.0: u64); +- _124 = opaque::(move _125) -> [return: bb30, unwind unreachable]; ++ _124 = opaque::(_56) -> [return: bb30, unwind unreachable]; + } + + bb30: { +- StorageDead(_125); +- StorageDead(_126); + StorageDead(_124); + StorageLive(_128); + _128 = &_3; + StorageLive(_129); +- StorageLive(_130); +- StorageLive(_131); + _131 = (*_128); +- StorageLive(_132); +- _132 = _1; +- _130 = Add(move _131, move _132); +- StorageDead(_132); +- StorageDead(_131); +- _129 = opaque::(move _130) -> [return: bb31, unwind unreachable]; ++ _130 = Add(_131, _1); ++ _129 = opaque::(_130) -> [return: bb31, unwind unreachable]; + } + + bb31: { +- StorageDead(_130); + StorageDead(_129); + StorageLive(_133); +- StorageLive(_134); +- StorageLive(_135); +- _135 = (*_128); +- StorageLive(_136); +- _136 = _1; +- _134 = Add(move _135, move _136); +- StorageDead(_136); +- StorageDead(_135); +- _133 = opaque::(move _134) -> [return: bb32, unwind unreachable]; ++ _133 = opaque::(_130) -> [return: bb32, unwind unreachable]; + } + + bb32: { +- StorageDead(_134); + StorageDead(_133); + StorageLive(_137); + _137 = &mut _3; + StorageLive(_138); + StorageLive(_139); + StorageLive(_140); + _140 = (*_137); +- StorageLive(_141); +- _141 = _1; +- _139 = Add(move _140, move _141); +- StorageDead(_141); ++ _139 = Add(move _140, _1); + StorageDead(_140); + _138 = opaque::(move _139) -> [return: bb33, unwind unreachable]; + } + + bb33: { + StorageDead(_139); + StorageDead(_138); + StorageLive(_142); + StorageLive(_143); + StorageLive(_144); + _144 = (*_137); +- StorageLive(_145); +- _145 = _1; +- _143 = Add(move _144, move _145); +- StorageDead(_145); ++ _143 = Add(move _144, _1); + StorageDead(_144); + _142 = opaque::(move _143) -> [return: bb34, unwind unreachable]; + } + + bb34: { + StorageDead(_143); + StorageDead(_142); +- StorageLive(_146); + StorageLive(_147); + _147 = &raw const _3; + StorageLive(_148); + StorageLive(_149); + StorageLive(_150); + _150 = (*_147); +- StorageLive(_151); +- _151 = _1; +- _149 = Add(move _150, move _151); +- StorageDead(_151); ++ _149 = Add(move _150, _1); + StorageDead(_150); + _148 = opaque::(move _149) -> [return: bb35, unwind unreachable]; + } + + bb35: { + StorageDead(_149); + StorageDead(_148); + StorageLive(_152); + StorageLive(_153); + StorageLive(_154); + _154 = (*_147); +- StorageLive(_155); +- _155 = _1; +- _153 = Add(move _154, move _155); +- StorageDead(_155); ++ _153 = Add(move _154, _1); + StorageDead(_154); + _152 = opaque::(move _153) -> [return: bb36, unwind unreachable]; + } + + bb36: { + StorageDead(_153); + StorageDead(_152); + StorageLive(_156); + _156 = &raw mut _3; + StorageLive(_157); + StorageLive(_158); + StorageLive(_159); + _159 = (*_156); +- StorageLive(_160); +- _160 = _1; +- _158 = Add(move _159, move _160); +- StorageDead(_160); ++ _158 = Add(move _159, _1); + StorageDead(_159); + _157 = opaque::(move _158) -> [return: bb37, unwind unreachable]; + } + + bb37: { + StorageDead(_158); + StorageDead(_157); + StorageLive(_161); + StorageLive(_162); + StorageLive(_163); + _163 = (*_156); +- StorageLive(_164); +- _164 = _1; +- _162 = Add(move _163, move _164); +- StorageDead(_164); ++ _162 = Add(move _163, _1); + StorageDead(_163); + _161 = opaque::(move _162) -> [return: bb38, unwind unreachable]; + } + + bb38: { + StorageDead(_162); + StorageDead(_161); +- _146 = const (); + StorageDead(_156); + StorageDead(_147); +- StorageDead(_146); + StorageLive(_165); + _165 = &_3; + StorageLive(_166); +- StorageLive(_167); +- StorageLive(_168); + _168 = (*_165); +- StorageLive(_169); +- _169 = _1; +- _167 = Add(move _168, move _169); +- StorageDead(_169); +- StorageDead(_168); +- _166 = opaque::(move _167) -> [return: bb39, unwind unreachable]; ++ _167 = Add(_168, _1); ++ _166 = opaque::(_167) -> [return: bb39, unwind unreachable]; + } + + bb39: { +- StorageDead(_167); + StorageDead(_166); + StorageLive(_170); +- StorageLive(_171); +- StorageLive(_172); +- _172 = (*_165); +- StorageLive(_173); +- _173 = _1; +- _171 = Add(move _172, move _173); +- StorageDead(_173); +- StorageDead(_172); +- _170 = opaque::(move _171) -> [return: bb40, unwind unreachable]; ++ _170 = opaque::(_167) -> [return: bb40, unwind unreachable]; + } + + bb40: { +- StorageDead(_171); + StorageDead(_170); + _0 = const (); + StorageDead(_165); + StorageDead(_137); + StorageDead(_128); + return; + } + } + diff --git a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..68b052907192d --- /dev/null +++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff @@ -0,0 +1,883 @@ +- // MIR for `subexpression_elimination` before GVN ++ // MIR for `subexpression_elimination` after GVN + + fn subexpression_elimination(_1: u64, _2: u64, _3: u64) -> () { + debug x => _1; + debug y => _2; + debug z => _3; + let mut _0: (); + let _4: (); + let mut _5: u64; + let mut _6: u64; + let mut _7: u64; + let _8: (); + let mut _9: u64; + let mut _10: u64; + let mut _11: u64; + let _12: (); + let mut _13: u64; + let mut _14: u64; + let mut _15: u64; + let _16: (); + let mut _17: u64; + let mut _18: u64; + let mut _19: u64; + let mut _20: bool; + let _21: (); + let mut _22: u64; + let mut _23: u64; + let mut _24: u64; + let mut _25: bool; + let _26: (); + let mut _27: u64; + let mut _28: u64; + let mut _29: u64; + let _30: (); + let mut _31: u64; + let mut _32: u64; + let mut _33: u64; + let _34: (); + let mut _35: u64; + let mut _36: u64; + let mut _37: u64; + let _38: (); + let mut _39: u64; + let mut _40: u64; + let mut _41: u64; + let _42: (); + let mut _43: u64; + let mut _44: u64; + let mut _45: u64; + let _46: (); + let mut _47: u32; + let mut _48: u64; + let _49: (); + let mut _50: f32; + let mut _51: u64; + let _52: (); + let mut _53: S; + let mut _54: u64; + let _55: (); + let mut _56: u64; + let mut _57: S; + let mut _58: u64; + let _59: (); + let mut _60: u64; + let mut _61: u64; + let mut _62: u64; + let mut _63: u64; + let mut _64: u64; + let _65: (); + let mut _66: u64; + let mut _67: u64; + let mut _68: u64; + let mut _69: u64; + let mut _70: u64; + let _71: (); + let mut _72: u64; + let mut _73: u64; + let mut _74: u64; + let mut _75: u64; + let mut _76: u64; + let _77: (); + let mut _78: u64; + let mut _79: u64; + let mut _80: u64; + let mut _81: u64; + let mut _82: bool; + let mut _83: u64; + let _84: (); + let mut _85: u64; + let mut _86: u64; + let mut _87: u64; + let mut _88: u64; + let mut _89: bool; + let mut _90: u64; + let _91: (); + let mut _92: u64; + let mut _93: u64; + let mut _94: u64; + let mut _95: u64; + let mut _96: u64; + let _97: (); + let mut _98: u64; + let mut _99: u64; + let mut _100: u64; + let mut _101: u64; + let mut _102: u64; + let _103: (); + let mut _104: u64; + let mut _105: u64; + let mut _106: u64; + let mut _107: u64; + let mut _108: u64; + let _109: (); + let mut _110: u64; + let mut _111: u64; + let mut _112: u64; + let mut _113: u64; + let mut _114: u64; + let _115: (); + let mut _116: u64; + let mut _117: u64; + let mut _118: u64; + let mut _119: u64; + let mut _120: u64; + let _121: (); + let mut _122: S; + let mut _123: u64; + let _124: (); + let mut _125: u64; + let mut _126: S; + let mut _127: u64; + let _128: &u64; + let _129: (); + let mut _130: u64; + let mut _131: u64; + let mut _132: u64; + let _133: (); + let mut _134: u64; + let mut _135: u64; + let mut _136: u64; + let _138: (); + let mut _139: u64; + let mut _140: u64; + let mut _141: u64; + let _142: (); + let mut _143: u64; + let mut _144: u64; + let mut _145: u64; + let _146: (); + let _148: (); + let mut _149: u64; + let mut _150: u64; + let mut _151: u64; + let _152: (); + let mut _153: u64; + let mut _154: u64; + let mut _155: u64; + let _157: (); + let mut _158: u64; + let mut _159: u64; + let mut _160: u64; + let _161: (); + let mut _162: u64; + let mut _163: u64; + let mut _164: u64; + let _166: (); + let mut _167: u64; + let mut _168: u64; + let mut _169: u64; + let _170: (); + let mut _171: u64; + let mut _172: u64; + let mut _173: u64; + scope 1 { + debug a => _128; + let _137: &mut u64; + scope 2 { + debug b => _137; + let _165: &u64; + scope 3 { + let _147: *const u64; + scope 4 { + debug c => _147; + let _156: *mut u64; + scope 5 { + debug d => _156; + } + } + } + scope 6 { + debug e => _165; + } + } + } + + bb0: { + StorageLive(_4); +- StorageLive(_5); +- StorageLive(_6); +- _6 = _1; +- StorageLive(_7); +- _7 = _2; +- _5 = Add(move _6, move _7); +- StorageDead(_7); +- StorageDead(_6); +- _4 = opaque::(move _5) -> [return: bb1, unwind continue]; ++ _5 = Add(_1, _2); ++ _4 = opaque::(_5) -> [return: bb1, unwind continue]; + } + + bb1: { +- StorageDead(_5); + StorageDead(_4); + StorageLive(_8); +- StorageLive(_9); +- StorageLive(_10); +- _10 = _1; +- StorageLive(_11); +- _11 = _2; +- _9 = Mul(move _10, move _11); +- StorageDead(_11); +- StorageDead(_10); +- _8 = opaque::(move _9) -> [return: bb2, unwind continue]; ++ _9 = Mul(_1, _2); ++ _8 = opaque::(_9) -> [return: bb2, unwind continue]; + } + + bb2: { +- StorageDead(_9); + StorageDead(_8); + StorageLive(_12); +- StorageLive(_13); +- StorageLive(_14); +- _14 = _1; +- StorageLive(_15); +- _15 = _2; +- _13 = Sub(move _14, move _15); +- StorageDead(_15); +- StorageDead(_14); +- _12 = opaque::(move _13) -> [return: bb3, unwind continue]; ++ _13 = Sub(_1, _2); ++ _12 = opaque::(_13) -> [return: bb3, unwind continue]; + } + + bb3: { +- StorageDead(_13); + StorageDead(_12); + StorageLive(_16); +- StorageLive(_17); +- StorageLive(_18); +- _18 = _1; +- StorageLive(_19); +- _19 = _2; +- _20 = Eq(_19, const 0_u64); +- assert(!move _20, "attempt to divide `{}` by zero", _18) -> [success: bb4, unwind continue]; ++ _20 = Eq(_2, const 0_u64); ++ assert(!_20, "attempt to divide `{}` by zero", _1) -> [success: bb4, unwind continue]; + } + + bb4: { +- _17 = Div(move _18, move _19); +- StorageDead(_19); +- StorageDead(_18); +- _16 = opaque::(move _17) -> [return: bb5, unwind continue]; ++ _17 = Div(_1, _2); ++ _16 = opaque::(_17) -> [return: bb5, unwind continue]; + } + + bb5: { +- StorageDead(_17); + StorageDead(_16); + StorageLive(_21); +- StorageLive(_22); +- StorageLive(_23); +- _23 = _1; +- StorageLive(_24); +- _24 = _2; +- _25 = Eq(_24, const 0_u64); +- assert(!move _25, "attempt to calculate the remainder of `{}` with a divisor of zero", _23) -> [success: bb6, unwind continue]; ++ assert(!_20, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb6, unwind continue]; + } + + bb6: { +- _22 = Rem(move _23, move _24); +- StorageDead(_24); +- StorageDead(_23); +- _21 = opaque::(move _22) -> [return: bb7, unwind continue]; ++ _22 = Rem(_1, _2); ++ _21 = opaque::(_22) -> [return: bb7, unwind continue]; + } + + bb7: { +- StorageDead(_22); + StorageDead(_21); + StorageLive(_26); +- StorageLive(_27); +- StorageLive(_28); +- _28 = _1; +- StorageLive(_29); +- _29 = _2; +- _27 = BitAnd(move _28, move _29); +- StorageDead(_29); +- StorageDead(_28); +- _26 = opaque::(move _27) -> [return: bb8, unwind continue]; ++ _27 = BitAnd(_1, _2); ++ _26 = opaque::(_27) -> [return: bb8, unwind continue]; + } + + bb8: { +- StorageDead(_27); + StorageDead(_26); + StorageLive(_30); +- StorageLive(_31); +- StorageLive(_32); +- _32 = _1; +- StorageLive(_33); +- _33 = _2; +- _31 = BitOr(move _32, move _33); +- StorageDead(_33); +- StorageDead(_32); +- _30 = opaque::(move _31) -> [return: bb9, unwind continue]; ++ _31 = BitOr(_1, _2); ++ _30 = opaque::(_31) -> [return: bb9, unwind continue]; + } + + bb9: { +- StorageDead(_31); + StorageDead(_30); + StorageLive(_34); +- StorageLive(_35); +- StorageLive(_36); +- _36 = _1; +- StorageLive(_37); +- _37 = _2; +- _35 = BitXor(move _36, move _37); +- StorageDead(_37); +- StorageDead(_36); +- _34 = opaque::(move _35) -> [return: bb10, unwind continue]; ++ _35 = BitXor(_1, _2); ++ _34 = opaque::(_35) -> [return: bb10, unwind continue]; + } + + bb10: { +- StorageDead(_35); + StorageDead(_34); + StorageLive(_38); +- StorageLive(_39); +- StorageLive(_40); +- _40 = _1; +- StorageLive(_41); +- _41 = _2; +- _39 = Shl(move _40, move _41); +- StorageDead(_41); +- StorageDead(_40); +- _38 = opaque::(move _39) -> [return: bb11, unwind continue]; ++ _39 = Shl(_1, _2); ++ _38 = opaque::(_39) -> [return: bb11, unwind continue]; + } + + bb11: { +- StorageDead(_39); + StorageDead(_38); + StorageLive(_42); +- StorageLive(_43); +- StorageLive(_44); +- _44 = _1; +- StorageLive(_45); +- _45 = _2; +- _43 = Shr(move _44, move _45); +- StorageDead(_45); +- StorageDead(_44); +- _42 = opaque::(move _43) -> [return: bb12, unwind continue]; ++ _43 = Shr(_1, _2); ++ _42 = opaque::(_43) -> [return: bb12, unwind continue]; + } + + bb12: { +- StorageDead(_43); + StorageDead(_42); + StorageLive(_46); + StorageLive(_47); +- StorageLive(_48); +- _48 = _1; +- _47 = move _48 as u32 (IntToInt); +- StorageDead(_48); ++ _47 = _1 as u32 (IntToInt); + _46 = opaque::(move _47) -> [return: bb13, unwind continue]; + } + + bb13: { + StorageDead(_47); + StorageDead(_46); + StorageLive(_49); + StorageLive(_50); +- StorageLive(_51); +- _51 = _1; +- _50 = move _51 as f32 (IntToFloat); +- StorageDead(_51); ++ _50 = _1 as f32 (IntToFloat); + _49 = opaque::(move _50) -> [return: bb14, unwind continue]; + } + + bb14: { + StorageDead(_50); + StorageDead(_49); + StorageLive(_52); +- StorageLive(_53); +- StorageLive(_54); +- _54 = _1; +- _53 = S::(move _54); +- StorageDead(_54); +- _52 = opaque::>(move _53) -> [return: bb15, unwind continue]; ++ _53 = S::(_1); ++ _52 = opaque::>(_53) -> [return: bb15, unwind continue]; + } + + bb15: { +- StorageDead(_53); + StorageDead(_52); + StorageLive(_55); +- StorageLive(_56); +- StorageLive(_57); +- StorageLive(_58); +- _58 = _1; +- _57 = S::(move _58); +- StorageDead(_58); +- _56 = (_57.0: u64); +- _55 = opaque::(move _56) -> [return: bb16, unwind continue]; ++ _56 = (_53.0: u64); ++ _55 = opaque::(_56) -> [return: bb16, unwind continue]; + } + + bb16: { +- StorageDead(_56); +- StorageDead(_57); + StorageDead(_55); + StorageLive(_59); + StorageLive(_60); +- StorageLive(_61); +- StorageLive(_62); +- _62 = _1; +- StorageLive(_63); +- _63 = _2; +- _61 = Add(move _62, move _63); +- StorageDead(_63); +- StorageDead(_62); + StorageLive(_64); + _64 = _3; +- _60 = Add(move _61, move _64); ++ _60 = Add(_5, move _64); + StorageDead(_64); +- StorageDead(_61); + _59 = opaque::(move _60) -> [return: bb17, unwind continue]; + } + + bb17: { + StorageDead(_60); + StorageDead(_59); + StorageLive(_65); + StorageLive(_66); +- StorageLive(_67); +- StorageLive(_68); +- _68 = _1; +- StorageLive(_69); +- _69 = _2; +- _67 = Mul(move _68, move _69); +- StorageDead(_69); +- StorageDead(_68); + StorageLive(_70); + _70 = _3; +- _66 = Add(move _67, move _70); ++ _66 = Add(_9, move _70); + StorageDead(_70); +- StorageDead(_67); + _65 = opaque::(move _66) -> [return: bb18, unwind continue]; + } + + bb18: { + StorageDead(_66); + StorageDead(_65); + StorageLive(_71); + StorageLive(_72); +- StorageLive(_73); +- StorageLive(_74); +- _74 = _1; +- StorageLive(_75); +- _75 = _2; +- _73 = Sub(move _74, move _75); +- StorageDead(_75); +- StorageDead(_74); + StorageLive(_76); + _76 = _3; +- _72 = Add(move _73, move _76); ++ _72 = Add(_13, move _76); + StorageDead(_76); +- StorageDead(_73); + _71 = opaque::(move _72) -> [return: bb19, unwind continue]; + } + + bb19: { + StorageDead(_72); + StorageDead(_71); + StorageLive(_77); + StorageLive(_78); +- StorageLive(_79); +- StorageLive(_80); +- _80 = _1; +- StorageLive(_81); +- _81 = _2; +- _82 = Eq(_81, const 0_u64); +- assert(!move _82, "attempt to divide `{}` by zero", _80) -> [success: bb20, unwind continue]; ++ assert(!_20, "attempt to divide `{}` by zero", _1) -> [success: bb20, unwind continue]; + } + + bb20: { +- _79 = Div(move _80, move _81); +- StorageDead(_81); +- StorageDead(_80); + StorageLive(_83); + _83 = _3; +- _78 = Add(move _79, move _83); ++ _78 = Add(_17, move _83); + StorageDead(_83); +- StorageDead(_79); + _77 = opaque::(move _78) -> [return: bb21, unwind continue]; + } + + bb21: { + StorageDead(_78); + StorageDead(_77); + StorageLive(_84); + StorageLive(_85); +- StorageLive(_86); +- StorageLive(_87); +- _87 = _1; +- StorageLive(_88); +- _88 = _2; +- _89 = Eq(_88, const 0_u64); +- assert(!move _89, "attempt to calculate the remainder of `{}` with a divisor of zero", _87) -> [success: bb22, unwind continue]; ++ assert(!_20, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb22, unwind continue]; + } + + bb22: { +- _86 = Rem(move _87, move _88); +- StorageDead(_88); +- StorageDead(_87); + StorageLive(_90); + _90 = _3; +- _85 = Add(move _86, move _90); ++ _85 = Add(_22, move _90); + StorageDead(_90); +- StorageDead(_86); + _84 = opaque::(move _85) -> [return: bb23, unwind continue]; + } + + bb23: { + StorageDead(_85); + StorageDead(_84); + StorageLive(_91); + StorageLive(_92); +- StorageLive(_93); +- StorageLive(_94); +- _94 = _1; +- StorageLive(_95); +- _95 = _2; +- _93 = BitAnd(move _94, move _95); +- StorageDead(_95); +- StorageDead(_94); + StorageLive(_96); + _96 = _3; +- _92 = Add(move _93, move _96); ++ _92 = Add(_27, move _96); + StorageDead(_96); +- StorageDead(_93); + _91 = opaque::(move _92) -> [return: bb24, unwind continue]; + } + + bb24: { + StorageDead(_92); + StorageDead(_91); + StorageLive(_97); + StorageLive(_98); +- StorageLive(_99); +- StorageLive(_100); +- _100 = _1; +- StorageLive(_101); +- _101 = _2; +- _99 = BitOr(move _100, move _101); +- StorageDead(_101); +- StorageDead(_100); + StorageLive(_102); + _102 = _3; +- _98 = Add(move _99, move _102); ++ _98 = Add(_31, move _102); + StorageDead(_102); +- StorageDead(_99); + _97 = opaque::(move _98) -> [return: bb25, unwind continue]; + } + + bb25: { + StorageDead(_98); + StorageDead(_97); + StorageLive(_103); + StorageLive(_104); +- StorageLive(_105); +- StorageLive(_106); +- _106 = _1; +- StorageLive(_107); +- _107 = _2; +- _105 = BitXor(move _106, move _107); +- StorageDead(_107); +- StorageDead(_106); + StorageLive(_108); + _108 = _3; +- _104 = Add(move _105, move _108); ++ _104 = Add(_35, move _108); + StorageDead(_108); +- StorageDead(_105); + _103 = opaque::(move _104) -> [return: bb26, unwind continue]; + } + + bb26: { + StorageDead(_104); + StorageDead(_103); + StorageLive(_109); + StorageLive(_110); +- StorageLive(_111); +- StorageLive(_112); +- _112 = _1; +- StorageLive(_113); +- _113 = _2; +- _111 = Shl(move _112, move _113); +- StorageDead(_113); +- StorageDead(_112); + StorageLive(_114); + _114 = _3; +- _110 = Add(move _111, move _114); ++ _110 = Add(_39, move _114); + StorageDead(_114); +- StorageDead(_111); + _109 = opaque::(move _110) -> [return: bb27, unwind continue]; + } + + bb27: { + StorageDead(_110); + StorageDead(_109); + StorageLive(_115); + StorageLive(_116); +- StorageLive(_117); +- StorageLive(_118); +- _118 = _1; +- StorageLive(_119); +- _119 = _2; +- _117 = Shr(move _118, move _119); +- StorageDead(_119); +- StorageDead(_118); + StorageLive(_120); + _120 = _3; +- _116 = Add(move _117, move _120); ++ _116 = Add(_43, move _120); + StorageDead(_120); +- StorageDead(_117); + _115 = opaque::(move _116) -> [return: bb28, unwind continue]; + } + + bb28: { + StorageDead(_116); + StorageDead(_115); + StorageLive(_121); +- StorageLive(_122); +- StorageLive(_123); +- _123 = _1; +- _122 = S::(move _123); +- StorageDead(_123); +- _121 = opaque::>(move _122) -> [return: bb29, unwind continue]; ++ _121 = opaque::>(_53) -> [return: bb29, unwind continue]; + } + + bb29: { +- StorageDead(_122); + StorageDead(_121); + StorageLive(_124); +- StorageLive(_125); +- StorageLive(_126); +- StorageLive(_127); +- _127 = _1; +- _126 = S::(move _127); +- StorageDead(_127); +- _125 = (_126.0: u64); +- _124 = opaque::(move _125) -> [return: bb30, unwind continue]; ++ _124 = opaque::(_56) -> [return: bb30, unwind continue]; + } + + bb30: { +- StorageDead(_125); +- StorageDead(_126); + StorageDead(_124); + StorageLive(_128); + _128 = &_3; + StorageLive(_129); +- StorageLive(_130); +- StorageLive(_131); + _131 = (*_128); +- StorageLive(_132); +- _132 = _1; +- _130 = Add(move _131, move _132); +- StorageDead(_132); +- StorageDead(_131); +- _129 = opaque::(move _130) -> [return: bb31, unwind continue]; ++ _130 = Add(_131, _1); ++ _129 = opaque::(_130) -> [return: bb31, unwind continue]; + } + + bb31: { +- StorageDead(_130); + StorageDead(_129); + StorageLive(_133); +- StorageLive(_134); +- StorageLive(_135); +- _135 = (*_128); +- StorageLive(_136); +- _136 = _1; +- _134 = Add(move _135, move _136); +- StorageDead(_136); +- StorageDead(_135); +- _133 = opaque::(move _134) -> [return: bb32, unwind continue]; ++ _133 = opaque::(_130) -> [return: bb32, unwind continue]; + } + + bb32: { +- StorageDead(_134); + StorageDead(_133); + StorageLive(_137); + _137 = &mut _3; + StorageLive(_138); + StorageLive(_139); + StorageLive(_140); + _140 = (*_137); +- StorageLive(_141); +- _141 = _1; +- _139 = Add(move _140, move _141); +- StorageDead(_141); ++ _139 = Add(move _140, _1); + StorageDead(_140); + _138 = opaque::(move _139) -> [return: bb33, unwind continue]; + } + + bb33: { + StorageDead(_139); + StorageDead(_138); + StorageLive(_142); + StorageLive(_143); + StorageLive(_144); + _144 = (*_137); +- StorageLive(_145); +- _145 = _1; +- _143 = Add(move _144, move _145); +- StorageDead(_145); ++ _143 = Add(move _144, _1); + StorageDead(_144); + _142 = opaque::(move _143) -> [return: bb34, unwind continue]; + } + + bb34: { + StorageDead(_143); + StorageDead(_142); +- StorageLive(_146); + StorageLive(_147); + _147 = &raw const _3; + StorageLive(_148); + StorageLive(_149); + StorageLive(_150); + _150 = (*_147); +- StorageLive(_151); +- _151 = _1; +- _149 = Add(move _150, move _151); +- StorageDead(_151); ++ _149 = Add(move _150, _1); + StorageDead(_150); + _148 = opaque::(move _149) -> [return: bb35, unwind continue]; + } + + bb35: { + StorageDead(_149); + StorageDead(_148); + StorageLive(_152); + StorageLive(_153); + StorageLive(_154); + _154 = (*_147); +- StorageLive(_155); +- _155 = _1; +- _153 = Add(move _154, move _155); +- StorageDead(_155); ++ _153 = Add(move _154, _1); + StorageDead(_154); + _152 = opaque::(move _153) -> [return: bb36, unwind continue]; + } + + bb36: { + StorageDead(_153); + StorageDead(_152); + StorageLive(_156); + _156 = &raw mut _3; + StorageLive(_157); + StorageLive(_158); + StorageLive(_159); + _159 = (*_156); +- StorageLive(_160); +- _160 = _1; +- _158 = Add(move _159, move _160); +- StorageDead(_160); ++ _158 = Add(move _159, _1); + StorageDead(_159); + _157 = opaque::(move _158) -> [return: bb37, unwind continue]; + } + + bb37: { + StorageDead(_158); + StorageDead(_157); + StorageLive(_161); + StorageLive(_162); + StorageLive(_163); + _163 = (*_156); +- StorageLive(_164); +- _164 = _1; +- _162 = Add(move _163, move _164); +- StorageDead(_164); ++ _162 = Add(move _163, _1); + StorageDead(_163); + _161 = opaque::(move _162) -> [return: bb38, unwind continue]; + } + + bb38: { + StorageDead(_162); + StorageDead(_161); +- _146 = const (); + StorageDead(_156); + StorageDead(_147); +- StorageDead(_146); + StorageLive(_165); + _165 = &_3; + StorageLive(_166); +- StorageLive(_167); +- StorageLive(_168); + _168 = (*_165); +- StorageLive(_169); +- _169 = _1; +- _167 = Add(move _168, move _169); +- StorageDead(_169); +- StorageDead(_168); +- _166 = opaque::(move _167) -> [return: bb39, unwind continue]; ++ _167 = Add(_168, _1); ++ _166 = opaque::(_167) -> [return: bb39, unwind continue]; + } + + bb39: { +- StorageDead(_167); + StorageDead(_166); + StorageLive(_170); +- StorageLive(_171); +- StorageLive(_172); +- _172 = (*_165); +- StorageLive(_173); +- _173 = _1; +- _171 = Add(move _172, move _173); +- StorageDead(_173); +- StorageDead(_172); +- _170 = opaque::(move _171) -> [return: bb40, unwind continue]; ++ _170 = opaque::(_167) -> [return: bb40, unwind continue]; + } + + bb40: { +- StorageDead(_171); + StorageDead(_170); + _0 = const (); + StorageDead(_165); + StorageDead(_137); + StorageDead(_128); + return; + } + } + diff --git a/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-abort.diff b/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-abort.diff new file mode 100644 index 0000000000000..f33845502ad94 --- /dev/null +++ b/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-abort.diff @@ -0,0 +1,45 @@ +- // MIR for `wrap_unwrap` before GVN ++ // MIR for `wrap_unwrap` after GVN + + fn wrap_unwrap(_1: T) -> T { + debug x => _1; + let mut _0: T; + let mut _2: std::option::Option; + let mut _3: T; + let mut _4: isize; + let _5: T; + let mut _6: !; + scope 1 { + debug y => _5; + } + + bb0: { + StorageLive(_2); +- StorageLive(_3); +- _3 = _1; +- _2 = Option::::Some(move _3); +- StorageDead(_3); ++ _2 = Option::::Some(_1); + _4 = discriminant(_2); + switchInt(move _4) -> [0: bb1, 1: bb3, otherwise: bb2]; + } + + bb1: { + StorageLive(_6); + _6 = begin_panic::<&str>(const "explicit panic") -> unwind unreachable; + } + + bb2: { + unreachable; + } + + bb3: { +- StorageLive(_5); + _5 = ((_2 as Some).0: T); + _0 = _5; +- StorageDead(_5); + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-unwind.diff b/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..edc05f99fe2f7 --- /dev/null +++ b/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-unwind.diff @@ -0,0 +1,45 @@ +- // MIR for `wrap_unwrap` before GVN ++ // MIR for `wrap_unwrap` after GVN + + fn wrap_unwrap(_1: T) -> T { + debug x => _1; + let mut _0: T; + let mut _2: std::option::Option; + let mut _3: T; + let mut _4: isize; + let _5: T; + let mut _6: !; + scope 1 { + debug y => _5; + } + + bb0: { + StorageLive(_2); +- StorageLive(_3); +- _3 = _1; +- _2 = Option::::Some(move _3); +- StorageDead(_3); ++ _2 = Option::::Some(_1); + _4 = discriminant(_2); + switchInt(move _4) -> [0: bb1, 1: bb3, otherwise: bb2]; + } + + bb1: { + StorageLive(_6); + _6 = begin_panic::<&str>(const "explicit panic") -> unwind continue; + } + + bb2: { + unreachable; + } + + bb3: { +- StorageLive(_5); + _5 = ((_2 as Some).0: T); + _0 = _5; +- StorageDead(_5); + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir b/tests/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir index 549306071addc..721fac27d8856 100644 --- a/tests/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir +++ b/tests/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir @@ -42,10 +42,10 @@ fn foo(_1: T, _2: i32) -> (i32, T) { StorageLive(_9); _9 = move (_7.0: i32); StorageLive(_11); - _10 = deref_copy ((*_6).0: &i32); + _10 = ((*_6).0: &i32); _11 = (*_10); StorageLive(_13); - _12 = deref_copy ((*_6).1: &T); + _12 = ((*_6).1: &T); _13 = (*_12); _0 = (move _11, move _13); StorageDead(_13); diff --git a/tests/mir-opt/inline/inline_generator.main.Inline.panic-abort.diff b/tests/mir-opt/inline/inline_generator.main.Inline.panic-abort.diff index 3f093a02dd2a3..6779003b6930e 100644 --- a/tests/mir-opt/inline/inline_generator.main.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/inline_generator.main.Inline.panic-abort.diff @@ -26,8 +26,6 @@ + let mut _6: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8}; + let mut _7: u32; + let mut _8: i32; -+ let mut _9: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8}; -+ let mut _10: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8}; + } bb0: { @@ -42,7 +40,7 @@ + StorageDead(_3); + StorageLive(_5); + _5 = const false; -+ _6 = deref_copy (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8}); ++ _6 = (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8}); + _7 = discriminant((*_6)); + switchInt(move _7) -> [0: bb3, 1: bb7, 3: bb8, otherwise: bb9]; } @@ -87,8 +85,7 @@ + + bb6: { + _1 = GeneratorState::::Yielded(move _8); -+ _9 = deref_copy (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8}); -+ discriminant((*_9)) = 3; ++ discriminant((*_6)) = 3; + goto -> bb1; + } + @@ -100,8 +97,7 @@ + StorageLive(_8); + StorageDead(_8); + _1 = GeneratorState::::Complete(_5); -+ _10 = deref_copy (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8}); -+ discriminant((*_10)) = 1; ++ discriminant((*_6)) = 1; + goto -> bb1; + } + diff --git a/tests/mir-opt/inline/inline_generator.main.Inline.panic-unwind.diff b/tests/mir-opt/inline/inline_generator.main.Inline.panic-unwind.diff index 3d76262c266f2..31744be99ec64 100644 --- a/tests/mir-opt/inline/inline_generator.main.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/inline_generator.main.Inline.panic-unwind.diff @@ -26,8 +26,6 @@ + let mut _6: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8}; + let mut _7: u32; + let mut _8: i32; -+ let mut _9: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8}; -+ let mut _10: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8}; + } bb0: { @@ -50,7 +48,7 @@ - _1 = <{generator@$DIR/inline_generator.rs:16:5: 16:8} as Generator>::resume(move _2, const false) -> [return: bb3, unwind: bb5]; + StorageLive(_5); + _5 = const false; -+ _6 = deref_copy (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8}); ++ _6 = (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8}); + _7 = discriminant((*_6)); + switchInt(move _7) -> [0: bb5, 1: bb9, 3: bb10, otherwise: bb11]; } @@ -99,8 +97,7 @@ + + bb8: { + _1 = GeneratorState::::Yielded(move _8); -+ _9 = deref_copy (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8}); -+ discriminant((*_9)) = 3; ++ discriminant((*_6)) = 3; + goto -> bb1; + } + @@ -112,8 +109,7 @@ + StorageLive(_8); + StorageDead(_8); + _1 = GeneratorState::::Complete(_5); -+ _10 = deref_copy (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8}); -+ discriminant((*_10)) = 1; ++ discriminant((*_6)) = 1; + goto -> bb1; + } +