From 55c2acf30e1e5bd2bfc132fab120d30e7c991273 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 20 Mar 2023 18:05:07 +0000 Subject: [PATCH 01/18] Add global value numbering pass. --- compiler/rustc_middle/src/mir/syntax.rs | 2 +- compiler/rustc_mir_transform/src/gvn.rs | 413 ++++++++ compiler/rustc_mir_transform/src/lib.rs | 2 + compiler/rustc_mir_transform/src/ref_prop.rs | 2 +- compiler/rustc_mir_transform/src/ssa.rs | 20 +- .../const_debuginfo.main.ConstDebugInfo.diff | 3 - .../gvn.arithmetic.GVN.panic-abort.diff | 342 +++++++ .../gvn.arithmetic.GVN.panic-unwind.diff | 342 +++++++ ...vn.arithmetic_checked.GVN.panic-abort.diff | 389 ++++++++ ...n.arithmetic_checked.GVN.panic-unwind.diff | 389 ++++++++ .../gvn.arithmetic_float.GVN.panic-abort.diff | 165 ++++ ...gvn.arithmetic_float.GVN.panic-unwind.diff | 165 ++++ tests/mir-opt/gvn.cast.GVN.panic-abort.diff | 501 ++++++++++ tests/mir-opt/gvn.cast.GVN.panic-unwind.diff | 501 ++++++++++ .../gvn.dereferences.GVN.panic-abort.diff | 191 ++++ .../gvn.dereferences.GVN.panic-unwind.diff | 191 ++++ ...gvn.multiple_branches.GVN.panic-abort.diff | 198 ++++ ...vn.multiple_branches.GVN.panic-unwind.diff | 198 ++++ .../gvn.references.GVN.panic-abort.diff | 105 +++ .../gvn.references.GVN.panic-unwind.diff | 113 +++ .../gvn.repeated_index.GVN.panic-abort.diff | 76 ++ .../gvn.repeated_index.GVN.panic-unwind.diff | 76 ++ tests/mir-opt/gvn.rs | 240 +++++ ...xpression_elimination.GVN.panic-abort.diff | 882 ++++++++++++++++++ ...pression_elimination.GVN.panic-unwind.diff | 882 ++++++++++++++++++ .../gvn.wrap_unwrap.GVN.panic-abort.diff | 45 + .../gvn.wrap_unwrap.GVN.panic-unwind.diff | 45 + ...ine_generator.main.Inline.panic-abort.diff | 8 +- ...ne_generator.main.Inline.panic-unwind.diff | 8 +- ...implifyComparisonIntegral.panic-abort.diff | 1 - ...mplifyComparisonIntegral.panic-unwind.diff | 1 - ...ondition-after-const-prop.panic-abort.diff | 3 - ...ndition-after-const-prop.panic-unwind.diff | 3 - 33 files changed, 6476 insertions(+), 26 deletions(-) create mode 100644 compiler/rustc_mir_transform/src/gvn.rs create mode 100644 tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff create mode 100644 tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff create mode 100644 tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff create mode 100644 tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff create mode 100644 tests/mir-opt/gvn.arithmetic_float.GVN.panic-abort.diff create mode 100644 tests/mir-opt/gvn.arithmetic_float.GVN.panic-unwind.diff create mode 100644 tests/mir-opt/gvn.cast.GVN.panic-abort.diff create mode 100644 tests/mir-opt/gvn.cast.GVN.panic-unwind.diff create mode 100644 tests/mir-opt/gvn.dereferences.GVN.panic-abort.diff create mode 100644 tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff create mode 100644 tests/mir-opt/gvn.multiple_branches.GVN.panic-abort.diff create mode 100644 tests/mir-opt/gvn.multiple_branches.GVN.panic-unwind.diff create mode 100644 tests/mir-opt/gvn.references.GVN.panic-abort.diff create mode 100644 tests/mir-opt/gvn.references.GVN.panic-unwind.diff create mode 100644 tests/mir-opt/gvn.repeated_index.GVN.panic-abort.diff create mode 100644 tests/mir-opt/gvn.repeated_index.GVN.panic-unwind.diff create mode 100644 tests/mir-opt/gvn.rs create mode 100644 tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff create mode 100644 tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff create mode 100644 tests/mir-opt/gvn.wrap_unwrap.GVN.panic-abort.diff create mode 100644 tests/mir-opt/gvn.wrap_unwrap.GVN.panic-unwind.diff 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..c8c7f3abf6af0 --- /dev/null +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -0,0 +1,413 @@ +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; + +/// Global value numbering. +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, &body.local_decls); + for arg in body.args_iter() { + if ssa.is_ssa(arg) { + let value = state.new_opaque().unwrap(); + state.assign(arg, value); + } + } + + for (local, rvalue, _) in ssa.assignments(body) { + let value = state.insert_rvalue(rvalue).or_else(|| state.new_opaque()).unwrap(); + state.assign(local, value); + } + + // Stop creating opaques during replacement as it is useless. + state.next_opaque = None; + + let mut any_replacement = false; + let mut replacer = Replacer { + tcx, + param_env, + ssa, + dominators, + state, + reused_locals: BitSet::new_empty(body.local_decls.len()), + any_replacement: &mut any_replacement, + }; + + 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]; + replacer.visit_basic_block_data(bb, data); + } + + StorageRemover { tcx, reused_locals: replacer.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, +} + +impl<'body, 'tcx> VnState<'body, 'tcx> { + fn new( + tcx: TyCtxt<'tcx>, + param_env: ty::ParamEnv<'tcx>, + 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), + } + } + + #[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) + } + + #[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)) + } + + #[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() + } + + #[instrument(level = "trace", skip(self))] + fn assign(&mut self, local: Local, value: VnIndex) { + self.locals[local] = Some(value); + self.rev_locals.entry(value).or_default().push(local); + } + + #[instrument(level = "trace", skip(self), ret)] + fn insert_place(&mut self, place: Place<'tcx>) -> Option { + let mut value = self.locals[place.local]?; + + for (index, proj) in place.projection.iter().enumerate() { + 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)); + } + + Some(value) + } + + #[instrument(level = "trace", skip(self), ret)] + fn insert_operand(&mut self, operand: &Operand<'tcx>) -> Option { + match *operand { + Operand::Constant(ref constant) => Some(self.insert(Value::Constant(constant.const_))), + Operand::Copy(place) | Operand::Move(place) => self.insert_place(place), + } + } + + #[instrument(level = "trace", skip(self), ret)] + fn insert_rvalue(&mut self, rvalue: &Rvalue<'tcx>) -> Option { + let value = match *rvalue { + // Forward values. + Rvalue::Use(ref operand) => return self.insert_operand(operand), + Rvalue::CopyForDeref(place) => return self.insert_operand(&Operand::Copy(place)), + + // Roots. + Rvalue::Repeat(ref op, amount) => { + let op = self.insert_operand(op)?; + Value::Repeat(op, amount) + } + Rvalue::NullaryOp(op, ty) => Value::NullaryOp(op, ty), + Rvalue::Aggregate(box ref kind, ref 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() + .map(|op| self.insert_operand(op).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(place) => { + let place = self.insert_place(place)?; + Value::Len(place) + } + Rvalue::Cast(kind, ref value, to) => { + let from = value.ty(self.local_decls, self.tcx); + let value = self.insert_operand(value)?; + Value::Cast { kind, value, from, to } + } + Rvalue::BinaryOp(op, box (ref lhs, ref rhs)) => { + let lhs = self.insert_operand(lhs)?; + let rhs = self.insert_operand(rhs)?; + Value::BinaryOp(op, lhs, rhs) + } + Rvalue::CheckedBinaryOp(op, box (ref lhs, ref rhs)) => { + let lhs = self.insert_operand(lhs)?; + let rhs = self.insert_operand(rhs)?; + Value::CheckedBinaryOp(op, lhs, rhs) + } + Rvalue::UnaryOp(op, ref arg) => { + let arg = self.insert_operand(arg)?; + Value::UnaryOp(op, arg) + } + Rvalue::Discriminant(place) => { + let place = self.insert_place(place)?; + Value::Discriminant(place) + } + + // Unsupported values. + Rvalue::ThreadLocalRef(..) | Rvalue::ShallowInitBox(..) => return None, + }; + debug!(?value); + Some(self.insert(value)) + } +} + +struct Replacer<'a, 'tcx> { + tcx: TyCtxt<'tcx>, + param_env: ty::ParamEnv<'tcx>, + ssa: SsaLocals, + dominators: Dominators, + state: VnState<'a, 'tcx>, + reused_locals: BitSet, + any_replacement: &'a mut bool, +} + +impl<'tcx> Replacer<'_, 'tcx> { + fn try_as_constant(&mut self, index: VnIndex) -> Option> { + if let Value::Constant(const_) = self.state.get(index) { + Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_: const_.clone() }) + } else { + None + } + } + + fn try_as_local(&mut self, index: VnIndex, loc: Location) -> Option { + let other = self.state.rev_locals.get(&index)?; + other + .iter() + .copied() + .find(|&other| self.ssa.assignment_dominates(&self.dominators, other, loc)) + } + + fn is_local_copiable(&self, local: Local) -> bool { + let ty = self.state.local_decls[local].ty; + // We only unify copy types as we only emit copies. + // We already simplify mutable reborrows as assignments, so we also allow copying those. + ty.is_ref() || ty.is_copy_modulo_regions(self.tcx, self.param_env) + } +} + +impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> { + fn tcx(&self) -> TyCtxt<'tcx> { + self.tcx + } + + fn visit_operand(&mut self, operand: &mut Operand<'tcx>, location: Location) { + if let Some(place) = operand.place() + && let Some(value) = self.state.insert_place(place) + { + if let Some(const_) = self.try_as_constant(value) { + *operand = Operand::Constant(Box::new(const_)); + *self.any_replacement = true; + } else if let Some(local) = self.try_as_local(value, location) + && *operand != Operand::Move(local.into()) + && self.is_local_copiable(local) + { + *operand = Operand::Copy(local.into()); + self.reused_locals.insert(local); + *self.any_replacement = true; + } + } + } + + 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 + && let Some(value) = self.state.insert_rvalue(rvalue) + { + 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())) + && self.is_local_copiable(local) + { + *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 d55b0cbe63574..fd6a41a70289a 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; @@ -551,6 +552,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..d16ef712a386b 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>, diff --git a/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff b/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff index ed47baa67daba..1e06c6fb49503 100644 --- a/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff +++ b/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff @@ -68,10 +68,7 @@ _2 = const 2_u8; _3 = const 3_u8; StorageLive(_4); - StorageLive(_5); - _5 = const 3_u8; _4 = const 6_u8; - StorageDead(_5); StorageLive(_9); _9 = const "hello, world!"; StorageLive(_14); 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..986052b2d41e5 --- /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..052b9d019f2e7 --- /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..33e4bdf5562a6 --- /dev/null +++ b/tests/mir-opt/gvn.rs @@ -0,0 +1,240 @@ +// 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)); //< This is not substituted as `S` is not `Copy`. + opaque(S(x).0); //< But this can be. + + // 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 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)); +} + +#[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 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..0034b6820f6e2 --- /dev/null +++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff @@ -0,0 +1,882 @@ +- // 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); ++ _53 = S::(_1); + _52 = opaque::>(move _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); ++ _57 = S::(_1); + _56 = (_57.0: u64); +- _55 = opaque::(move _56) -> [return: bb16, unwind unreachable]; ++ _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); ++ _122 = S::(_1); + _121 = opaque::>(move _122) -> [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..37bc2930a0dee --- /dev/null +++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff @@ -0,0 +1,882 @@ +- // 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); ++ _53 = S::(_1); + _52 = opaque::>(move _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); ++ _57 = S::(_1); + _56 = (_57.0: u64); +- _55 = opaque::(move _56) -> [return: bb16, unwind continue]; ++ _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); ++ _122 = S::(_1); + _121 = opaque::>(move _122) -> [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_generator.main.Inline.panic-abort.diff b/tests/mir-opt/inline/inline_generator.main.Inline.panic-abort.diff index d2c0591cc0ac8..2a59a77c45452 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: { @@ -82,8 +80,7 @@ + + bb5: { + _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; + } + @@ -95,8 +92,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 c024e3d7f7737..8982c31cd09bc 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: { @@ -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/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff index 9d8f272abea3a..277e3a05867ed 100644 --- a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff +++ b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff @@ -34,7 +34,6 @@ _2 = move _3 as &[T] (PointerCoercion(Unsize)); StorageDead(_3); _8 = const 3_usize; - _9 = const 3_usize; _10 = const true; goto -> bb2; } diff --git a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff index 738b0b1b3e5ac..327ce8f36bf7f 100644 --- a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff +++ b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff @@ -34,7 +34,6 @@ _2 = move _3 as &[T] (PointerCoercion(Unsize)); StorageDead(_3); _8 = const 3_usize; - _9 = const 3_usize; _10 = const true; goto -> bb2; } diff --git a/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-abort.diff b/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-abort.diff index d395715836064..e6536549db6eb 100644 --- a/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-abort.diff +++ b/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-abort.diff @@ -7,8 +7,6 @@ let _2: (); bb0: { - StorageLive(_1); - _1 = const false; - switchInt(const false) -> [0: bb3, otherwise: bb1]; + goto -> bb3; } @@ -26,7 +24,6 @@ } bb4: { - StorageDead(_1); return; } } diff --git a/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-unwind.diff b/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-unwind.diff index 81903c64dbd4b..54f9fe2e89c72 100644 --- a/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-unwind.diff +++ b/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-unwind.diff @@ -7,8 +7,6 @@ let _2: (); bb0: { - StorageLive(_1); - _1 = const false; - switchInt(const false) -> [0: bb3, otherwise: bb1]; + goto -> bb3; } @@ -26,7 +24,6 @@ } bb4: { - StorageDead(_1); return; } } From b14921a5ac048f2a4b3e5c4f6dee471e5d54999c Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 9 Apr 2023 11:15:48 +0000 Subject: [PATCH 02/18] Add documentation. --- compiler/rustc_mir_transform/src/gvn.rs | 44 ++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index c8c7f3abf6af0..ae3352732d979 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -1,3 +1,33 @@ +//! 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. +//! +//! # 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; @@ -11,7 +41,6 @@ use rustc_target::abi::{VariantIdx, FIRST_VARIANT}; use crate::ssa::SsaLocals; use crate::MirPass; -/// Global value numbering. pub struct GVN; impl<'tcx> MirPass<'tcx> for GVN { @@ -65,6 +94,9 @@ fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { replacer.visit_basic_block_data(bb, data); } + // 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: replacer.reused_locals }.visit_body_preserves_cfg(body); if any_replacement { @@ -154,6 +186,8 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { 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()?; @@ -162,6 +196,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { 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()?; @@ -174,12 +209,14 @@ impl<'body, 'tcx> VnState<'body, '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); self.rev_locals.entry(value).or_default().push(local); } + /// Represent the *value* which would be read from `place`. #[instrument(level = "trace", skip(self), ret)] fn insert_place(&mut self, place: Place<'tcx>) -> Option { let mut value = self.locals[place.local]?; @@ -308,11 +345,14 @@ struct Replacer<'a, 'tcx> { ssa: SsaLocals, dominators: Dominators, state: VnState<'a, 'tcx>, + /// Set of locals that are reused, and for which we should remove storage statements to avoid a + /// use-after-StorageDead. reused_locals: BitSet, any_replacement: &'a mut bool, } impl<'tcx> Replacer<'_, '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.state.get(index) { Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_: const_.clone() }) @@ -321,6 +361,8 @@ impl<'tcx> Replacer<'_, 'tcx> { } } + /// 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.state.rev_locals.get(&index)?; other From 1836de57ce3bcea5ca1850e8f8f31c4cd3e30841 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 1 May 2023 09:59:00 +0000 Subject: [PATCH 03/18] Do not check copiability. --- compiler/rustc_mir_transform/src/gvn.rs | 19 +++++++------------ tests/mir-opt/gvn.rs | 4 ++-- ...xpression_elimination.GVN.panic-abort.diff | 17 +++++++++-------- ...pression_elimination.GVN.panic-unwind.diff | 17 +++++++++-------- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index ae3352732d979..0695f9af75241 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -80,7 +80,6 @@ fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let mut any_replacement = false; let mut replacer = Replacer { tcx, - param_env, ssa, dominators, state, @@ -213,7 +212,13 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { #[instrument(level = "trace", skip(self))] fn assign(&mut self, local: Local, value: VnIndex) { self.locals[local] = Some(value); - self.rev_locals.entry(value).or_default().push(local); + + // 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`. @@ -341,7 +346,6 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { struct Replacer<'a, 'tcx> { tcx: TyCtxt<'tcx>, - param_env: ty::ParamEnv<'tcx>, ssa: SsaLocals, dominators: Dominators, state: VnState<'a, 'tcx>, @@ -370,13 +374,6 @@ impl<'tcx> Replacer<'_, 'tcx> { .copied() .find(|&other| self.ssa.assignment_dominates(&self.dominators, other, loc)) } - - fn is_local_copiable(&self, local: Local) -> bool { - let ty = self.state.local_decls[local].ty; - // We only unify copy types as we only emit copies. - // We already simplify mutable reborrows as assignments, so we also allow copying those. - ty.is_ref() || ty.is_copy_modulo_regions(self.tcx, self.param_env) - } } impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> { @@ -393,7 +390,6 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> { *self.any_replacement = true; } else if let Some(local) = self.try_as_local(value, location) && *operand != Operand::Move(local.into()) - && self.is_local_copiable(local) { *operand = Operand::Copy(local.into()); self.reused_locals.insert(local); @@ -412,7 +408,6 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> { *self.any_replacement = true; } else if let Some(local) = self.try_as_local(value, location) && *rvalue != Rvalue::Use(Operand::Move(local.into())) - && self.is_local_copiable(local) { *rvalue = Rvalue::Use(Operand::Copy(local.into())); self.reused_locals.insert(local); diff --git a/tests/mir-opt/gvn.rs b/tests/mir-opt/gvn.rs index 33e4bdf5562a6..f86854fe5e163 100644 --- a/tests/mir-opt/gvn.rs +++ b/tests/mir-opt/gvn.rs @@ -34,8 +34,8 @@ fn subexpression_elimination(x: u64, y: u64, mut z: u64) { opaque((x ^ y) + z); opaque((x << y) + z); opaque((x >> y) + z); - opaque(S(x)); //< This is not substituted as `S` is not `Copy`. - opaque(S(x).0); //< But this can be. + opaque(S(x)); + opaque(S(x).0); // We can substitute through an immutable reference too. let a = &z; diff --git a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff index 0034b6820f6e2..f44ab92f22945 100644 --- a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff @@ -405,17 +405,18 @@ StorageDead(_50); StorageDead(_49); StorageLive(_52); - StorageLive(_53); +- 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::>(move _53) -> [return: bb15, unwind unreachable]; ++ _52 = opaque::>(_53) -> [return: bb15, unwind unreachable]; } bb15: { - StorageDead(_53); +- StorageDead(_53); StorageDead(_52); StorageLive(_55); - StorageLive(_56); @@ -424,7 +425,7 @@ - _58 = _1; - _57 = S::(move _58); - StorageDead(_58); -+ _57 = S::(_1); ++ _57 = _53; _56 = (_57.0: u64); - _55 = opaque::(move _56) -> [return: bb16, unwind unreachable]; + _55 = opaque::(_56) -> [return: bb16, unwind unreachable]; @@ -667,17 +668,17 @@ StorageDead(_116); StorageDead(_115); StorageLive(_121); - StorageLive(_122); +- StorageLive(_122); - StorageLive(_123); - _123 = _1; - _122 = S::(move _123); - StorageDead(_123); -+ _122 = S::(_1); - _121 = opaque::>(move _122) -> [return: bb29, unwind unreachable]; +- _121 = opaque::>(move _122) -> [return: bb29, unwind unreachable]; ++ _121 = opaque::>(_53) -> [return: bb29, unwind unreachable]; } bb29: { - StorageDead(_122); +- StorageDead(_122); StorageDead(_121); StorageLive(_124); - StorageLive(_125); diff --git a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff index 37bc2930a0dee..a4da75bd680a9 100644 --- a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff @@ -405,17 +405,18 @@ StorageDead(_50); StorageDead(_49); StorageLive(_52); - StorageLive(_53); +- 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::>(move _53) -> [return: bb15, unwind continue]; ++ _52 = opaque::>(_53) -> [return: bb15, unwind continue]; } bb15: { - StorageDead(_53); +- StorageDead(_53); StorageDead(_52); StorageLive(_55); - StorageLive(_56); @@ -424,7 +425,7 @@ - _58 = _1; - _57 = S::(move _58); - StorageDead(_58); -+ _57 = S::(_1); ++ _57 = _53; _56 = (_57.0: u64); - _55 = opaque::(move _56) -> [return: bb16, unwind continue]; + _55 = opaque::(_56) -> [return: bb16, unwind continue]; @@ -667,17 +668,17 @@ StorageDead(_116); StorageDead(_115); StorageLive(_121); - StorageLive(_122); +- StorageLive(_122); - StorageLive(_123); - _123 = _1; - _122 = S::(move _123); - StorageDead(_123); -+ _122 = S::(_1); - _121 = opaque::>(move _122) -> [return: bb29, unwind continue]; +- _121 = opaque::>(move _122) -> [return: bb29, unwind continue]; ++ _121 = opaque::>(_53) -> [return: bb29, unwind continue]; } bb29: { - StorageDead(_122); +- StorageDead(_122); StorageDead(_121); StorageLive(_124); - StorageLive(_125); From 923016928adebb6336bbfb2501bbc20c2d982acc Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 13 May 2023 22:05:24 +0000 Subject: [PATCH 04/18] Add a paragraph about the assume bitwise equal. --- compiler/rustc_mir_transform/src/gvn.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 0695f9af75241..2b96763c29713 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -18,6 +18,31 @@ //! //! 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. From 4d6fe1fc7e39b69abd16320a91cdce4a96fd009a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 14 May 2023 13:27:07 +0000 Subject: [PATCH 05/18] Do not assume anything about repeated reification of generic functions. --- src/tools/miri/tests/pass/function_pointers.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tools/miri/tests/pass/function_pointers.rs b/src/tools/miri/tests/pass/function_pointers.rs index b66826e3fcdfb..593012ca45b78 100644 --- a/src/tools/miri/tests/pass/function_pointers.rs +++ b/src/tools/miri/tests/pass/function_pointers.rs @@ -75,7 +75,6 @@ fn main() { 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); // Any non-null value is okay for function pointers. unsafe { From a84faa28f21aeffe81131900c3b1041b8099bd2e Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 14 May 2023 20:31:02 +0000 Subject: [PATCH 06/18] Complete miri test. --- .../miri/tests/pass/function_pointers.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/tools/miri/tests/pass/function_pointers.rs b/src/tools/miri/tests/pass/function_pointers.rs index 593012ca45b78..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,9 +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); + // 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 { From b31ebb9a5e383c58a1e5dc43865a7243225ca0a9 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 1 Jul 2023 14:57:29 +0000 Subject: [PATCH 07/18] Workaround issue 112651. --- compiler/rustc_mir_transform/src/gvn.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 2b96763c29713..d4894d3c24dc9 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -96,7 +96,11 @@ fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { for (local, rvalue, _) in ssa.assignments(body) { let value = state.insert_rvalue(rvalue).or_else(|| state.new_opaque()).unwrap(); - state.assign(local, value); + // 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. From 81a4ad258ab5854c5b0e0c58d9089523f4fcb023 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 12 Apr 2023 18:39:56 +0000 Subject: [PATCH 08/18] Embed simplification into VnState. --- compiler/rustc_mir_transform/src/gvn.rs | 171 ++++++++++-------- compiler/rustc_mir_transform/src/ssa.rs | 18 ++ tests/mir-opt/gvn.cast.GVN.panic-abort.diff | 12 +- tests/mir-opt/gvn.cast.GVN.panic-unwind.diff | 12 +- ...xpression_elimination.GVN.panic-abort.diff | 8 +- ...pression_elimination.GVN.panic-unwind.diff | 8 +- ...line_closure_captures.foo.Inline.after.mir | 4 +- ...ine_generator.main.Inline.panic-abort.diff | 2 +- ...ne_generator.main.Inline.panic-unwind.diff | 2 +- 9 files changed, 136 insertions(+), 101 deletions(-) diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index d4894d3c24dc9..04584a732aa33 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -86,7 +86,7 @@ fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { // 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, &body.local_decls); + 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(); @@ -94,38 +94,29 @@ fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { } } - for (local, rvalue, _) in ssa.assignments(body) { - let value = state.insert_rvalue(rvalue).or_else(|| state.new_opaque()).unwrap(); + 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 mut any_replacement = false; - let mut replacer = Replacer { - tcx, - ssa, - dominators, - state, - reused_locals: BitSet::new_empty(body.local_decls.len()), - any_replacement: &mut any_replacement, - }; - 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]; - replacer.visit_basic_block_data(bb, data); + 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: replacer.reused_locals }.visit_body_preserves_cfg(body); + StorageRemover { tcx, reused_locals: state.reused_locals }.visit_body_preserves_cfg(body); if any_replacement { crate::simplify::remove_unused_definitions(body); @@ -189,12 +180,18 @@ struct VnState<'body, 'tcx> { /// 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 { @@ -205,6 +202,10 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { rev_locals: FxHashMap::default(), values: FxIndexSet::default(), next_opaque: Some(0), + ssa, + dominators, + reused_locals: BitSet::new_empty(local_decls.len()), + any_replacement: false, } } @@ -252,10 +253,16 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { /// Represent the *value* which would be read from `place`. #[instrument(level = "trace", skip(self), ret)] - fn insert_place(&mut self, place: Place<'tcx>) -> Option { + fn simplify_place(&mut self, place: &mut Place<'tcx>, location: Location) -> Option { + // Another place that holds the same value. + let mut place_ref = place.as_ref(); 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) { + place_ref = PlaceRef { local, projection: &place.projection[index..] }; + } + let proj = match proj { ProjectionElem::Deref => { let ty = Place::ty_from( @@ -293,31 +300,65 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { value = self.insert(Value::Projection(value, proj)); } + if let Some(local) = self.try_as_local(value, location) + && local != place.local + { + *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() + { + *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 insert_operand(&mut self, operand: &Operand<'tcx>) -> Option { + 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(place) | Operand::Move(place) => self.insert_place(place), + Operand::Copy(ref mut place) | Operand::Move(ref mut place) => { + let value = self.simplify_place(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 insert_rvalue(&mut self, rvalue: &Rvalue<'tcx>) -> Option { + fn simplify_rvalue( + &mut self, + rvalue: &mut Rvalue<'tcx>, + location: Location, + ) -> Option { let value = match *rvalue { // Forward values. - Rvalue::Use(ref operand) => return self.insert_operand(operand), - Rvalue::CopyForDeref(place) => return self.insert_operand(&Operand::Copy(place)), + 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 op, amount) => { - let op = self.insert_operand(op)?; + 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 fields) => { + Rvalue::Aggregate(box ref kind, ref mut fields) => { let variant_index = match *kind { AggregateKind::Array(..) | AggregateKind::Tuple @@ -328,8 +369,8 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { AggregateKind::Adt(_, _, _, _, Some(_)) => return None, }; let fields: Option> = fields - .iter() - .map(|op| self.insert_operand(op).or_else(|| self.new_opaque())) + .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?) @@ -337,31 +378,31 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { Rvalue::Ref(.., place) | Rvalue::AddressOf(_, place) => return self.new_pointer(place), // Operations. - Rvalue::Len(place) => { - let place = self.insert_place(place)?; + Rvalue::Len(ref mut place) => { + let place = self.simplify_place(place, location)?; Value::Len(place) } - Rvalue::Cast(kind, ref value, to) => { + Rvalue::Cast(kind, ref mut value, to) => { let from = value.ty(self.local_decls, self.tcx); - let value = self.insert_operand(value)?; + let value = self.simplify_operand(value, location)?; Value::Cast { kind, value, from, to } } - Rvalue::BinaryOp(op, box (ref lhs, ref rhs)) => { - let lhs = self.insert_operand(lhs)?; - let rhs = self.insert_operand(rhs)?; - Value::BinaryOp(op, lhs, rhs) + 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 lhs, ref rhs)) => { - let lhs = self.insert_operand(lhs)?; - let rhs = self.insert_operand(rhs)?; - Value::CheckedBinaryOp(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 arg) => { - let arg = self.insert_operand(arg)?; + Rvalue::UnaryOp(op, ref mut arg) => { + let arg = self.simplify_operand(arg, location)?; Value::UnaryOp(op, arg) } - Rvalue::Discriminant(place) => { - let place = self.insert_place(place)?; + Rvalue::Discriminant(ref mut place) => { + let place = self.simplify_place(place, location)?; Value::Discriminant(place) } @@ -373,22 +414,11 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { } } -struct Replacer<'a, 'tcx> { - tcx: TyCtxt<'tcx>, - ssa: SsaLocals, - dominators: Dominators, - state: VnState<'a, 'tcx>, - /// Set of locals that are reused, and for which we should remove storage statements to avoid a - /// use-after-StorageDead. - reused_locals: BitSet, - any_replacement: &'a mut bool, -} - -impl<'tcx> Replacer<'_, 'tcx> { +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.state.get(index) { - Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_: const_.clone() }) + if let Value::Constant(const_) = *self.get(index) { + Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_ }) } else { None } @@ -397,50 +427,37 @@ impl<'tcx> Replacer<'_, 'tcx> { /// 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.state.rev_locals.get(&index)?; + let other = self.rev_locals.get(&index)?; other .iter() .copied() - .find(|&other| self.ssa.assignment_dominates(&self.dominators, other, loc)) + .find(|&other| self.ssa.assignment_dominates(self.dominators, other, loc)) } } -impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> { +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) { - if let Some(place) = operand.place() - && let Some(value) = self.state.insert_place(place) - { - if let Some(const_) = self.try_as_constant(value) { - *operand = Operand::Constant(Box::new(const_)); - *self.any_replacement = true; - } else if let Some(local) = self.try_as_local(value, location) - && *operand != Operand::Move(local.into()) - { - *operand = Operand::Copy(local.into()); - self.reused_locals.insert(local); - *self.any_replacement = true; - } - } + 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 - && let Some(value) = self.state.insert_rvalue(rvalue) + && 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; + 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; + self.any_replacement = true; } } } diff --git a/compiler/rustc_mir_transform/src/ssa.rs b/compiler/rustc_mir_transform/src/ssa.rs index d16ef712a386b..3a675752fba91 100644 --- a/compiler/rustc_mir_transform/src/ssa.rs +++ b/compiler/rustc_mir_transform/src/ssa.rs @@ -164,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/tests/mir-opt/gvn.cast.GVN.panic-abort.diff b/tests/mir-opt/gvn.cast.GVN.panic-abort.diff index 986052b2d41e5..513fe60b65d93 100644 --- a/tests/mir-opt/gvn.cast.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.cast.GVN.panic-abort.diff @@ -104,11 +104,11 @@ } bb0: { - StorageLive(_1); +- StorageLive(_1); _1 = const 1_i64; - StorageLive(_2); +- StorageLive(_2); _2 = const 1_u64; - StorageLive(_3); +- StorageLive(_3); _3 = const 1f64; StorageLive(_4); StorageLive(_5); @@ -492,9 +492,9 @@ - StorageDead(_90); StorageDead(_89); _0 = const (); - StorageDead(_3); - StorageDead(_2); - StorageDead(_1); +- 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 index 052b9d019f2e7..33192ed8de033 100644 --- a/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff @@ -104,11 +104,11 @@ } bb0: { - StorageLive(_1); +- StorageLive(_1); _1 = const 1_i64; - StorageLive(_2); +- StorageLive(_2); _2 = const 1_u64; - StorageLive(_3); +- StorageLive(_3); _3 = const 1f64; StorageLive(_4); StorageLive(_5); @@ -492,9 +492,9 @@ - StorageDead(_90); StorageDead(_89); _0 = const (); - StorageDead(_3); - StorageDead(_2); - StorageDead(_1); +- StorageDead(_3); +- StorageDead(_2); +- StorageDead(_1); return; } } diff --git a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff index f44ab92f22945..bf866e2f4d22f 100644 --- a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff @@ -420,20 +420,20 @@ StorageDead(_52); StorageLive(_55); - StorageLive(_56); - StorageLive(_57); +- StorageLive(_57); - StorageLive(_58); - _58 = _1; - _57 = S::(move _58); - StorageDead(_58); -+ _57 = _53; - _56 = (_57.0: u64); +- _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(_57); StorageDead(_55); StorageLive(_59); StorageLive(_60); diff --git a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff index a4da75bd680a9..68b052907192d 100644 --- a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff @@ -420,20 +420,20 @@ StorageDead(_52); StorageLive(_55); - StorageLive(_56); - StorageLive(_57); +- StorageLive(_57); - StorageLive(_58); - _58 = _1; - _57 = S::(move _58); - StorageDead(_58); -+ _57 = _53; - _56 = (_57.0: u64); +- _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(_57); StorageDead(_55); StorageLive(_59); StorageLive(_60); 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 2a59a77c45452..1b414a2a29ed2 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 @@ -48,7 +48,7 @@ - _1 = <{generator@$DIR/inline_generator.rs:16:5: 16:8} as Generator>::resume(move _2, const false) -> [return: bb3, unwind unreachable]; + 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: bb2, 1: bb6, 3: bb7, otherwise: bb8]; } 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 8982c31cd09bc..ef76d8e2da30b 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 @@ -48,7 +48,7 @@ - _1 = <{generator@$DIR/inline_generator.rs:16:5: 16:8} as Generator>::resume(move _2, const false) -> [return: bb3, unwind: bb4]; + 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]; } From 8efc151828edfc9b16b17ce4f311a2e629244679 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 23 Sep 2023 07:56:59 +0000 Subject: [PATCH 09/18] Do not clone valtree and slice constants. --- compiler/rustc_mir_transform/src/gvn.rs | 31 ++ .../const_debuginfo.main.ConstDebugInfo.diff | 3 + tests/mir-opt/gvn.rs | 13 + tests/mir-opt/gvn.slices.GVN.panic-abort.diff | 275 ++++++++++++++++++ .../mir-opt/gvn.slices.GVN.panic-unwind.diff | 275 ++++++++++++++++++ ...implifyComparisonIntegral.panic-abort.diff | 1 + ...mplifyComparisonIntegral.panic-unwind.diff | 1 + ...ondition-after-const-prop.panic-abort.diff | 3 + ...ndition-after-const-prop.panic-unwind.diff | 3 + 9 files changed, 605 insertions(+) create mode 100644 tests/mir-opt/gvn.slices.GVN.panic-abort.diff create mode 100644 tests/mir-opt/gvn.slices.GVN.panic-unwind.diff diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 04584a732aa33..1a75b18bf7a53 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -418,6 +418,35 @@ 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 @@ -447,6 +476,8 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> { 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) { diff --git a/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff b/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff index 1e06c6fb49503..ed47baa67daba 100644 --- a/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff +++ b/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff @@ -68,7 +68,10 @@ _2 = const 2_u8; _3 = const 3_u8; StorageLive(_4); + StorageLive(_5); + _5 = const 3_u8; _4 = const 6_u8; + StorageDead(_5); StorageLive(_9); _9 = const "hello, world!"; StorageLive(_14); diff --git a/tests/mir-opt/gvn.rs b/tests/mir-opt/gvn.rs index f86854fe5e163..a85e2ae368b41 100644 --- a/tests/mir-opt/gvn.rs +++ b/tests/mir-opt/gvn.rs @@ -212,6 +212,17 @@ fn dereferences(t: &mut u32, u: &impl Copy, s: &S) { 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); @@ -223,6 +234,7 @@ fn main() { multiple_branches(true, 5, 9); references(5); dereferences(&mut 5, &6, &S(7)); + slices(); } #[inline(never)] @@ -238,3 +250,4 @@ fn opaque(_: impl Sized) {} // 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/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff index 277e3a05867ed..9d8f272abea3a 100644 --- a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff +++ b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff @@ -34,6 +34,7 @@ _2 = move _3 as &[T] (PointerCoercion(Unsize)); StorageDead(_3); _8 = const 3_usize; + _9 = const 3_usize; _10 = const true; goto -> bb2; } diff --git a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff index 327ce8f36bf7f..738b0b1b3e5ac 100644 --- a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff +++ b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff @@ -34,6 +34,7 @@ _2 = move _3 as &[T] (PointerCoercion(Unsize)); StorageDead(_3); _8 = const 3_usize; + _9 = const 3_usize; _10 = const true; goto -> bb2; } diff --git a/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-abort.diff b/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-abort.diff index e6536549db6eb..d395715836064 100644 --- a/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-abort.diff +++ b/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-abort.diff @@ -7,6 +7,8 @@ let _2: (); bb0: { + StorageLive(_1); + _1 = const false; - switchInt(const false) -> [0: bb3, otherwise: bb1]; + goto -> bb3; } @@ -24,6 +26,7 @@ } bb4: { + StorageDead(_1); return; } } diff --git a/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-unwind.diff b/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-unwind.diff index 54f9fe2e89c72..81903c64dbd4b 100644 --- a/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-unwind.diff +++ b/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-unwind.diff @@ -7,6 +7,8 @@ let _2: (); bb0: { + StorageLive(_1); + _1 = const false; - switchInt(const false) -> [0: bb3, otherwise: bb1]; + goto -> bb3; } @@ -24,6 +26,7 @@ } bb4: { + StorageDead(_1); return; } } From 17855c1182bbbe7568ef5a9fc1a7ecf26de51c85 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 16 Sep 2023 17:13:30 +0000 Subject: [PATCH 10/18] Do not remove unused definitions inside GVN. --- compiler/rustc_mir_transform/src/gvn.rs | 12 - compiler/rustc_mir_transform/src/lib.rs | 1 + compiler/rustc_mir_transform/src/simplify.rs | 2 + .../const_debuginfo.main.ConstDebugInfo.diff | 75 ++- .../gvn.arithmetic.GVN.panic-abort.diff | 107 ++-- .../gvn.arithmetic.GVN.panic-unwind.diff | 107 ++-- ...vn.arithmetic_checked.GVN.panic-abort.diff | 109 ++-- ...n.arithmetic_checked.GVN.panic-unwind.diff | 109 ++-- .../gvn.arithmetic_float.GVN.panic-abort.diff | 66 +-- ...gvn.arithmetic_float.GVN.panic-unwind.diff | 66 +-- tests/mir-opt/gvn.cast.GVN.panic-abort.diff | 156 +++--- tests/mir-opt/gvn.cast.GVN.panic-unwind.diff | 156 +++--- .../gvn.dereferences.GVN.panic-abort.diff | 14 +- .../gvn.dereferences.GVN.panic-unwind.diff | 14 +- ...gvn.multiple_branches.GVN.panic-abort.diff | 136 ++--- ...vn.multiple_branches.GVN.panic-unwind.diff | 136 ++--- .../gvn.repeated_index.GVN.panic-abort.diff | 7 +- .../gvn.repeated_index.GVN.panic-unwind.diff | 7 +- tests/mir-opt/gvn.slices.GVN.panic-abort.diff | 41 +- .../mir-opt/gvn.slices.GVN.panic-unwind.diff | 41 +- ...xpression_elimination.GVN.panic-abort.diff | 493 ++++++++++-------- ...pression_elimination.GVN.panic-unwind.diff | 493 ++++++++++-------- .../gvn.wrap_unwrap.GVN.panic-abort.diff | 8 +- .../gvn.wrap_unwrap.GVN.panic-unwind.diff | 8 +- ...implifyComparisonIntegral.panic-abort.diff | 47 +- ...mplifyComparisonIntegral.panic-unwind.diff | 47 +- ...ondition-after-const-prop.panic-abort.diff | 8 +- ...ndition-after-const-prop.panic-unwind.diff | 8 +- 28 files changed, 1348 insertions(+), 1126 deletions(-) diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 1a75b18bf7a53..d66bb2fa396c3 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -111,16 +111,11 @@ fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { 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! { @@ -183,7 +178,6 @@ struct VnState<'body, 'tcx> { ssa: &'body SsaLocals, dominators: &'body Dominators, reused_locals: BitSet, - any_replacement: bool, } impl<'body, 'tcx> VnState<'body, 'tcx> { @@ -205,7 +199,6 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { ssa, dominators, reused_locals: BitSet::new_empty(local_decls.len()), - any_replacement: false, } } @@ -305,13 +298,11 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { { *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() { *place = place_ref.project_deeper(&[], self.tcx); self.reused_locals.insert(place_ref.local); - self.any_replacement = true; } Some(value) @@ -329,7 +320,6 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { let value = self.simplify_place(place, location)?; if let Some(const_) = self.try_as_constant(value) { *operand = Operand::Constant(Box::new(const_)); - self.any_replacement = true; } Some(value) } @@ -482,13 +472,11 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> { { 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; } } } diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index fd6a41a70289a..84b6e8caac577 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -553,6 +553,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { &separate_const_switch::SeparateConstSwitch, &const_prop::ConstProp, &gvn::GVN, + &simplify::SimplifyLocals::AfterGVN, &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/simplify.rs b/compiler/rustc_mir_transform/src/simplify.rs index b7a51cfd61966..8cf725d695cde 100644 --- a/compiler/rustc_mir_transform/src/simplify.rs +++ b/compiler/rustc_mir_transform/src/simplify.rs @@ -458,6 +458,7 @@ fn save_unreachable_coverage( pub enum SimplifyLocals { BeforeConstProp, + AfterGVN, Final, } @@ -465,6 +466,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyLocals { fn name(&self) -> &'static str { match &self { SimplifyLocals::BeforeConstProp => "SimplifyLocals-before-const-prop", + SimplifyLocals::AfterGVN => "SimplifyLocals-after-value-numbering", SimplifyLocals::Final => "SimplifyLocals-final", } } diff --git a/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff b/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff index ed47baa67daba..ca58ecf3fbcde 100644 --- a/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff +++ b/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff @@ -4,12 +4,6 @@ fn main() -> () { let mut _0: (); let _1: u8; - let mut _5: u8; - let mut _6: u8; - let mut _7: u8; - let mut _8: u8; - let mut _12: u32; - let mut _13: u32; scope 1 { - debug x => _1; + debug x => const 1_u8; @@ -25,33 +19,33 @@ scope 4 { - debug sum => _4; + debug sum => const 6_u8; - let _9: &str; + let _5: &str; scope 5 { -- debug s => _9; +- debug s => _5; + debug s => const "hello, world!"; - let _14: bool; - let _15: bool; - let _16: u32; + let _8: bool; + let _9: bool; + let _10: u32; scope 6 { -- debug ((f: (bool, bool, u32)).0: bool) => _14; -- debug ((f: (bool, bool, u32)).1: bool) => _15; -- debug ((f: (bool, bool, u32)).2: u32) => _16; +- debug ((f: (bool, bool, u32)).0: bool) => _8; +- debug ((f: (bool, bool, u32)).1: bool) => _9; +- debug ((f: (bool, bool, u32)).2: u32) => _10; + debug ((f: (bool, bool, u32)).0: bool) => const true; + debug ((f: (bool, bool, u32)).1: bool) => const false; + debug ((f: (bool, bool, u32)).2: u32) => const 123_u32; - let _10: std::option::Option; + let _6: std::option::Option; scope 7 { - debug o => _10; - let _17: u32; - let _18: u32; + debug o => _6; + let _11: u32; + let _12: u32; scope 8 { -- debug ((p: Point).0: u32) => _17; -- debug ((p: Point).1: u32) => _18; +- debug ((p: Point).0: u32) => _11; +- debug ((p: Point).1: u32) => _12; + debug ((p: Point).0: u32) => const 32_u32; + debug ((p: Point).1: u32) => const 32_u32; - let _11: u32; + let _7: u32; scope 9 { -- debug a => _11; +- debug a => _7; + debug a => const 64_u32; } } @@ -68,30 +62,27 @@ _2 = const 2_u8; _3 = const 3_u8; StorageLive(_4); - StorageLive(_5); - _5 = const 3_u8; _4 = const 6_u8; - StorageDead(_5); + StorageLive(_5); + _5 = const "hello, world!"; + StorageLive(_8); StorageLive(_9); - _9 = const "hello, world!"; - StorageLive(_14); - StorageLive(_15); - StorageLive(_16); - _14 = const true; - _15 = const false; - _16 = const 123_u32; StorageLive(_10); - _10 = Option::::Some(const 99_u16); - _17 = const 32_u32; - _18 = const 32_u32; - StorageLive(_11); - _11 = const 64_u32; - StorageDead(_11); - StorageDead(_10); - StorageDead(_14); - StorageDead(_15); - StorageDead(_16); + _8 = const true; + _9 = const false; + _10 = const 123_u32; + StorageLive(_6); + _6 = Option::::Some(const 99_u16); + _11 = const 32_u32; + _12 = const 32_u32; + StorageLive(_7); + _7 = const 64_u32; + StorageDead(_7); + StorageDead(_6); + StorageDead(_8); StorageDead(_9); + StorageDead(_10); + StorageDead(_5); StorageDead(_4); return; } diff --git a/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff b/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff index 3f5173c189e12..17ba0d3cef2d4 100644 --- a/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff @@ -67,11 +67,11 @@ bb0: { StorageLive(_2); StorageLive(_3); -- StorageLive(_4); -- _4 = _1; + StorageLive(_4); + _4 = _1; - _3 = Add(move _4, const 0_u64); -- StorageDead(_4); + _3 = Add(_1, const 0_u64); + StorageDead(_4); _2 = opaque::(move _3) -> [return: bb1, unwind unreachable]; } @@ -80,11 +80,11 @@ StorageDead(_2); StorageLive(_5); StorageLive(_6); -- StorageLive(_7); -- _7 = _1; + StorageLive(_7); + _7 = _1; - _6 = Sub(move _7, const 0_u64); -- StorageDead(_7); + _6 = Sub(_1, const 0_u64); + StorageDead(_7); _5 = opaque::(move _6) -> [return: bb2, unwind unreachable]; } @@ -93,11 +93,11 @@ StorageDead(_5); StorageLive(_8); StorageLive(_9); -- StorageLive(_10); -- _10 = _1; + StorageLive(_10); + _10 = _1; - _9 = Mul(move _10, const 0_u64); -- StorageDead(_10); + _9 = Mul(_1, const 0_u64); + StorageDead(_10); _8 = opaque::(move _9) -> [return: bb3, unwind unreachable]; } @@ -106,11 +106,11 @@ StorageDead(_8); StorageLive(_11); StorageLive(_12); -- StorageLive(_13); -- _13 = _1; + StorageLive(_13); + _13 = _1; - _12 = Mul(move _13, const 1_u64); -- StorageDead(_13); + _12 = Mul(_1, const 1_u64); + StorageDead(_13); _11 = opaque::(move _12) -> [return: bb4, unwind unreachable]; } @@ -119,8 +119,8 @@ StorageDead(_11); StorageLive(_14); StorageLive(_15); -- StorageLive(_16); -- _16 = _1; + 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]; @@ -128,8 +128,8 @@ bb5: { - _15 = Div(move _16, const 0_u64); -- StorageDead(_16); + _15 = Div(_1, const 0_u64); + StorageDead(_16); _14 = opaque::(move _15) -> [return: bb6, unwind unreachable]; } @@ -138,8 +138,8 @@ StorageDead(_14); StorageLive(_18); StorageLive(_19); -- StorageLive(_20); -- _20 = _1; + 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]; @@ -147,8 +147,8 @@ bb7: { - _19 = Div(move _20, const 1_u64); -- StorageDead(_20); + _19 = Div(_1, const 1_u64); + StorageDead(_20); _18 = opaque::(move _19) -> [return: bb8, unwind unreachable]; } @@ -157,8 +157,8 @@ StorageDead(_18); StorageLive(_22); StorageLive(_23); -- StorageLive(_24); -- _24 = _1; + 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); @@ -167,8 +167,8 @@ bb9: { - _23 = Div(const 0_u64, move _24); -- StorageDead(_24); + _23 = Div(const 0_u64, _1); + StorageDead(_24); _22 = opaque::(move _23) -> [return: bb10, unwind unreachable]; } @@ -177,17 +177,18 @@ StorageDead(_22); StorageLive(_26); StorageLive(_27); -- StorageLive(_28); -- _28 = _1; + 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]; ++ _29 = _25; + 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); + StorageDead(_28); _26 = opaque::(move _27) -> [return: bb12, unwind unreachable]; } @@ -196,17 +197,18 @@ StorageDead(_26); StorageLive(_30); StorageLive(_31); -- StorageLive(_32); -- _32 = _1; + 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]; ++ _33 = _17; + 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); + StorageDead(_32); _30 = opaque::(move _31) -> [return: bb14, unwind unreachable]; } @@ -215,17 +217,18 @@ StorageDead(_30); StorageLive(_34); StorageLive(_35); -- StorageLive(_36); -- _36 = _1; + 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]; ++ _37 = _21; + 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); + StorageDead(_36); _34 = opaque::(move _35) -> [return: bb16, unwind unreachable]; } @@ -234,17 +237,18 @@ StorageDead(_34); StorageLive(_38); StorageLive(_39); -- StorageLive(_40); -- _40 = _1; + 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]; ++ _41 = _25; + 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); + StorageDead(_40); _38 = opaque::(move _39) -> [return: bb18, unwind unreachable]; } @@ -253,17 +257,18 @@ StorageDead(_38); StorageLive(_42); StorageLive(_43); -- StorageLive(_44); -- _44 = _1; + 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]; ++ _45 = _25; + 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); + StorageDead(_44); _42 = opaque::(move _43) -> [return: bb20, unwind unreachable]; } @@ -272,11 +277,11 @@ StorageDead(_42); StorageLive(_46); StorageLive(_47); -- StorageLive(_48); -- _48 = _1; + StorageLive(_48); + _48 = _1; - _47 = BitAnd(move _48, const 0_u64); -- StorageDead(_48); + _47 = BitAnd(_1, const 0_u64); + StorageDead(_48); _46 = opaque::(move _47) -> [return: bb21, unwind unreachable]; } @@ -285,11 +290,11 @@ StorageDead(_46); StorageLive(_49); StorageLive(_50); -- StorageLive(_51); -- _51 = _1; + StorageLive(_51); + _51 = _1; - _50 = BitOr(move _51, const 0_u64); -- StorageDead(_51); + _50 = BitOr(_1, const 0_u64); + StorageDead(_51); _49 = opaque::(move _50) -> [return: bb22, unwind unreachable]; } @@ -298,11 +303,11 @@ StorageDead(_49); StorageLive(_52); StorageLive(_53); -- StorageLive(_54); -- _54 = _1; + StorageLive(_54); + _54 = _1; - _53 = BitXor(move _54, const 0_u64); -- StorageDead(_54); + _53 = BitXor(_1, const 0_u64); + StorageDead(_54); _52 = opaque::(move _53) -> [return: bb23, unwind unreachable]; } @@ -311,11 +316,11 @@ StorageDead(_52); StorageLive(_55); StorageLive(_56); -- StorageLive(_57); -- _57 = _1; + StorageLive(_57); + _57 = _1; - _56 = Shr(move _57, const 0_i32); -- StorageDead(_57); + _56 = Shr(_1, const 0_i32); + StorageDead(_57); _55 = opaque::(move _56) -> [return: bb24, unwind unreachable]; } @@ -324,11 +329,11 @@ StorageDead(_55); StorageLive(_58); StorageLive(_59); -- StorageLive(_60); -- _60 = _1; + StorageLive(_60); + _60 = _1; - _59 = Shl(move _60, const 0_i32); -- StorageDead(_60); + _59 = Shl(_1, const 0_i32); + StorageDead(_60); _58 = opaque::(move _59) -> [return: bb25, unwind unreachable]; } diff --git a/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff b/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff index 38da21d91d41d..f14fd409bea1c 100644 --- a/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff @@ -67,11 +67,11 @@ bb0: { StorageLive(_2); StorageLive(_3); -- StorageLive(_4); -- _4 = _1; + StorageLive(_4); + _4 = _1; - _3 = Add(move _4, const 0_u64); -- StorageDead(_4); + _3 = Add(_1, const 0_u64); + StorageDead(_4); _2 = opaque::(move _3) -> [return: bb1, unwind continue]; } @@ -80,11 +80,11 @@ StorageDead(_2); StorageLive(_5); StorageLive(_6); -- StorageLive(_7); -- _7 = _1; + StorageLive(_7); + _7 = _1; - _6 = Sub(move _7, const 0_u64); -- StorageDead(_7); + _6 = Sub(_1, const 0_u64); + StorageDead(_7); _5 = opaque::(move _6) -> [return: bb2, unwind continue]; } @@ -93,11 +93,11 @@ StorageDead(_5); StorageLive(_8); StorageLive(_9); -- StorageLive(_10); -- _10 = _1; + StorageLive(_10); + _10 = _1; - _9 = Mul(move _10, const 0_u64); -- StorageDead(_10); + _9 = Mul(_1, const 0_u64); + StorageDead(_10); _8 = opaque::(move _9) -> [return: bb3, unwind continue]; } @@ -106,11 +106,11 @@ StorageDead(_8); StorageLive(_11); StorageLive(_12); -- StorageLive(_13); -- _13 = _1; + StorageLive(_13); + _13 = _1; - _12 = Mul(move _13, const 1_u64); -- StorageDead(_13); + _12 = Mul(_1, const 1_u64); + StorageDead(_13); _11 = opaque::(move _12) -> [return: bb4, unwind continue]; } @@ -119,8 +119,8 @@ StorageDead(_11); StorageLive(_14); StorageLive(_15); -- StorageLive(_16); -- _16 = _1; + 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]; @@ -128,8 +128,8 @@ bb5: { - _15 = Div(move _16, const 0_u64); -- StorageDead(_16); + _15 = Div(_1, const 0_u64); + StorageDead(_16); _14 = opaque::(move _15) -> [return: bb6, unwind continue]; } @@ -138,8 +138,8 @@ StorageDead(_14); StorageLive(_18); StorageLive(_19); -- StorageLive(_20); -- _20 = _1; + 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]; @@ -147,8 +147,8 @@ bb7: { - _19 = Div(move _20, const 1_u64); -- StorageDead(_20); + _19 = Div(_1, const 1_u64); + StorageDead(_20); _18 = opaque::(move _19) -> [return: bb8, unwind continue]; } @@ -157,8 +157,8 @@ StorageDead(_18); StorageLive(_22); StorageLive(_23); -- StorageLive(_24); -- _24 = _1; + 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); @@ -167,8 +167,8 @@ bb9: { - _23 = Div(const 0_u64, move _24); -- StorageDead(_24); + _23 = Div(const 0_u64, _1); + StorageDead(_24); _22 = opaque::(move _23) -> [return: bb10, unwind continue]; } @@ -177,17 +177,18 @@ StorageDead(_22); StorageLive(_26); StorageLive(_27); -- StorageLive(_28); -- _28 = _1; + 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]; ++ _29 = _25; + 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); + StorageDead(_28); _26 = opaque::(move _27) -> [return: bb12, unwind continue]; } @@ -196,17 +197,18 @@ StorageDead(_26); StorageLive(_30); StorageLive(_31); -- StorageLive(_32); -- _32 = _1; + 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]; ++ _33 = _17; + 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); + StorageDead(_32); _30 = opaque::(move _31) -> [return: bb14, unwind continue]; } @@ -215,17 +217,18 @@ StorageDead(_30); StorageLive(_34); StorageLive(_35); -- StorageLive(_36); -- _36 = _1; + 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]; ++ _37 = _21; + 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); + StorageDead(_36); _34 = opaque::(move _35) -> [return: bb16, unwind continue]; } @@ -234,17 +237,18 @@ StorageDead(_34); StorageLive(_38); StorageLive(_39); -- StorageLive(_40); -- _40 = _1; + 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]; ++ _41 = _25; + 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); + StorageDead(_40); _38 = opaque::(move _39) -> [return: bb18, unwind continue]; } @@ -253,17 +257,18 @@ StorageDead(_38); StorageLive(_42); StorageLive(_43); -- StorageLive(_44); -- _44 = _1; + 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]; ++ _45 = _25; + 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); + StorageDead(_44); _42 = opaque::(move _43) -> [return: bb20, unwind continue]; } @@ -272,11 +277,11 @@ StorageDead(_42); StorageLive(_46); StorageLive(_47); -- StorageLive(_48); -- _48 = _1; + StorageLive(_48); + _48 = _1; - _47 = BitAnd(move _48, const 0_u64); -- StorageDead(_48); + _47 = BitAnd(_1, const 0_u64); + StorageDead(_48); _46 = opaque::(move _47) -> [return: bb21, unwind continue]; } @@ -285,11 +290,11 @@ StorageDead(_46); StorageLive(_49); StorageLive(_50); -- StorageLive(_51); -- _51 = _1; + StorageLive(_51); + _51 = _1; - _50 = BitOr(move _51, const 0_u64); -- StorageDead(_51); + _50 = BitOr(_1, const 0_u64); + StorageDead(_51); _49 = opaque::(move _50) -> [return: bb22, unwind continue]; } @@ -298,11 +303,11 @@ StorageDead(_49); StorageLive(_52); StorageLive(_53); -- StorageLive(_54); -- _54 = _1; + StorageLive(_54); + _54 = _1; - _53 = BitXor(move _54, const 0_u64); -- StorageDead(_54); + _53 = BitXor(_1, const 0_u64); + StorageDead(_54); _52 = opaque::(move _53) -> [return: bb23, unwind continue]; } @@ -311,11 +316,11 @@ StorageDead(_52); StorageLive(_55); StorageLive(_56); -- StorageLive(_57); -- _57 = _1; + StorageLive(_57); + _57 = _1; - _56 = Shr(move _57, const 0_i32); -- StorageDead(_57); + _56 = Shr(_1, const 0_i32); + StorageDead(_57); _55 = opaque::(move _56) -> [return: bb24, unwind continue]; } @@ -324,11 +329,11 @@ StorageDead(_55); StorageLive(_58); StorageLive(_59); -- StorageLive(_60); -- _60 = _1; + StorageLive(_60); + _60 = _1; - _59 = Shl(move _60, const 0_i32); -- StorageDead(_60); + _59 = Shl(_1, const 0_i32); + StorageDead(_60); _58 = opaque::(move _59) -> [return: bb25, unwind continue]; } diff --git a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff index 0c342799e0794..e586e4ac8898c 100644 --- a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff @@ -75,8 +75,8 @@ bb0: { StorageLive(_2); StorageLive(_3); -- StorageLive(_4); -- _4 = _1; + 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); @@ -85,7 +85,7 @@ bb1: { _3 = move (_5.0: u64); -- StorageDead(_4); + StorageDead(_4); _2 = opaque::(move _3) -> [return: bb2, unwind unreachable]; } @@ -94,8 +94,8 @@ StorageDead(_2); StorageLive(_6); StorageLive(_7); -- StorageLive(_8); -- _8 = _1; + 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); @@ -104,7 +104,7 @@ bb3: { _7 = move (_9.0: u64); -- StorageDead(_8); + StorageDead(_8); _6 = opaque::(move _7) -> [return: bb4, unwind unreachable]; } @@ -113,8 +113,8 @@ StorageDead(_6); StorageLive(_10); StorageLive(_11); -- StorageLive(_12); -- _12 = _1; + 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); @@ -123,7 +123,7 @@ bb5: { _11 = move (_13.0: u64); -- StorageDead(_12); + StorageDead(_12); _10 = opaque::(move _11) -> [return: bb6, unwind unreachable]; } @@ -132,8 +132,8 @@ StorageDead(_10); StorageLive(_14); StorageLive(_15); -- StorageLive(_16); -- _16 = _1; + 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); @@ -142,7 +142,7 @@ bb7: { _15 = move (_17.0: u64); -- StorageDead(_16); + StorageDead(_16); _14 = opaque::(move _15) -> [return: bb8, unwind unreachable]; } @@ -151,8 +151,8 @@ StorageDead(_14); StorageLive(_18); StorageLive(_19); -- StorageLive(_20); -- _20 = _1; + 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]; @@ -160,8 +160,8 @@ bb9: { - _19 = Div(move _20, const 0_u64); -- StorageDead(_20); + _19 = Div(_1, const 0_u64); + StorageDead(_20); _18 = opaque::(move _19) -> [return: bb10, unwind unreachable]; } @@ -170,8 +170,8 @@ StorageDead(_18); StorageLive(_22); StorageLive(_23); -- StorageLive(_24); -- _24 = _1; + 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]; @@ -179,8 +179,8 @@ bb11: { - _23 = Div(move _24, const 1_u64); -- StorageDead(_24); + _23 = Div(_1, const 1_u64); + StorageDead(_24); _22 = opaque::(move _23) -> [return: bb12, unwind unreachable]; } @@ -189,8 +189,8 @@ StorageDead(_22); StorageLive(_26); StorageLive(_27); -- StorageLive(_28); -- _28 = _1; + 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); @@ -199,8 +199,8 @@ bb13: { - _27 = Div(const 0_u64, move _28); -- StorageDead(_28); + _27 = Div(const 0_u64, _1); + StorageDead(_28); _26 = opaque::(move _27) -> [return: bb14, unwind unreachable]; } @@ -209,17 +209,18 @@ StorageDead(_26); StorageLive(_30); StorageLive(_31); -- StorageLive(_32); -- _32 = _1; + 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]; ++ _33 = _29; + 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); + StorageDead(_32); _30 = opaque::(move _31) -> [return: bb16, unwind unreachable]; } @@ -228,17 +229,18 @@ StorageDead(_30); StorageLive(_34); StorageLive(_35); -- StorageLive(_36); -- _36 = _1; + 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]; ++ _37 = _21; + 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); + StorageDead(_36); _34 = opaque::(move _35) -> [return: bb18, unwind unreachable]; } @@ -247,17 +249,18 @@ StorageDead(_34); StorageLive(_38); StorageLive(_39); -- StorageLive(_40); -- _40 = _1; + 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]; ++ _41 = _25; + 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); + StorageDead(_40); _38 = opaque::(move _39) -> [return: bb20, unwind unreachable]; } @@ -266,17 +269,18 @@ StorageDead(_38); StorageLive(_42); StorageLive(_43); -- StorageLive(_44); -- _44 = _1; + 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]; ++ _45 = _29; + 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); + StorageDead(_44); _42 = opaque::(move _43) -> [return: bb22, unwind unreachable]; } @@ -285,17 +289,18 @@ StorageDead(_42); StorageLive(_46); StorageLive(_47); -- StorageLive(_48); -- _48 = _1; + 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]; ++ _49 = _29; + 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); + StorageDead(_48); _46 = opaque::(move _47) -> [return: bb24, unwind unreachable]; } @@ -304,11 +309,11 @@ StorageDead(_46); StorageLive(_50); StorageLive(_51); -- StorageLive(_52); -- _52 = _1; + StorageLive(_52); + _52 = _1; - _51 = BitAnd(move _52, const 0_u64); -- StorageDead(_52); + _51 = BitAnd(_1, const 0_u64); + StorageDead(_52); _50 = opaque::(move _51) -> [return: bb25, unwind unreachable]; } @@ -317,11 +322,11 @@ StorageDead(_50); StorageLive(_53); StorageLive(_54); -- StorageLive(_55); -- _55 = _1; + StorageLive(_55); + _55 = _1; - _54 = BitOr(move _55, const 0_u64); -- StorageDead(_55); + _54 = BitOr(_1, const 0_u64); + StorageDead(_55); _53 = opaque::(move _54) -> [return: bb26, unwind unreachable]; } @@ -330,11 +335,11 @@ StorageDead(_53); StorageLive(_56); StorageLive(_57); -- StorageLive(_58); -- _58 = _1; + StorageLive(_58); + _58 = _1; - _57 = BitXor(move _58, const 0_u64); -- StorageDead(_58); + _57 = BitXor(_1, const 0_u64); + StorageDead(_58); _56 = opaque::(move _57) -> [return: bb27, unwind unreachable]; } @@ -343,8 +348,8 @@ StorageDead(_56); StorageLive(_59); StorageLive(_60); -- StorageLive(_61); -- _61 = _1; + 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]; @@ -354,8 +359,8 @@ bb28: { - _60 = Shr(move _61, const 0_i32); -- StorageDead(_61); + _60 = Shr(_1, const 0_i32); + StorageDead(_61); _59 = opaque::(move _60) -> [return: bb29, unwind unreachable]; } @@ -364,18 +369,20 @@ StorageDead(_59); StorageLive(_64); StorageLive(_65); -- StorageLive(_66); -- _66 = _1; + 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]; ++ _67 = _62; ++ _68 = _63; + 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); + StorageDead(_66); _64 = opaque::(move _65) -> [return: bb31, unwind unreachable]; } diff --git a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff index 7813c29b962d2..f58a9116b8fe7 100644 --- a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff @@ -75,8 +75,8 @@ bb0: { StorageLive(_2); StorageLive(_3); -- StorageLive(_4); -- _4 = _1; + 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); @@ -85,7 +85,7 @@ bb1: { _3 = move (_5.0: u64); -- StorageDead(_4); + StorageDead(_4); _2 = opaque::(move _3) -> [return: bb2, unwind continue]; } @@ -94,8 +94,8 @@ StorageDead(_2); StorageLive(_6); StorageLive(_7); -- StorageLive(_8); -- _8 = _1; + 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); @@ -104,7 +104,7 @@ bb3: { _7 = move (_9.0: u64); -- StorageDead(_8); + StorageDead(_8); _6 = opaque::(move _7) -> [return: bb4, unwind continue]; } @@ -113,8 +113,8 @@ StorageDead(_6); StorageLive(_10); StorageLive(_11); -- StorageLive(_12); -- _12 = _1; + 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); @@ -123,7 +123,7 @@ bb5: { _11 = move (_13.0: u64); -- StorageDead(_12); + StorageDead(_12); _10 = opaque::(move _11) -> [return: bb6, unwind continue]; } @@ -132,8 +132,8 @@ StorageDead(_10); StorageLive(_14); StorageLive(_15); -- StorageLive(_16); -- _16 = _1; + 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); @@ -142,7 +142,7 @@ bb7: { _15 = move (_17.0: u64); -- StorageDead(_16); + StorageDead(_16); _14 = opaque::(move _15) -> [return: bb8, unwind continue]; } @@ -151,8 +151,8 @@ StorageDead(_14); StorageLive(_18); StorageLive(_19); -- StorageLive(_20); -- _20 = _1; + 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]; @@ -160,8 +160,8 @@ bb9: { - _19 = Div(move _20, const 0_u64); -- StorageDead(_20); + _19 = Div(_1, const 0_u64); + StorageDead(_20); _18 = opaque::(move _19) -> [return: bb10, unwind continue]; } @@ -170,8 +170,8 @@ StorageDead(_18); StorageLive(_22); StorageLive(_23); -- StorageLive(_24); -- _24 = _1; + 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]; @@ -179,8 +179,8 @@ bb11: { - _23 = Div(move _24, const 1_u64); -- StorageDead(_24); + _23 = Div(_1, const 1_u64); + StorageDead(_24); _22 = opaque::(move _23) -> [return: bb12, unwind continue]; } @@ -189,8 +189,8 @@ StorageDead(_22); StorageLive(_26); StorageLive(_27); -- StorageLive(_28); -- _28 = _1; + 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); @@ -199,8 +199,8 @@ bb13: { - _27 = Div(const 0_u64, move _28); -- StorageDead(_28); + _27 = Div(const 0_u64, _1); + StorageDead(_28); _26 = opaque::(move _27) -> [return: bb14, unwind continue]; } @@ -209,17 +209,18 @@ StorageDead(_26); StorageLive(_30); StorageLive(_31); -- StorageLive(_32); -- _32 = _1; + 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]; ++ _33 = _29; + 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); + StorageDead(_32); _30 = opaque::(move _31) -> [return: bb16, unwind continue]; } @@ -228,17 +229,18 @@ StorageDead(_30); StorageLive(_34); StorageLive(_35); -- StorageLive(_36); -- _36 = _1; + 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]; ++ _37 = _21; + 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); + StorageDead(_36); _34 = opaque::(move _35) -> [return: bb18, unwind continue]; } @@ -247,17 +249,18 @@ StorageDead(_34); StorageLive(_38); StorageLive(_39); -- StorageLive(_40); -- _40 = _1; + 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]; ++ _41 = _25; + 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); + StorageDead(_40); _38 = opaque::(move _39) -> [return: bb20, unwind continue]; } @@ -266,17 +269,18 @@ StorageDead(_38); StorageLive(_42); StorageLive(_43); -- StorageLive(_44); -- _44 = _1; + 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]; ++ _45 = _29; + 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); + StorageDead(_44); _42 = opaque::(move _43) -> [return: bb22, unwind continue]; } @@ -285,17 +289,18 @@ StorageDead(_42); StorageLive(_46); StorageLive(_47); -- StorageLive(_48); -- _48 = _1; + 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]; ++ _49 = _29; + 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); + StorageDead(_48); _46 = opaque::(move _47) -> [return: bb24, unwind continue]; } @@ -304,11 +309,11 @@ StorageDead(_46); StorageLive(_50); StorageLive(_51); -- StorageLive(_52); -- _52 = _1; + StorageLive(_52); + _52 = _1; - _51 = BitAnd(move _52, const 0_u64); -- StorageDead(_52); + _51 = BitAnd(_1, const 0_u64); + StorageDead(_52); _50 = opaque::(move _51) -> [return: bb25, unwind continue]; } @@ -317,11 +322,11 @@ StorageDead(_50); StorageLive(_53); StorageLive(_54); -- StorageLive(_55); -- _55 = _1; + StorageLive(_55); + _55 = _1; - _54 = BitOr(move _55, const 0_u64); -- StorageDead(_55); + _54 = BitOr(_1, const 0_u64); + StorageDead(_55); _53 = opaque::(move _54) -> [return: bb26, unwind continue]; } @@ -330,11 +335,11 @@ StorageDead(_53); StorageLive(_56); StorageLive(_57); -- StorageLive(_58); -- _58 = _1; + StorageLive(_58); + _58 = _1; - _57 = BitXor(move _58, const 0_u64); -- StorageDead(_58); + _57 = BitXor(_1, const 0_u64); + StorageDead(_58); _56 = opaque::(move _57) -> [return: bb27, unwind continue]; } @@ -343,8 +348,8 @@ StorageDead(_56); StorageLive(_59); StorageLive(_60); -- StorageLive(_61); -- _61 = _1; + 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]; @@ -354,8 +359,8 @@ bb28: { - _60 = Shr(move _61, const 0_i32); -- StorageDead(_61); + _60 = Shr(_1, const 0_i32); + StorageDead(_61); _59 = opaque::(move _60) -> [return: bb29, unwind continue]; } @@ -364,18 +369,20 @@ StorageDead(_59); StorageLive(_64); StorageLive(_65); -- StorageLive(_66); -- _66 = _1; + 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]; ++ _67 = _62; ++ _68 = _63; + 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); + StorageDead(_66); _64 = opaque::(move _65) -> [return: bb31, unwind continue]; } diff --git a/tests/mir-opt/gvn.arithmetic_float.GVN.panic-abort.diff b/tests/mir-opt/gvn.arithmetic_float.GVN.panic-abort.diff index 7d5ac8353fe43..b332100eaf03c 100644 --- a/tests/mir-opt/gvn.arithmetic_float.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.arithmetic_float.GVN.panic-abort.diff @@ -37,11 +37,11 @@ bb0: { StorageLive(_2); StorageLive(_3); -- StorageLive(_4); -- _4 = _1; + StorageLive(_4); + _4 = _1; - _3 = Add(move _4, const 0f64); -- StorageDead(_4); + _3 = Add(_1, const 0f64); + StorageDead(_4); _2 = opaque::(move _3) -> [return: bb1, unwind unreachable]; } @@ -50,11 +50,11 @@ StorageDead(_2); StorageLive(_5); StorageLive(_6); -- StorageLive(_7); -- _7 = _1; + StorageLive(_7); + _7 = _1; - _6 = Sub(move _7, const 0f64); -- StorageDead(_7); + _6 = Sub(_1, const 0f64); + StorageDead(_7); _5 = opaque::(move _6) -> [return: bb2, unwind unreachable]; } @@ -63,11 +63,11 @@ StorageDead(_5); StorageLive(_8); StorageLive(_9); -- StorageLive(_10); -- _10 = _1; + StorageLive(_10); + _10 = _1; - _9 = Mul(move _10, const 0f64); -- StorageDead(_10); + _9 = Mul(_1, const 0f64); + StorageDead(_10); _8 = opaque::(move _9) -> [return: bb3, unwind unreachable]; } @@ -76,11 +76,11 @@ StorageDead(_8); StorageLive(_11); StorageLive(_12); -- StorageLive(_13); -- _13 = _1; + StorageLive(_13); + _13 = _1; - _12 = Div(move _13, const 0f64); -- StorageDead(_13); + _12 = Div(_1, const 0f64); + StorageDead(_13); _11 = opaque::(move _12) -> [return: bb4, unwind unreachable]; } @@ -89,11 +89,11 @@ StorageDead(_11); StorageLive(_14); StorageLive(_15); -- StorageLive(_16); -- _16 = _1; + StorageLive(_16); + _16 = _1; - _15 = Div(const 0f64, move _16); -- StorageDead(_16); + _15 = Div(const 0f64, _1); + StorageDead(_16); _14 = opaque::(move _15) -> [return: bb5, unwind unreachable]; } @@ -102,11 +102,11 @@ StorageDead(_14); StorageLive(_17); StorageLive(_18); -- StorageLive(_19); -- _19 = _1; + StorageLive(_19); + _19 = _1; - _18 = Rem(move _19, const 0f64); -- StorageDead(_19); + _18 = Rem(_1, const 0f64); + StorageDead(_19); _17 = opaque::(move _18) -> [return: bb6, unwind unreachable]; } @@ -115,11 +115,11 @@ StorageDead(_17); StorageLive(_20); StorageLive(_21); -- StorageLive(_22); -- _22 = _1; + StorageLive(_22); + _22 = _1; - _21 = Rem(const 0f64, move _22); -- StorageDead(_22); + _21 = Rem(const 0f64, _1); + StorageDead(_22); _20 = opaque::(move _21) -> [return: bb7, unwind unreachable]; } @@ -128,14 +128,14 @@ StorageDead(_20); StorageLive(_23); StorageLive(_24); -- StorageLive(_25); -- _25 = _1; -- StorageLive(_26); -- _26 = _1; + StorageLive(_25); + _25 = _1; + StorageLive(_26); + _26 = _1; - _24 = Eq(move _25, move _26); -- StorageDead(_26); -- StorageDead(_25); + _24 = Eq(_1, _1); + StorageDead(_26); + StorageDead(_25); _23 = opaque::(move _24) -> [return: bb8, unwind unreachable]; } @@ -144,14 +144,14 @@ StorageDead(_23); StorageLive(_27); StorageLive(_28); -- StorageLive(_29); -- _29 = _1; -- StorageLive(_30); -- _30 = _1; + StorageLive(_29); + _29 = _1; + StorageLive(_30); + _30 = _1; - _28 = Ne(move _29, move _30); -- StorageDead(_30); -- StorageDead(_29); + _28 = Ne(_1, _1); + StorageDead(_30); + StorageDead(_29); _27 = opaque::(move _28) -> [return: bb9, unwind unreachable]; } diff --git a/tests/mir-opt/gvn.arithmetic_float.GVN.panic-unwind.diff b/tests/mir-opt/gvn.arithmetic_float.GVN.panic-unwind.diff index 36c26dc66051b..28664cb0ac8ca 100644 --- a/tests/mir-opt/gvn.arithmetic_float.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.arithmetic_float.GVN.panic-unwind.diff @@ -37,11 +37,11 @@ bb0: { StorageLive(_2); StorageLive(_3); -- StorageLive(_4); -- _4 = _1; + StorageLive(_4); + _4 = _1; - _3 = Add(move _4, const 0f64); -- StorageDead(_4); + _3 = Add(_1, const 0f64); + StorageDead(_4); _2 = opaque::(move _3) -> [return: bb1, unwind continue]; } @@ -50,11 +50,11 @@ StorageDead(_2); StorageLive(_5); StorageLive(_6); -- StorageLive(_7); -- _7 = _1; + StorageLive(_7); + _7 = _1; - _6 = Sub(move _7, const 0f64); -- StorageDead(_7); + _6 = Sub(_1, const 0f64); + StorageDead(_7); _5 = opaque::(move _6) -> [return: bb2, unwind continue]; } @@ -63,11 +63,11 @@ StorageDead(_5); StorageLive(_8); StorageLive(_9); -- StorageLive(_10); -- _10 = _1; + StorageLive(_10); + _10 = _1; - _9 = Mul(move _10, const 0f64); -- StorageDead(_10); + _9 = Mul(_1, const 0f64); + StorageDead(_10); _8 = opaque::(move _9) -> [return: bb3, unwind continue]; } @@ -76,11 +76,11 @@ StorageDead(_8); StorageLive(_11); StorageLive(_12); -- StorageLive(_13); -- _13 = _1; + StorageLive(_13); + _13 = _1; - _12 = Div(move _13, const 0f64); -- StorageDead(_13); + _12 = Div(_1, const 0f64); + StorageDead(_13); _11 = opaque::(move _12) -> [return: bb4, unwind continue]; } @@ -89,11 +89,11 @@ StorageDead(_11); StorageLive(_14); StorageLive(_15); -- StorageLive(_16); -- _16 = _1; + StorageLive(_16); + _16 = _1; - _15 = Div(const 0f64, move _16); -- StorageDead(_16); + _15 = Div(const 0f64, _1); + StorageDead(_16); _14 = opaque::(move _15) -> [return: bb5, unwind continue]; } @@ -102,11 +102,11 @@ StorageDead(_14); StorageLive(_17); StorageLive(_18); -- StorageLive(_19); -- _19 = _1; + StorageLive(_19); + _19 = _1; - _18 = Rem(move _19, const 0f64); -- StorageDead(_19); + _18 = Rem(_1, const 0f64); + StorageDead(_19); _17 = opaque::(move _18) -> [return: bb6, unwind continue]; } @@ -115,11 +115,11 @@ StorageDead(_17); StorageLive(_20); StorageLive(_21); -- StorageLive(_22); -- _22 = _1; + StorageLive(_22); + _22 = _1; - _21 = Rem(const 0f64, move _22); -- StorageDead(_22); + _21 = Rem(const 0f64, _1); + StorageDead(_22); _20 = opaque::(move _21) -> [return: bb7, unwind continue]; } @@ -128,14 +128,14 @@ StorageDead(_20); StorageLive(_23); StorageLive(_24); -- StorageLive(_25); -- _25 = _1; -- StorageLive(_26); -- _26 = _1; + StorageLive(_25); + _25 = _1; + StorageLive(_26); + _26 = _1; - _24 = Eq(move _25, move _26); -- StorageDead(_26); -- StorageDead(_25); + _24 = Eq(_1, _1); + StorageDead(_26); + StorageDead(_25); _23 = opaque::(move _24) -> [return: bb8, unwind continue]; } @@ -144,14 +144,14 @@ StorageDead(_23); StorageLive(_27); StorageLive(_28); -- StorageLive(_29); -- _29 = _1; -- StorageLive(_30); -- _30 = _1; + StorageLive(_29); + _29 = _1; + StorageLive(_30); + _30 = _1; - _28 = Ne(move _29, move _30); -- StorageDead(_30); -- StorageDead(_29); + _28 = Ne(_1, _1); + StorageDead(_30); + StorageDead(_29); _27 = opaque::(move _28) -> [return: bb9, unwind continue]; } diff --git a/tests/mir-opt/gvn.cast.GVN.panic-abort.diff b/tests/mir-opt/gvn.cast.GVN.panic-abort.diff index 513fe60b65d93..37b0d92931f68 100644 --- a/tests/mir-opt/gvn.cast.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.cast.GVN.panic-abort.diff @@ -105,18 +105,22 @@ bb0: { - StorageLive(_1); ++ nop; _1 = const 1_i64; - StorageLive(_2); ++ nop; _2 = const 1_u64; - StorageLive(_3); ++ nop; _3 = const 1f64; StorageLive(_4); StorageLive(_5); -- StorageLive(_6); + StorageLive(_6); - _6 = _1; - _5 = move _6 as u8 (IntToInt); -- StorageDead(_6); ++ _6 = const 1_i64; + _5 = const 1_i64 as u8 (IntToInt); + StorageDead(_6); _4 = opaque::(move _5) -> [return: bb1, unwind unreachable]; } @@ -125,11 +129,12 @@ StorageDead(_4); StorageLive(_7); StorageLive(_8); -- StorageLive(_9); + StorageLive(_9); - _9 = _1; - _8 = move _9 as u16 (IntToInt); -- StorageDead(_9); ++ _9 = const 1_i64; + _8 = const 1_i64 as u16 (IntToInt); + StorageDead(_9); _7 = opaque::(move _8) -> [return: bb2, unwind unreachable]; } @@ -138,11 +143,12 @@ StorageDead(_7); StorageLive(_10); StorageLive(_11); -- StorageLive(_12); + StorageLive(_12); - _12 = _1; - _11 = move _12 as u32 (IntToInt); -- StorageDead(_12); ++ _12 = const 1_i64; + _11 = const 1_i64 as u32 (IntToInt); + StorageDead(_12); _10 = opaque::(move _11) -> [return: bb3, unwind unreachable]; } @@ -151,11 +157,12 @@ StorageDead(_10); StorageLive(_13); StorageLive(_14); -- StorageLive(_15); + StorageLive(_15); - _15 = _1; - _14 = move _15 as u64 (IntToInt); -- StorageDead(_15); ++ _15 = const 1_i64; + _14 = const 1_i64 as u64 (IntToInt); + StorageDead(_15); _13 = opaque::(move _14) -> [return: bb4, unwind unreachable]; } @@ -164,11 +171,12 @@ StorageDead(_13); StorageLive(_16); StorageLive(_17); -- StorageLive(_18); + StorageLive(_18); - _18 = _1; - _17 = move _18 as i8 (IntToInt); -- StorageDead(_18); ++ _18 = const 1_i64; + _17 = const 1_i64 as i8 (IntToInt); + StorageDead(_18); _16 = opaque::(move _17) -> [return: bb5, unwind unreachable]; } @@ -177,11 +185,12 @@ StorageDead(_16); StorageLive(_19); StorageLive(_20); -- StorageLive(_21); + StorageLive(_21); - _21 = _1; - _20 = move _21 as i16 (IntToInt); -- StorageDead(_21); ++ _21 = const 1_i64; + _20 = const 1_i64 as i16 (IntToInt); + StorageDead(_21); _19 = opaque::(move _20) -> [return: bb6, unwind unreachable]; } @@ -190,11 +199,12 @@ StorageDead(_19); StorageLive(_22); StorageLive(_23); -- StorageLive(_24); + StorageLive(_24); - _24 = _1; - _23 = move _24 as i32 (IntToInt); -- StorageDead(_24); ++ _24 = const 1_i64; + _23 = const 1_i64 as i32 (IntToInt); + StorageDead(_24); _22 = opaque::(move _23) -> [return: bb7, unwind unreachable]; } @@ -202,22 +212,24 @@ StorageDead(_23); StorageDead(_22); StorageLive(_25); -- StorageLive(_26); + StorageLive(_26); - _26 = _1; - _25 = opaque::(move _26) -> [return: bb8, unwind unreachable]; ++ _26 = const 1_i64; + _25 = opaque::(const 1_i64) -> [return: bb8, unwind unreachable]; } bb8: { -- StorageDead(_26); + StorageDead(_26); StorageDead(_25); StorageLive(_27); StorageLive(_28); -- StorageLive(_29); + StorageLive(_29); - _29 = _1; - _28 = move _29 as f32 (IntToFloat); -- StorageDead(_29); ++ _29 = const 1_i64; + _28 = const 1_i64 as f32 (IntToFloat); + StorageDead(_29); _27 = opaque::(move _28) -> [return: bb9, unwind unreachable]; } @@ -226,11 +238,12 @@ StorageDead(_27); StorageLive(_30); StorageLive(_31); -- StorageLive(_32); + StorageLive(_32); - _32 = _1; - _31 = move _32 as f64 (IntToFloat); -- StorageDead(_32); ++ _32 = const 1_i64; + _31 = const 1_i64 as f64 (IntToFloat); + StorageDead(_32); _30 = opaque::(move _31) -> [return: bb10, unwind unreachable]; } @@ -239,11 +252,12 @@ StorageDead(_30); StorageLive(_33); StorageLive(_34); -- StorageLive(_35); + StorageLive(_35); - _35 = _2; - _34 = move _35 as u8 (IntToInt); -- StorageDead(_35); ++ _35 = const 1_u64; + _34 = const 1_u64 as u8 (IntToInt); + StorageDead(_35); _33 = opaque::(move _34) -> [return: bb11, unwind unreachable]; } @@ -252,11 +266,12 @@ StorageDead(_33); StorageLive(_36); StorageLive(_37); -- StorageLive(_38); + StorageLive(_38); - _38 = _2; - _37 = move _38 as u16 (IntToInt); -- StorageDead(_38); ++ _38 = const 1_u64; + _37 = const 1_u64 as u16 (IntToInt); + StorageDead(_38); _36 = opaque::(move _37) -> [return: bb12, unwind unreachable]; } @@ -265,11 +280,12 @@ StorageDead(_36); StorageLive(_39); StorageLive(_40); -- StorageLive(_41); + StorageLive(_41); - _41 = _2; - _40 = move _41 as u32 (IntToInt); -- StorageDead(_41); ++ _41 = const 1_u64; + _40 = const 1_u64 as u32 (IntToInt); + StorageDead(_41); _39 = opaque::(move _40) -> [return: bb13, unwind unreachable]; } @@ -277,22 +293,24 @@ StorageDead(_40); StorageDead(_39); StorageLive(_42); -- StorageLive(_43); + StorageLive(_43); - _43 = _2; - _42 = opaque::(move _43) -> [return: bb14, unwind unreachable]; ++ _43 = const 1_u64; + _42 = opaque::(const 1_u64) -> [return: bb14, unwind unreachable]; } bb14: { -- StorageDead(_43); + StorageDead(_43); StorageDead(_42); StorageLive(_44); StorageLive(_45); -- StorageLive(_46); + StorageLive(_46); - _46 = _2; - _45 = move _46 as i8 (IntToInt); -- StorageDead(_46); ++ _46 = const 1_u64; + _45 = const 1_u64 as i8 (IntToInt); + StorageDead(_46); _44 = opaque::(move _45) -> [return: bb15, unwind unreachable]; } @@ -301,11 +319,12 @@ StorageDead(_44); StorageLive(_47); StorageLive(_48); -- StorageLive(_49); + StorageLive(_49); - _49 = _2; - _48 = move _49 as i16 (IntToInt); -- StorageDead(_49); ++ _49 = const 1_u64; + _48 = const 1_u64 as i16 (IntToInt); + StorageDead(_49); _47 = opaque::(move _48) -> [return: bb16, unwind unreachable]; } @@ -314,11 +333,12 @@ StorageDead(_47); StorageLive(_50); StorageLive(_51); -- StorageLive(_52); + StorageLive(_52); - _52 = _2; - _51 = move _52 as i32 (IntToInt); -- StorageDead(_52); ++ _52 = const 1_u64; + _51 = const 1_u64 as i32 (IntToInt); + StorageDead(_52); _50 = opaque::(move _51) -> [return: bb17, unwind unreachable]; } @@ -327,11 +347,12 @@ StorageDead(_50); StorageLive(_53); StorageLive(_54); -- StorageLive(_55); + StorageLive(_55); - _55 = _2; - _54 = move _55 as i64 (IntToInt); -- StorageDead(_55); ++ _55 = const 1_u64; + _54 = const 1_u64 as i64 (IntToInt); + StorageDead(_55); _53 = opaque::(move _54) -> [return: bb18, unwind unreachable]; } @@ -340,11 +361,12 @@ StorageDead(_53); StorageLive(_56); StorageLive(_57); -- StorageLive(_58); + StorageLive(_58); - _58 = _2; - _57 = move _58 as f32 (IntToFloat); -- StorageDead(_58); ++ _58 = const 1_u64; + _57 = const 1_u64 as f32 (IntToFloat); + StorageDead(_58); _56 = opaque::(move _57) -> [return: bb19, unwind unreachable]; } @@ -353,11 +375,12 @@ StorageDead(_56); StorageLive(_59); StorageLive(_60); -- StorageLive(_61); + StorageLive(_61); - _61 = _2; - _60 = move _61 as f64 (IntToFloat); -- StorageDead(_61); ++ _61 = const 1_u64; + _60 = const 1_u64 as f64 (IntToFloat); + StorageDead(_61); _59 = opaque::(move _60) -> [return: bb20, unwind unreachable]; } @@ -366,11 +389,12 @@ StorageDead(_59); StorageLive(_62); StorageLive(_63); -- StorageLive(_64); + StorageLive(_64); - _64 = _3; - _63 = move _64 as u8 (FloatToInt); -- StorageDead(_64); ++ _64 = const 1f64; + _63 = const 1f64 as u8 (FloatToInt); + StorageDead(_64); _62 = opaque::(move _63) -> [return: bb21, unwind unreachable]; } @@ -379,11 +403,12 @@ StorageDead(_62); StorageLive(_65); StorageLive(_66); -- StorageLive(_67); + StorageLive(_67); - _67 = _3; - _66 = move _67 as u16 (FloatToInt); -- StorageDead(_67); ++ _67 = const 1f64; + _66 = const 1f64 as u16 (FloatToInt); + StorageDead(_67); _65 = opaque::(move _66) -> [return: bb22, unwind unreachable]; } @@ -392,11 +417,12 @@ StorageDead(_65); StorageLive(_68); StorageLive(_69); -- StorageLive(_70); + StorageLive(_70); - _70 = _3; - _69 = move _70 as u32 (FloatToInt); -- StorageDead(_70); ++ _70 = const 1f64; + _69 = const 1f64 as u32 (FloatToInt); + StorageDead(_70); _68 = opaque::(move _69) -> [return: bb23, unwind unreachable]; } @@ -405,11 +431,12 @@ StorageDead(_68); StorageLive(_71); StorageLive(_72); -- StorageLive(_73); + StorageLive(_73); - _73 = _3; - _72 = move _73 as u64 (FloatToInt); -- StorageDead(_73); ++ _73 = const 1f64; + _72 = const 1f64 as u64 (FloatToInt); + StorageDead(_73); _71 = opaque::(move _72) -> [return: bb24, unwind unreachable]; } @@ -418,11 +445,12 @@ StorageDead(_71); StorageLive(_74); StorageLive(_75); -- StorageLive(_76); + StorageLive(_76); - _76 = _3; - _75 = move _76 as i8 (FloatToInt); -- StorageDead(_76); ++ _76 = const 1f64; + _75 = const 1f64 as i8 (FloatToInt); + StorageDead(_76); _74 = opaque::(move _75) -> [return: bb25, unwind unreachable]; } @@ -431,11 +459,12 @@ StorageDead(_74); StorageLive(_77); StorageLive(_78); -- StorageLive(_79); + StorageLive(_79); - _79 = _3; - _78 = move _79 as i16 (FloatToInt); -- StorageDead(_79); ++ _79 = const 1f64; + _78 = const 1f64 as i16 (FloatToInt); + StorageDead(_79); _77 = opaque::(move _78) -> [return: bb26, unwind unreachable]; } @@ -444,11 +473,12 @@ StorageDead(_77); StorageLive(_80); StorageLive(_81); -- StorageLive(_82); + StorageLive(_82); - _82 = _3; - _81 = move _82 as i32 (FloatToInt); -- StorageDead(_82); ++ _82 = const 1f64; + _81 = const 1f64 as i32 (FloatToInt); + StorageDead(_82); _80 = opaque::(move _81) -> [return: bb27, unwind unreachable]; } @@ -457,11 +487,12 @@ StorageDead(_80); StorageLive(_83); StorageLive(_84); -- StorageLive(_85); + StorageLive(_85); - _85 = _3; - _84 = move _85 as i64 (FloatToInt); -- StorageDead(_85); ++ _85 = const 1f64; + _84 = const 1f64 as i64 (FloatToInt); + StorageDead(_85); _83 = opaque::(move _84) -> [return: bb28, unwind unreachable]; } @@ -470,11 +501,12 @@ StorageDead(_83); StorageLive(_86); StorageLive(_87); -- StorageLive(_88); + StorageLive(_88); - _88 = _3; - _87 = move _88 as f32 (FloatToFloat); -- StorageDead(_88); ++ _88 = const 1f64; + _87 = const 1f64 as f32 (FloatToFloat); + StorageDead(_88); _86 = opaque::(move _87) -> [return: bb29, unwind unreachable]; } @@ -482,19 +514,23 @@ StorageDead(_87); StorageDead(_86); StorageLive(_89); -- StorageLive(_90); + StorageLive(_90); - _90 = _3; - _89 = opaque::(move _90) -> [return: bb30, unwind unreachable]; ++ _90 = const 1f64; + _89 = opaque::(const 1f64) -> [return: bb30, unwind unreachable]; } bb30: { -- StorageDead(_90); + StorageDead(_90); StorageDead(_89); _0 = const (); - StorageDead(_3); - StorageDead(_2); - StorageDead(_1); ++ nop; ++ nop; ++ nop; return; } } diff --git a/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff b/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff index 33192ed8de033..fbdec455188ab 100644 --- a/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff @@ -105,18 +105,22 @@ bb0: { - StorageLive(_1); ++ nop; _1 = const 1_i64; - StorageLive(_2); ++ nop; _2 = const 1_u64; - StorageLive(_3); ++ nop; _3 = const 1f64; StorageLive(_4); StorageLive(_5); -- StorageLive(_6); + StorageLive(_6); - _6 = _1; - _5 = move _6 as u8 (IntToInt); -- StorageDead(_6); ++ _6 = const 1_i64; + _5 = const 1_i64 as u8 (IntToInt); + StorageDead(_6); _4 = opaque::(move _5) -> [return: bb1, unwind continue]; } @@ -125,11 +129,12 @@ StorageDead(_4); StorageLive(_7); StorageLive(_8); -- StorageLive(_9); + StorageLive(_9); - _9 = _1; - _8 = move _9 as u16 (IntToInt); -- StorageDead(_9); ++ _9 = const 1_i64; + _8 = const 1_i64 as u16 (IntToInt); + StorageDead(_9); _7 = opaque::(move _8) -> [return: bb2, unwind continue]; } @@ -138,11 +143,12 @@ StorageDead(_7); StorageLive(_10); StorageLive(_11); -- StorageLive(_12); + StorageLive(_12); - _12 = _1; - _11 = move _12 as u32 (IntToInt); -- StorageDead(_12); ++ _12 = const 1_i64; + _11 = const 1_i64 as u32 (IntToInt); + StorageDead(_12); _10 = opaque::(move _11) -> [return: bb3, unwind continue]; } @@ -151,11 +157,12 @@ StorageDead(_10); StorageLive(_13); StorageLive(_14); -- StorageLive(_15); + StorageLive(_15); - _15 = _1; - _14 = move _15 as u64 (IntToInt); -- StorageDead(_15); ++ _15 = const 1_i64; + _14 = const 1_i64 as u64 (IntToInt); + StorageDead(_15); _13 = opaque::(move _14) -> [return: bb4, unwind continue]; } @@ -164,11 +171,12 @@ StorageDead(_13); StorageLive(_16); StorageLive(_17); -- StorageLive(_18); + StorageLive(_18); - _18 = _1; - _17 = move _18 as i8 (IntToInt); -- StorageDead(_18); ++ _18 = const 1_i64; + _17 = const 1_i64 as i8 (IntToInt); + StorageDead(_18); _16 = opaque::(move _17) -> [return: bb5, unwind continue]; } @@ -177,11 +185,12 @@ StorageDead(_16); StorageLive(_19); StorageLive(_20); -- StorageLive(_21); + StorageLive(_21); - _21 = _1; - _20 = move _21 as i16 (IntToInt); -- StorageDead(_21); ++ _21 = const 1_i64; + _20 = const 1_i64 as i16 (IntToInt); + StorageDead(_21); _19 = opaque::(move _20) -> [return: bb6, unwind continue]; } @@ -190,11 +199,12 @@ StorageDead(_19); StorageLive(_22); StorageLive(_23); -- StorageLive(_24); + StorageLive(_24); - _24 = _1; - _23 = move _24 as i32 (IntToInt); -- StorageDead(_24); ++ _24 = const 1_i64; + _23 = const 1_i64 as i32 (IntToInt); + StorageDead(_24); _22 = opaque::(move _23) -> [return: bb7, unwind continue]; } @@ -202,22 +212,24 @@ StorageDead(_23); StorageDead(_22); StorageLive(_25); -- StorageLive(_26); + StorageLive(_26); - _26 = _1; - _25 = opaque::(move _26) -> [return: bb8, unwind continue]; ++ _26 = const 1_i64; + _25 = opaque::(const 1_i64) -> [return: bb8, unwind continue]; } bb8: { -- StorageDead(_26); + StorageDead(_26); StorageDead(_25); StorageLive(_27); StorageLive(_28); -- StorageLive(_29); + StorageLive(_29); - _29 = _1; - _28 = move _29 as f32 (IntToFloat); -- StorageDead(_29); ++ _29 = const 1_i64; + _28 = const 1_i64 as f32 (IntToFloat); + StorageDead(_29); _27 = opaque::(move _28) -> [return: bb9, unwind continue]; } @@ -226,11 +238,12 @@ StorageDead(_27); StorageLive(_30); StorageLive(_31); -- StorageLive(_32); + StorageLive(_32); - _32 = _1; - _31 = move _32 as f64 (IntToFloat); -- StorageDead(_32); ++ _32 = const 1_i64; + _31 = const 1_i64 as f64 (IntToFloat); + StorageDead(_32); _30 = opaque::(move _31) -> [return: bb10, unwind continue]; } @@ -239,11 +252,12 @@ StorageDead(_30); StorageLive(_33); StorageLive(_34); -- StorageLive(_35); + StorageLive(_35); - _35 = _2; - _34 = move _35 as u8 (IntToInt); -- StorageDead(_35); ++ _35 = const 1_u64; + _34 = const 1_u64 as u8 (IntToInt); + StorageDead(_35); _33 = opaque::(move _34) -> [return: bb11, unwind continue]; } @@ -252,11 +266,12 @@ StorageDead(_33); StorageLive(_36); StorageLive(_37); -- StorageLive(_38); + StorageLive(_38); - _38 = _2; - _37 = move _38 as u16 (IntToInt); -- StorageDead(_38); ++ _38 = const 1_u64; + _37 = const 1_u64 as u16 (IntToInt); + StorageDead(_38); _36 = opaque::(move _37) -> [return: bb12, unwind continue]; } @@ -265,11 +280,12 @@ StorageDead(_36); StorageLive(_39); StorageLive(_40); -- StorageLive(_41); + StorageLive(_41); - _41 = _2; - _40 = move _41 as u32 (IntToInt); -- StorageDead(_41); ++ _41 = const 1_u64; + _40 = const 1_u64 as u32 (IntToInt); + StorageDead(_41); _39 = opaque::(move _40) -> [return: bb13, unwind continue]; } @@ -277,22 +293,24 @@ StorageDead(_40); StorageDead(_39); StorageLive(_42); -- StorageLive(_43); + StorageLive(_43); - _43 = _2; - _42 = opaque::(move _43) -> [return: bb14, unwind continue]; ++ _43 = const 1_u64; + _42 = opaque::(const 1_u64) -> [return: bb14, unwind continue]; } bb14: { -- StorageDead(_43); + StorageDead(_43); StorageDead(_42); StorageLive(_44); StorageLive(_45); -- StorageLive(_46); + StorageLive(_46); - _46 = _2; - _45 = move _46 as i8 (IntToInt); -- StorageDead(_46); ++ _46 = const 1_u64; + _45 = const 1_u64 as i8 (IntToInt); + StorageDead(_46); _44 = opaque::(move _45) -> [return: bb15, unwind continue]; } @@ -301,11 +319,12 @@ StorageDead(_44); StorageLive(_47); StorageLive(_48); -- StorageLive(_49); + StorageLive(_49); - _49 = _2; - _48 = move _49 as i16 (IntToInt); -- StorageDead(_49); ++ _49 = const 1_u64; + _48 = const 1_u64 as i16 (IntToInt); + StorageDead(_49); _47 = opaque::(move _48) -> [return: bb16, unwind continue]; } @@ -314,11 +333,12 @@ StorageDead(_47); StorageLive(_50); StorageLive(_51); -- StorageLive(_52); + StorageLive(_52); - _52 = _2; - _51 = move _52 as i32 (IntToInt); -- StorageDead(_52); ++ _52 = const 1_u64; + _51 = const 1_u64 as i32 (IntToInt); + StorageDead(_52); _50 = opaque::(move _51) -> [return: bb17, unwind continue]; } @@ -327,11 +347,12 @@ StorageDead(_50); StorageLive(_53); StorageLive(_54); -- StorageLive(_55); + StorageLive(_55); - _55 = _2; - _54 = move _55 as i64 (IntToInt); -- StorageDead(_55); ++ _55 = const 1_u64; + _54 = const 1_u64 as i64 (IntToInt); + StorageDead(_55); _53 = opaque::(move _54) -> [return: bb18, unwind continue]; } @@ -340,11 +361,12 @@ StorageDead(_53); StorageLive(_56); StorageLive(_57); -- StorageLive(_58); + StorageLive(_58); - _58 = _2; - _57 = move _58 as f32 (IntToFloat); -- StorageDead(_58); ++ _58 = const 1_u64; + _57 = const 1_u64 as f32 (IntToFloat); + StorageDead(_58); _56 = opaque::(move _57) -> [return: bb19, unwind continue]; } @@ -353,11 +375,12 @@ StorageDead(_56); StorageLive(_59); StorageLive(_60); -- StorageLive(_61); + StorageLive(_61); - _61 = _2; - _60 = move _61 as f64 (IntToFloat); -- StorageDead(_61); ++ _61 = const 1_u64; + _60 = const 1_u64 as f64 (IntToFloat); + StorageDead(_61); _59 = opaque::(move _60) -> [return: bb20, unwind continue]; } @@ -366,11 +389,12 @@ StorageDead(_59); StorageLive(_62); StorageLive(_63); -- StorageLive(_64); + StorageLive(_64); - _64 = _3; - _63 = move _64 as u8 (FloatToInt); -- StorageDead(_64); ++ _64 = const 1f64; + _63 = const 1f64 as u8 (FloatToInt); + StorageDead(_64); _62 = opaque::(move _63) -> [return: bb21, unwind continue]; } @@ -379,11 +403,12 @@ StorageDead(_62); StorageLive(_65); StorageLive(_66); -- StorageLive(_67); + StorageLive(_67); - _67 = _3; - _66 = move _67 as u16 (FloatToInt); -- StorageDead(_67); ++ _67 = const 1f64; + _66 = const 1f64 as u16 (FloatToInt); + StorageDead(_67); _65 = opaque::(move _66) -> [return: bb22, unwind continue]; } @@ -392,11 +417,12 @@ StorageDead(_65); StorageLive(_68); StorageLive(_69); -- StorageLive(_70); + StorageLive(_70); - _70 = _3; - _69 = move _70 as u32 (FloatToInt); -- StorageDead(_70); ++ _70 = const 1f64; + _69 = const 1f64 as u32 (FloatToInt); + StorageDead(_70); _68 = opaque::(move _69) -> [return: bb23, unwind continue]; } @@ -405,11 +431,12 @@ StorageDead(_68); StorageLive(_71); StorageLive(_72); -- StorageLive(_73); + StorageLive(_73); - _73 = _3; - _72 = move _73 as u64 (FloatToInt); -- StorageDead(_73); ++ _73 = const 1f64; + _72 = const 1f64 as u64 (FloatToInt); + StorageDead(_73); _71 = opaque::(move _72) -> [return: bb24, unwind continue]; } @@ -418,11 +445,12 @@ StorageDead(_71); StorageLive(_74); StorageLive(_75); -- StorageLive(_76); + StorageLive(_76); - _76 = _3; - _75 = move _76 as i8 (FloatToInt); -- StorageDead(_76); ++ _76 = const 1f64; + _75 = const 1f64 as i8 (FloatToInt); + StorageDead(_76); _74 = opaque::(move _75) -> [return: bb25, unwind continue]; } @@ -431,11 +459,12 @@ StorageDead(_74); StorageLive(_77); StorageLive(_78); -- StorageLive(_79); + StorageLive(_79); - _79 = _3; - _78 = move _79 as i16 (FloatToInt); -- StorageDead(_79); ++ _79 = const 1f64; + _78 = const 1f64 as i16 (FloatToInt); + StorageDead(_79); _77 = opaque::(move _78) -> [return: bb26, unwind continue]; } @@ -444,11 +473,12 @@ StorageDead(_77); StorageLive(_80); StorageLive(_81); -- StorageLive(_82); + StorageLive(_82); - _82 = _3; - _81 = move _82 as i32 (FloatToInt); -- StorageDead(_82); ++ _82 = const 1f64; + _81 = const 1f64 as i32 (FloatToInt); + StorageDead(_82); _80 = opaque::(move _81) -> [return: bb27, unwind continue]; } @@ -457,11 +487,12 @@ StorageDead(_80); StorageLive(_83); StorageLive(_84); -- StorageLive(_85); + StorageLive(_85); - _85 = _3; - _84 = move _85 as i64 (FloatToInt); -- StorageDead(_85); ++ _85 = const 1f64; + _84 = const 1f64 as i64 (FloatToInt); + StorageDead(_85); _83 = opaque::(move _84) -> [return: bb28, unwind continue]; } @@ -470,11 +501,12 @@ StorageDead(_83); StorageLive(_86); StorageLive(_87); -- StorageLive(_88); + StorageLive(_88); - _88 = _3; - _87 = move _88 as f32 (FloatToFloat); -- StorageDead(_88); ++ _88 = const 1f64; + _87 = const 1f64 as f32 (FloatToFloat); + StorageDead(_88); _86 = opaque::(move _87) -> [return: bb29, unwind continue]; } @@ -482,19 +514,23 @@ StorageDead(_87); StorageDead(_86); StorageLive(_89); -- StorageLive(_90); + StorageLive(_90); - _90 = _3; - _89 = opaque::(move _90) -> [return: bb30, unwind continue]; ++ _90 = const 1f64; + _89 = opaque::(const 1f64) -> [return: bb30, unwind continue]; } bb30: { -- StorageDead(_90); + StorageDead(_90); StorageDead(_89); _0 = const (); - StorageDead(_3); - StorageDead(_2); - StorageDead(_1); ++ nop; ++ nop; ++ nop; return; } } diff --git a/tests/mir-opt/gvn.dereferences.GVN.panic-abort.diff b/tests/mir-opt/gvn.dereferences.GVN.panic-abort.diff index ee320cf678701..46bf13985daf8 100644 --- a/tests/mir-opt/gvn.dereferences.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.dereferences.GVN.panic-abort.diff @@ -116,6 +116,7 @@ _18 = &(*_1); StorageLive(_19); - StorageLive(_20); ++ nop; _20 = (*_18); - _19 = opaque::(move _20) -> [return: bb7, unwind unreachable]; + _19 = opaque::(_20) -> [return: bb7, unwind unreachable]; @@ -123,16 +124,18 @@ bb7: { - StorageDead(_20); ++ nop; StorageDead(_19); StorageLive(_21); -- StorageLive(_22); + StorageLive(_22); - _22 = (*_18); - _21 = opaque::(move _22) -> [return: bb8, unwind unreachable]; ++ _22 = _20; + _21 = opaque::(_20) -> [return: bb8, unwind unreachable]; } bb8: { -- StorageDead(_22); + StorageDead(_22); StorageDead(_21); StorageLive(_23); StorageLive(_24); @@ -163,6 +166,7 @@ StorageDead(_27); StorageLive(_29); - StorageLive(_30); ++ nop; _30 = ((*_3).0: u32); - _29 = opaque::(move _30) -> [return: bb12, unwind unreachable]; + _29 = opaque::(_30) -> [return: bb12, unwind unreachable]; @@ -170,16 +174,18 @@ bb12: { - StorageDead(_30); ++ nop; StorageDead(_29); StorageLive(_31); -- StorageLive(_32); + StorageLive(_32); - _32 = ((*_3).0: u32); - _31 = opaque::(move _32) -> [return: bb13, unwind unreachable]; ++ _32 = _30; + _31 = opaque::(_30) -> [return: bb13, unwind unreachable]; } bb13: { -- StorageDead(_32); + StorageDead(_32); StorageDead(_31); _0 = const (); StorageDead(_18); diff --git a/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff b/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff index f627b4d59887a..3e731ead859e6 100644 --- a/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff @@ -116,6 +116,7 @@ _18 = &(*_1); StorageLive(_19); - StorageLive(_20); ++ nop; _20 = (*_18); - _19 = opaque::(move _20) -> [return: bb7, unwind continue]; + _19 = opaque::(_20) -> [return: bb7, unwind continue]; @@ -123,16 +124,18 @@ bb7: { - StorageDead(_20); ++ nop; StorageDead(_19); StorageLive(_21); -- StorageLive(_22); + StorageLive(_22); - _22 = (*_18); - _21 = opaque::(move _22) -> [return: bb8, unwind continue]; ++ _22 = _20; + _21 = opaque::(_20) -> [return: bb8, unwind continue]; } bb8: { -- StorageDead(_22); + StorageDead(_22); StorageDead(_21); StorageLive(_23); StorageLive(_24); @@ -163,6 +166,7 @@ StorageDead(_27); StorageLive(_29); - StorageLive(_30); ++ nop; _30 = ((*_3).0: u32); - _29 = opaque::(move _30) -> [return: bb12, unwind continue]; + _29 = opaque::(_30) -> [return: bb12, unwind continue]; @@ -170,16 +174,18 @@ bb12: { - StorageDead(_30); ++ nop; StorageDead(_29); StorageLive(_31); -- StorageLive(_32); + StorageLive(_32); - _32 = ((*_3).0: u32); - _31 = opaque::(move _32) -> [return: bb13, unwind continue]; ++ _32 = _30; + _31 = opaque::(_30) -> [return: bb13, unwind continue]; } bb13: { -- StorageDead(_32); + StorageDead(_32); StorageDead(_31); _0 = const (); StorageDead(_18); diff --git a/tests/mir-opt/gvn.multiple_branches.GVN.panic-abort.diff b/tests/mir-opt/gvn.multiple_branches.GVN.panic-abort.diff index 0a66900283b61..29ca1ba5902e1 100644 --- a/tests/mir-opt/gvn.multiple_branches.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.multiple_branches.GVN.panic-abort.diff @@ -39,9 +39,9 @@ let mut _34: u8; bb0: { -- StorageLive(_4); -- StorageLive(_5); -- _5 = _1; + StorageLive(_4); + StorageLive(_5); + _5 = _1; - switchInt(move _5) -> [0: bb4, otherwise: bb1]; + switchInt(_1) -> [0: bb4, otherwise: bb1]; } @@ -49,121 +49,130 @@ bb1: { StorageLive(_6); - StorageLive(_7); -- StorageLive(_8); -- _8 = _2; -- StorageLive(_9); -- _9 = _3; ++ nop; + 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); + StorageDead(_9); + StorageDead(_8); +- _6 = opaque::(move _7) -> [return: bb2, unwind unreachable]; + _6 = opaque::(_7) -> [return: bb2, unwind unreachable]; } bb2: { - StorageDead(_7); ++ nop; StorageDead(_6); StorageLive(_10); -- StorageLive(_11); -- StorageLive(_12); -- _12 = _2; -- StorageLive(_13); -- _13 = _3; + StorageLive(_11); + StorageLive(_12); + _12 = _2; + StorageLive(_13); + _13 = _3; - _11 = Add(move _12, move _13); -- StorageDead(_13); -- StorageDead(_12); ++ _11 = _7; + StorageDead(_13); + StorageDead(_12); - _10 = opaque::(move _11) -> [return: bb3, unwind unreachable]; + _10 = opaque::(_7) -> [return: bb3, unwind unreachable]; } bb3: { -- StorageDead(_11); + StorageDead(_11); StorageDead(_10); -- _4 = const (); + _4 = const (); goto -> bb7; } bb4: { StorageLive(_14); - StorageLive(_15); -- StorageLive(_16); -- _16 = _2; -- StorageLive(_17); -- _17 = _3; ++ nop; + 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); + StorageDead(_17); + StorageDead(_16); +- _14 = opaque::(move _15) -> [return: bb5, unwind unreachable]; + _14 = opaque::(_15) -> [return: bb5, unwind unreachable]; } bb5: { - StorageDead(_15); ++ nop; StorageDead(_14); StorageLive(_18); -- StorageLive(_19); -- StorageLive(_20); -- _20 = _2; -- StorageLive(_21); -- _21 = _3; + StorageLive(_19); + StorageLive(_20); + _20 = _2; + StorageLive(_21); + _21 = _3; - _19 = Add(move _20, move _21); -- StorageDead(_21); -- StorageDead(_20); ++ _19 = _15; + StorageDead(_21); + StorageDead(_20); - _18 = opaque::(move _19) -> [return: bb6, unwind unreachable]; + _18 = opaque::(_15) -> [return: bb6, unwind unreachable]; } bb6: { -- StorageDead(_19); + StorageDead(_19); StorageDead(_18); -- _4 = const (); + _4 = const (); goto -> bb7; } bb7: { -- StorageDead(_5); -- StorageDead(_4); + StorageDead(_5); + StorageDead(_4); StorageLive(_22); - StorageLive(_23); -- StorageLive(_24); -- _24 = _2; -- StorageLive(_25); -- _25 = _3; ++ nop; + 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); + StorageDead(_25); + StorageDead(_24); +- _22 = opaque::(move _23) -> [return: bb8, unwind unreachable]; + _22 = opaque::(_23) -> [return: bb8, unwind unreachable]; } bb8: { - StorageDead(_23); ++ nop; StorageDead(_22); -- StorageLive(_26); -- _26 = _1; + 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; + StorageLive(_28); + StorageLive(_29); + _29 = _2; + StorageLive(_30); + _30 = _3; - _28 = Add(move _29, move _30); -- StorageDead(_30); -- StorageDead(_29); ++ _28 = _23; + StorageDead(_30); + StorageDead(_29); - _27 = opaque::(move _28) -> [return: bb10, unwind unreachable]; + _27 = opaque::(_23) -> [return: bb10, unwind unreachable]; } bb10: { -- StorageDead(_28); + StorageDead(_28); StorageDead(_27); _0 = const (); goto -> bb13; @@ -171,27 +180,28 @@ bb11: { StorageLive(_31); -- StorageLive(_32); -- StorageLive(_33); -- _33 = _2; -- StorageLive(_34); -- _34 = _3; + StorageLive(_32); + StorageLive(_33); + _33 = _2; + StorageLive(_34); + _34 = _3; - _32 = Add(move _33, move _34); -- StorageDead(_34); -- StorageDead(_33); ++ _32 = _23; + StorageDead(_34); + StorageDead(_33); - _31 = opaque::(move _32) -> [return: bb12, unwind unreachable]; + _31 = opaque::(_23) -> [return: bb12, unwind unreachable]; } bb12: { -- StorageDead(_32); + StorageDead(_32); StorageDead(_31); _0 = const (); goto -> bb13; } bb13: { -- StorageDead(_26); + 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 index 0199f2720a989..5394dc8be8a04 100644 --- a/tests/mir-opt/gvn.multiple_branches.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.multiple_branches.GVN.panic-unwind.diff @@ -39,9 +39,9 @@ let mut _34: u8; bb0: { -- StorageLive(_4); -- StorageLive(_5); -- _5 = _1; + StorageLive(_4); + StorageLive(_5); + _5 = _1; - switchInt(move _5) -> [0: bb4, otherwise: bb1]; + switchInt(_1) -> [0: bb4, otherwise: bb1]; } @@ -49,121 +49,130 @@ bb1: { StorageLive(_6); - StorageLive(_7); -- StorageLive(_8); -- _8 = _2; -- StorageLive(_9); -- _9 = _3; ++ nop; + 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); + StorageDead(_9); + StorageDead(_8); +- _6 = opaque::(move _7) -> [return: bb2, unwind continue]; + _6 = opaque::(_7) -> [return: bb2, unwind continue]; } bb2: { - StorageDead(_7); ++ nop; StorageDead(_6); StorageLive(_10); -- StorageLive(_11); -- StorageLive(_12); -- _12 = _2; -- StorageLive(_13); -- _13 = _3; + StorageLive(_11); + StorageLive(_12); + _12 = _2; + StorageLive(_13); + _13 = _3; - _11 = Add(move _12, move _13); -- StorageDead(_13); -- StorageDead(_12); ++ _11 = _7; + StorageDead(_13); + StorageDead(_12); - _10 = opaque::(move _11) -> [return: bb3, unwind continue]; + _10 = opaque::(_7) -> [return: bb3, unwind continue]; } bb3: { -- StorageDead(_11); + StorageDead(_11); StorageDead(_10); -- _4 = const (); + _4 = const (); goto -> bb7; } bb4: { StorageLive(_14); - StorageLive(_15); -- StorageLive(_16); -- _16 = _2; -- StorageLive(_17); -- _17 = _3; ++ nop; + 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); + StorageDead(_17); + StorageDead(_16); +- _14 = opaque::(move _15) -> [return: bb5, unwind continue]; + _14 = opaque::(_15) -> [return: bb5, unwind continue]; } bb5: { - StorageDead(_15); ++ nop; StorageDead(_14); StorageLive(_18); -- StorageLive(_19); -- StorageLive(_20); -- _20 = _2; -- StorageLive(_21); -- _21 = _3; + StorageLive(_19); + StorageLive(_20); + _20 = _2; + StorageLive(_21); + _21 = _3; - _19 = Add(move _20, move _21); -- StorageDead(_21); -- StorageDead(_20); ++ _19 = _15; + StorageDead(_21); + StorageDead(_20); - _18 = opaque::(move _19) -> [return: bb6, unwind continue]; + _18 = opaque::(_15) -> [return: bb6, unwind continue]; } bb6: { -- StorageDead(_19); + StorageDead(_19); StorageDead(_18); -- _4 = const (); + _4 = const (); goto -> bb7; } bb7: { -- StorageDead(_5); -- StorageDead(_4); + StorageDead(_5); + StorageDead(_4); StorageLive(_22); - StorageLive(_23); -- StorageLive(_24); -- _24 = _2; -- StorageLive(_25); -- _25 = _3; ++ nop; + 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); + StorageDead(_25); + StorageDead(_24); +- _22 = opaque::(move _23) -> [return: bb8, unwind continue]; + _22 = opaque::(_23) -> [return: bb8, unwind continue]; } bb8: { - StorageDead(_23); ++ nop; StorageDead(_22); -- StorageLive(_26); -- _26 = _1; + 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; + StorageLive(_28); + StorageLive(_29); + _29 = _2; + StorageLive(_30); + _30 = _3; - _28 = Add(move _29, move _30); -- StorageDead(_30); -- StorageDead(_29); ++ _28 = _23; + StorageDead(_30); + StorageDead(_29); - _27 = opaque::(move _28) -> [return: bb10, unwind continue]; + _27 = opaque::(_23) -> [return: bb10, unwind continue]; } bb10: { -- StorageDead(_28); + StorageDead(_28); StorageDead(_27); _0 = const (); goto -> bb13; @@ -171,27 +180,28 @@ bb11: { StorageLive(_31); -- StorageLive(_32); -- StorageLive(_33); -- _33 = _2; -- StorageLive(_34); -- _34 = _3; + StorageLive(_32); + StorageLive(_33); + _33 = _2; + StorageLive(_34); + _34 = _3; - _32 = Add(move _33, move _34); -- StorageDead(_34); -- StorageDead(_33); ++ _32 = _23; + StorageDead(_34); + StorageDead(_33); - _31 = opaque::(move _32) -> [return: bb12, unwind continue]; + _31 = opaque::(_23) -> [return: bb12, unwind continue]; } bb12: { -- StorageDead(_32); + StorageDead(_32); StorageDead(_31); _0 = const (); goto -> bb13; } bb13: { -- StorageDead(_26); + StorageDead(_26); return; } } diff --git a/tests/mir-opt/gvn.repeated_index.GVN.panic-abort.diff b/tests/mir-opt/gvn.repeated_index.GVN.panic-abort.diff index 4c29523d6b282..6e542d7f964ce 100644 --- a/tests/mir-opt/gvn.repeated_index.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.repeated_index.GVN.panic-abort.diff @@ -23,11 +23,11 @@ bb0: { StorageLive(_3); -- StorageLive(_4); -- _4 = _1; + StorageLive(_4); + _4 = _1; - _3 = [move _4; N]; -- StorageDead(_4); + _3 = [_1; N]; + StorageDead(_4); StorageLive(_5); StorageLive(_6); StorageLive(_7); @@ -55,6 +55,7 @@ - _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]; ++ _13 = _8; + _14 = Lt(_2, _8); + assert(move _14, "index out of bounds: the length is {} but the index is {}", _8, _2) -> [success: bb3, unwind unreachable]; } diff --git a/tests/mir-opt/gvn.repeated_index.GVN.panic-unwind.diff b/tests/mir-opt/gvn.repeated_index.GVN.panic-unwind.diff index e44f54cf3cf3c..a07cd49ec7c6f 100644 --- a/tests/mir-opt/gvn.repeated_index.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.repeated_index.GVN.panic-unwind.diff @@ -23,11 +23,11 @@ bb0: { StorageLive(_3); -- StorageLive(_4); -- _4 = _1; + StorageLive(_4); + _4 = _1; - _3 = [move _4; N]; -- StorageDead(_4); + _3 = [_1; N]; + StorageDead(_4); StorageLive(_5); StorageLive(_6); StorageLive(_7); @@ -55,6 +55,7 @@ - _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]; ++ _13 = _8; + _14 = Lt(_2, _8); + assert(move _14, "index out of bounds: the length is {} but the index is {}", _8, _2) -> [success: bb3, unwind continue]; } diff --git a/tests/mir-opt/gvn.slices.GVN.panic-abort.diff b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff index de3d28d057594..d924c70d617dd 100644 --- a/tests/mir-opt/gvn.slices.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff @@ -85,30 +85,32 @@ bb0: { - StorageLive(_1); ++ nop; _1 = const "my favourite slice"; StorageLive(_2); -- StorageLive(_3); -- _3 = _1; + 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(_3); StorageDead(_2); StorageLive(_4); _4 = _1; StorageLive(_5); -- StorageLive(_6); + StorageLive(_6); - _6 = _4; - _5 = opaque::<&str>(move _6) -> [return: bb2, unwind unreachable]; ++ _6 = _1; + _5 = opaque::<&str>(_1) -> [return: bb2, unwind unreachable]; } bb2: { -- StorageDead(_6); + StorageDead(_6); StorageDead(_5); -- StorageLive(_7); + StorageLive(_7); StorageLive(_8); StorageLive(_9); StorageLive(_10); @@ -149,22 +151,23 @@ bb5: { StorageDead(_19); StorageDead(_18); -- _7 = const (); + _7 = const (); StorageDead(_17); StorageDead(_16); StorageDead(_15); StorageDead(_13); StorageDead(_10); StorageDead(_8); -- StorageDead(_7); + StorageDead(_7); - StorageLive(_29); ++ nop; StorageLive(_30); _30 = &(*_1); _29 = move _30 as &[u8] (Transmute); StorageDead(_30); StorageLive(_31); -- StorageLive(_32); -- _32 = _29; + StorageLive(_32); + _32 = _29; - _31 = opaque::<&[u8]>(move _32) -> [return: bb7, unwind unreachable]; + _31 = opaque::<&[u8]>(_29) -> [return: bb7, unwind unreachable]; } @@ -173,10 +176,12 @@ StorageDead(_19); StorageDead(_18); - StorageLive(_21); ++ nop; _21 = core::panicking::AssertKind::Eq; StorageLive(_22); -- StorageLive(_23); + StorageLive(_23); - _23 = move _21; ++ _23 = _21; StorageLive(_24); StorageLive(_25); _25 = &(*_15); @@ -192,9 +197,9 @@ } bb7: { -- StorageDead(_32); + StorageDead(_32); StorageDead(_31); -- StorageLive(_33); + StorageLive(_33); StorageLive(_34); StorageLive(_35); StorageLive(_36); @@ -235,18 +240,20 @@ bb10: { StorageDead(_45); StorageDead(_44); -- _33 = const (); + _33 = const (); StorageDead(_43); StorageDead(_42); StorageDead(_41); StorageDead(_39); StorageDead(_36); StorageDead(_34); -- StorageDead(_33); + StorageDead(_33); _0 = const (); - StorageDead(_29); ++ nop; StorageDead(_4); - StorageDead(_1); ++ nop; return; } @@ -254,10 +261,12 @@ StorageDead(_45); StorageDead(_44); - StorageLive(_47); ++ nop; _47 = core::panicking::AssertKind::Eq; StorageLive(_48); -- StorageLive(_49); + StorageLive(_49); - _49 = move _47; ++ _49 = _47; StorageLive(_50); StorageLive(_51); _51 = &(*_41); diff --git a/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff b/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff index f22bb25436f05..63225aa0a1016 100644 --- a/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff @@ -85,30 +85,32 @@ bb0: { - StorageLive(_1); ++ nop; _1 = const "my favourite slice"; StorageLive(_2); -- StorageLive(_3); -- _3 = _1; + 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(_3); StorageDead(_2); StorageLive(_4); _4 = _1; StorageLive(_5); -- StorageLive(_6); + StorageLive(_6); - _6 = _4; - _5 = opaque::<&str>(move _6) -> [return: bb2, unwind continue]; ++ _6 = _1; + _5 = opaque::<&str>(_1) -> [return: bb2, unwind continue]; } bb2: { -- StorageDead(_6); + StorageDead(_6); StorageDead(_5); -- StorageLive(_7); + StorageLive(_7); StorageLive(_8); StorageLive(_9); StorageLive(_10); @@ -149,22 +151,23 @@ bb5: { StorageDead(_19); StorageDead(_18); -- _7 = const (); + _7 = const (); StorageDead(_17); StorageDead(_16); StorageDead(_15); StorageDead(_13); StorageDead(_10); StorageDead(_8); -- StorageDead(_7); + StorageDead(_7); - StorageLive(_29); ++ nop; StorageLive(_30); _30 = &(*_1); _29 = move _30 as &[u8] (Transmute); StorageDead(_30); StorageLive(_31); -- StorageLive(_32); -- _32 = _29; + StorageLive(_32); + _32 = _29; - _31 = opaque::<&[u8]>(move _32) -> [return: bb7, unwind continue]; + _31 = opaque::<&[u8]>(_29) -> [return: bb7, unwind continue]; } @@ -173,10 +176,12 @@ StorageDead(_19); StorageDead(_18); - StorageLive(_21); ++ nop; _21 = core::panicking::AssertKind::Eq; StorageLive(_22); -- StorageLive(_23); + StorageLive(_23); - _23 = move _21; ++ _23 = _21; StorageLive(_24); StorageLive(_25); _25 = &(*_15); @@ -192,9 +197,9 @@ } bb7: { -- StorageDead(_32); + StorageDead(_32); StorageDead(_31); -- StorageLive(_33); + StorageLive(_33); StorageLive(_34); StorageLive(_35); StorageLive(_36); @@ -235,18 +240,20 @@ bb10: { StorageDead(_45); StorageDead(_44); -- _33 = const (); + _33 = const (); StorageDead(_43); StorageDead(_42); StorageDead(_41); StorageDead(_39); StorageDead(_36); StorageDead(_34); -- StorageDead(_33); + StorageDead(_33); _0 = const (); - StorageDead(_29); ++ nop; StorageDead(_4); - StorageDead(_1); ++ nop; return; } @@ -254,10 +261,12 @@ StorageDead(_45); StorageDead(_44); - StorageLive(_47); ++ nop; _47 = core::panicking::AssertKind::Eq; StorageLive(_48); -- StorageLive(_49); + StorageLive(_49); - _49 = move _47; ++ _49 = _47; StorageLive(_50); StorageLive(_51); _51 = &(*_41); diff --git a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff index bf866e2f4d22f..6c8513e32816a 100644 --- a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff @@ -197,61 +197,68 @@ bb0: { StorageLive(_4); - StorageLive(_5); -- StorageLive(_6); -- _6 = _1; -- StorageLive(_7); -- _7 = _2; ++ nop; + 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); + StorageDead(_7); + StorageDead(_6); +- _4 = opaque::(move _5) -> [return: bb1, unwind unreachable]; + _4 = opaque::(_5) -> [return: bb1, unwind unreachable]; } bb1: { - StorageDead(_5); ++ nop; StorageDead(_4); StorageLive(_8); - StorageLive(_9); -- StorageLive(_10); -- _10 = _1; -- StorageLive(_11); -- _11 = _2; ++ nop; + 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); + StorageDead(_11); + StorageDead(_10); +- _8 = opaque::(move _9) -> [return: bb2, unwind unreachable]; + _8 = opaque::(_9) -> [return: bb2, unwind unreachable]; } bb2: { - StorageDead(_9); ++ nop; StorageDead(_8); StorageLive(_12); - StorageLive(_13); -- StorageLive(_14); -- _14 = _1; -- StorageLive(_15); -- _15 = _2; ++ nop; + 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); + StorageDead(_15); + StorageDead(_14); +- _12 = opaque::(move _13) -> [return: bb3, unwind unreachable]; + _12 = opaque::(_13) -> [return: bb3, unwind unreachable]; } bb3: { - StorageDead(_13); ++ nop; StorageDead(_12); StorageLive(_16); - StorageLive(_17); -- StorageLive(_18); -- _18 = _1; -- StorageLive(_19); -- _19 = _2; ++ nop; + 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); @@ -260,131 +267,145 @@ bb4: { - _17 = Div(move _18, move _19); -- StorageDead(_19); -- StorageDead(_18); -- _16 = opaque::(move _17) -> [return: bb5, unwind unreachable]; + _17 = Div(_1, _2); + StorageDead(_19); + StorageDead(_18); +- _16 = opaque::(move _17) -> [return: bb5, unwind unreachable]; + _16 = opaque::(_17) -> [return: bb5, unwind unreachable]; } bb5: { - StorageDead(_17); ++ nop; StorageDead(_16); StorageLive(_21); - StorageLive(_22); -- StorageLive(_23); -- _23 = _1; -- StorageLive(_24); -- _24 = _2; ++ nop; + 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]; ++ _25 = _20; + 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); + StorageDead(_24); + StorageDead(_23); +- _21 = opaque::(move _22) -> [return: bb7, unwind unreachable]; + _21 = opaque::(_22) -> [return: bb7, unwind unreachable]; } bb7: { - StorageDead(_22); ++ nop; StorageDead(_21); StorageLive(_26); - StorageLive(_27); -- StorageLive(_28); -- _28 = _1; -- StorageLive(_29); -- _29 = _2; ++ nop; + 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); + StorageDead(_29); + StorageDead(_28); +- _26 = opaque::(move _27) -> [return: bb8, unwind unreachable]; + _26 = opaque::(_27) -> [return: bb8, unwind unreachable]; } bb8: { - StorageDead(_27); ++ nop; StorageDead(_26); StorageLive(_30); - StorageLive(_31); -- StorageLive(_32); -- _32 = _1; -- StorageLive(_33); -- _33 = _2; ++ nop; + 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); + StorageDead(_33); + StorageDead(_32); +- _30 = opaque::(move _31) -> [return: bb9, unwind unreachable]; + _30 = opaque::(_31) -> [return: bb9, unwind unreachable]; } bb9: { - StorageDead(_31); ++ nop; StorageDead(_30); StorageLive(_34); - StorageLive(_35); -- StorageLive(_36); -- _36 = _1; -- StorageLive(_37); -- _37 = _2; ++ nop; + 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); + StorageDead(_37); + StorageDead(_36); +- _34 = opaque::(move _35) -> [return: bb10, unwind unreachable]; + _34 = opaque::(_35) -> [return: bb10, unwind unreachable]; } bb10: { - StorageDead(_35); ++ nop; StorageDead(_34); StorageLive(_38); - StorageLive(_39); -- StorageLive(_40); -- _40 = _1; -- StorageLive(_41); -- _41 = _2; ++ nop; + 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); + StorageDead(_41); + StorageDead(_40); +- _38 = opaque::(move _39) -> [return: bb11, unwind unreachable]; + _38 = opaque::(_39) -> [return: bb11, unwind unreachable]; } bb11: { - StorageDead(_39); ++ nop; StorageDead(_38); StorageLive(_42); - StorageLive(_43); -- StorageLive(_44); -- _44 = _1; -- StorageLive(_45); -- _45 = _2; ++ nop; + 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); + StorageDead(_45); + StorageDead(_44); +- _42 = opaque::(move _43) -> [return: bb12, unwind unreachable]; + _42 = opaque::(_43) -> [return: bb12, unwind unreachable]; } bb12: { - StorageDead(_43); ++ nop; StorageDead(_42); StorageLive(_46); StorageLive(_47); -- StorageLive(_48); -- _48 = _1; + StorageLive(_48); + _48 = _1; - _47 = move _48 as u32 (IntToInt); -- StorageDead(_48); + _47 = _1 as u32 (IntToInt); + StorageDead(_48); _46 = opaque::(move _47) -> [return: bb13, unwind unreachable]; } @@ -393,11 +414,11 @@ StorageDead(_46); StorageLive(_49); StorageLive(_50); -- StorageLive(_51); -- _51 = _1; + StorageLive(_51); + _51 = _1; - _50 = move _51 as f32 (IntToFloat); -- StorageDead(_51); + _50 = _1 as f32 (IntToFloat); + StorageDead(_51); _49 = opaque::(move _50) -> [return: bb14, unwind unreachable]; } @@ -406,25 +427,29 @@ StorageDead(_49); StorageLive(_52); - StorageLive(_53); -- StorageLive(_54); -- _54 = _1; ++ nop; + StorageLive(_54); + _54 = _1; - _53 = S::(move _54); -- StorageDead(_54); -- _52 = opaque::>(move _53) -> [return: bb15, unwind unreachable]; + _53 = S::(_1); + StorageDead(_54); +- _52 = opaque::>(move _53) -> [return: bb15, unwind unreachable]; + _52 = opaque::>(_53) -> [return: bb15, unwind unreachable]; } bb15: { - StorageDead(_53); ++ nop; StorageDead(_52); StorageLive(_55); - StorageLive(_56); -- StorageLive(_57); -- StorageLive(_58); -- _58 = _1; ++ nop; + StorageLive(_57); + StorageLive(_58); + _58 = _1; - _57 = S::(move _58); -- StorageDead(_58); ++ _57 = _53; + StorageDead(_58); - _56 = (_57.0: u64); - _55 = opaque::(move _56) -> [return: bb16, unwind unreachable]; + _56 = (_53.0: u64); @@ -433,24 +458,26 @@ bb16: { - StorageDead(_56); -- StorageDead(_57); ++ nop; + StorageDead(_57); StorageDead(_55); StorageLive(_59); StorageLive(_60); -- StorageLive(_61); -- StorageLive(_62); -- _62 = _1; -- StorageLive(_63); -- _63 = _2; + StorageLive(_61); + StorageLive(_62); + _62 = _1; + StorageLive(_63); + _63 = _2; - _61 = Add(move _62, move _63); -- StorageDead(_63); -- StorageDead(_62); ++ _61 = _5; + StorageDead(_63); + StorageDead(_62); StorageLive(_64); _64 = _3; - _60 = Add(move _61, move _64); + _60 = Add(_5, move _64); StorageDead(_64); -- StorageDead(_61); + StorageDead(_61); _59 = opaque::(move _60) -> [return: bb17, unwind unreachable]; } @@ -459,20 +486,21 @@ StorageDead(_59); StorageLive(_65); StorageLive(_66); -- StorageLive(_67); -- StorageLive(_68); -- _68 = _1; -- StorageLive(_69); -- _69 = _2; + StorageLive(_67); + StorageLive(_68); + _68 = _1; + StorageLive(_69); + _69 = _2; - _67 = Mul(move _68, move _69); -- StorageDead(_69); -- StorageDead(_68); ++ _67 = _9; + StorageDead(_69); + StorageDead(_68); StorageLive(_70); _70 = _3; - _66 = Add(move _67, move _70); + _66 = Add(_9, move _70); StorageDead(_70); -- StorageDead(_67); + StorageDead(_67); _65 = opaque::(move _66) -> [return: bb18, unwind unreachable]; } @@ -481,20 +509,21 @@ StorageDead(_65); StorageLive(_71); StorageLive(_72); -- StorageLive(_73); -- StorageLive(_74); -- _74 = _1; -- StorageLive(_75); -- _75 = _2; + StorageLive(_73); + StorageLive(_74); + _74 = _1; + StorageLive(_75); + _75 = _2; - _73 = Sub(move _74, move _75); -- StorageDead(_75); -- StorageDead(_74); ++ _73 = _13; + StorageDead(_75); + StorageDead(_74); StorageLive(_76); _76 = _3; - _72 = Add(move _73, move _76); + _72 = Add(_13, move _76); StorageDead(_76); -- StorageDead(_73); + StorageDead(_73); _71 = opaque::(move _72) -> [return: bb19, unwind unreachable]; } @@ -503,26 +532,28 @@ StorageDead(_71); StorageLive(_77); StorageLive(_78); -- StorageLive(_79); -- StorageLive(_80); -- _80 = _1; -- StorageLive(_81); -- _81 = _2; + 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]; ++ _82 = _20; + assert(!_20, "attempt to divide `{}` by zero", _1) -> [success: bb20, unwind unreachable]; } bb20: { - _79 = Div(move _80, move _81); -- StorageDead(_81); -- StorageDead(_80); ++ _79 = _17; + StorageDead(_81); + StorageDead(_80); StorageLive(_83); _83 = _3; - _78 = Add(move _79, move _83); + _78 = Add(_17, move _83); StorageDead(_83); -- StorageDead(_79); + StorageDead(_79); _77 = opaque::(move _78) -> [return: bb21, unwind unreachable]; } @@ -531,26 +562,28 @@ StorageDead(_77); StorageLive(_84); StorageLive(_85); -- StorageLive(_86); -- StorageLive(_87); -- _87 = _1; -- StorageLive(_88); -- _88 = _2; + 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]; ++ _89 = _20; + 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); ++ _86 = _22; + StorageDead(_88); + StorageDead(_87); StorageLive(_90); _90 = _3; - _85 = Add(move _86, move _90); + _85 = Add(_22, move _90); StorageDead(_90); -- StorageDead(_86); + StorageDead(_86); _84 = opaque::(move _85) -> [return: bb23, unwind unreachable]; } @@ -559,20 +592,21 @@ StorageDead(_84); StorageLive(_91); StorageLive(_92); -- StorageLive(_93); -- StorageLive(_94); -- _94 = _1; -- StorageLive(_95); -- _95 = _2; + StorageLive(_93); + StorageLive(_94); + _94 = _1; + StorageLive(_95); + _95 = _2; - _93 = BitAnd(move _94, move _95); -- StorageDead(_95); -- StorageDead(_94); ++ _93 = _27; + StorageDead(_95); + StorageDead(_94); StorageLive(_96); _96 = _3; - _92 = Add(move _93, move _96); + _92 = Add(_27, move _96); StorageDead(_96); -- StorageDead(_93); + StorageDead(_93); _91 = opaque::(move _92) -> [return: bb24, unwind unreachable]; } @@ -581,20 +615,21 @@ StorageDead(_91); StorageLive(_97); StorageLive(_98); -- StorageLive(_99); -- StorageLive(_100); -- _100 = _1; -- StorageLive(_101); -- _101 = _2; + StorageLive(_99); + StorageLive(_100); + _100 = _1; + StorageLive(_101); + _101 = _2; - _99 = BitOr(move _100, move _101); -- StorageDead(_101); -- StorageDead(_100); ++ _99 = _31; + StorageDead(_101); + StorageDead(_100); StorageLive(_102); _102 = _3; - _98 = Add(move _99, move _102); + _98 = Add(_31, move _102); StorageDead(_102); -- StorageDead(_99); + StorageDead(_99); _97 = opaque::(move _98) -> [return: bb25, unwind unreachable]; } @@ -603,20 +638,21 @@ StorageDead(_97); StorageLive(_103); StorageLive(_104); -- StorageLive(_105); -- StorageLive(_106); -- _106 = _1; -- StorageLive(_107); -- _107 = _2; + StorageLive(_105); + StorageLive(_106); + _106 = _1; + StorageLive(_107); + _107 = _2; - _105 = BitXor(move _106, move _107); -- StorageDead(_107); -- StorageDead(_106); ++ _105 = _35; + StorageDead(_107); + StorageDead(_106); StorageLive(_108); _108 = _3; - _104 = Add(move _105, move _108); + _104 = Add(_35, move _108); StorageDead(_108); -- StorageDead(_105); + StorageDead(_105); _103 = opaque::(move _104) -> [return: bb26, unwind unreachable]; } @@ -625,20 +661,21 @@ StorageDead(_103); StorageLive(_109); StorageLive(_110); -- StorageLive(_111); -- StorageLive(_112); -- _112 = _1; -- StorageLive(_113); -- _113 = _2; + StorageLive(_111); + StorageLive(_112); + _112 = _1; + StorageLive(_113); + _113 = _2; - _111 = Shl(move _112, move _113); -- StorageDead(_113); -- StorageDead(_112); ++ _111 = _39; + StorageDead(_113); + StorageDead(_112); StorageLive(_114); _114 = _3; - _110 = Add(move _111, move _114); + _110 = Add(_39, move _114); StorageDead(_114); -- StorageDead(_111); + StorageDead(_111); _109 = opaque::(move _110) -> [return: bb27, unwind unreachable]; } @@ -647,20 +684,21 @@ StorageDead(_109); StorageLive(_115); StorageLive(_116); -- StorageLive(_117); -- StorageLive(_118); -- _118 = _1; -- StorageLive(_119); -- _119 = _2; + StorageLive(_117); + StorageLive(_118); + _118 = _1; + StorageLive(_119); + _119 = _2; - _117 = Shr(move _118, move _119); -- StorageDead(_119); -- StorageDead(_118); ++ _117 = _43; + StorageDead(_119); + StorageDead(_118); StorageLive(_120); _120 = _3; - _116 = Add(move _117, move _120); + _116 = Add(_43, move _120); StorageDead(_120); -- StorageDead(_117); + StorageDead(_117); _115 = opaque::(move _116) -> [return: bb28, unwind unreachable]; } @@ -668,68 +706,77 @@ StorageDead(_116); StorageDead(_115); StorageLive(_121); -- StorageLive(_122); -- StorageLive(_123); -- _123 = _1; + StorageLive(_122); + StorageLive(_123); + _123 = _1; - _122 = S::(move _123); -- StorageDead(_123); ++ _122 = _53; + StorageDead(_123); - _121 = opaque::>(move _122) -> [return: bb29, unwind unreachable]; + _121 = opaque::>(_53) -> [return: bb29, unwind unreachable]; } bb29: { -- StorageDead(_122); + StorageDead(_122); StorageDead(_121); StorageLive(_124); -- StorageLive(_125); -- StorageLive(_126); -- StorageLive(_127); -- _127 = _1; + StorageLive(_125); + StorageLive(_126); + StorageLive(_127); + _127 = _1; - _126 = S::(move _127); -- StorageDead(_127); ++ _126 = _53; + StorageDead(_127); - _125 = (_126.0: u64); - _124 = opaque::(move _125) -> [return: bb30, unwind unreachable]; ++ _125 = _56; + _124 = opaque::(_56) -> [return: bb30, unwind unreachable]; } bb30: { -- StorageDead(_125); -- StorageDead(_126); + StorageDead(_125); + StorageDead(_126); StorageDead(_124); StorageLive(_128); _128 = &_3; StorageLive(_129); - StorageLive(_130); - StorageLive(_131); ++ nop; ++ nop; _131 = (*_128); -- StorageLive(_132); -- _132 = _1; + StorageLive(_132); + _132 = _1; - _130 = Add(move _131, move _132); -- StorageDead(_132); ++ _130 = Add(_131, _1); + StorageDead(_132); - StorageDead(_131); - _129 = opaque::(move _130) -> [return: bb31, unwind unreachable]; -+ _130 = Add(_131, _1); ++ nop; + _129 = opaque::(_130) -> [return: bb31, unwind unreachable]; } bb31: { - StorageDead(_130); ++ nop; StorageDead(_129); StorageLive(_133); -- StorageLive(_134); -- StorageLive(_135); + StorageLive(_134); + StorageLive(_135); - _135 = (*_128); -- StorageLive(_136); -- _136 = _1; ++ _135 = _131; + StorageLive(_136); + _136 = _1; - _134 = Add(move _135, move _136); -- StorageDead(_136); -- StorageDead(_135); ++ _134 = _130; + StorageDead(_136); + StorageDead(_135); - _133 = opaque::(move _134) -> [return: bb32, unwind unreachable]; + _133 = opaque::(_130) -> [return: bb32, unwind unreachable]; } bb32: { -- StorageDead(_134); + StorageDead(_134); StorageDead(_133); StorageLive(_137); _137 = &mut _3; @@ -737,11 +784,11 @@ StorageLive(_139); StorageLive(_140); _140 = (*_137); -- StorageLive(_141); -- _141 = _1; + StorageLive(_141); + _141 = _1; - _139 = Add(move _140, move _141); -- StorageDead(_141); + _139 = Add(move _140, _1); + StorageDead(_141); StorageDead(_140); _138 = opaque::(move _139) -> [return: bb33, unwind unreachable]; } @@ -753,11 +800,11 @@ StorageLive(_143); StorageLive(_144); _144 = (*_137); -- StorageLive(_145); -- _145 = _1; + StorageLive(_145); + _145 = _1; - _143 = Add(move _144, move _145); -- StorageDead(_145); + _143 = Add(move _144, _1); + StorageDead(_145); StorageDead(_144); _142 = opaque::(move _143) -> [return: bb34, unwind unreachable]; } @@ -765,18 +812,18 @@ bb34: { StorageDead(_143); StorageDead(_142); -- StorageLive(_146); + StorageLive(_146); StorageLive(_147); _147 = &raw const _3; StorageLive(_148); StorageLive(_149); StorageLive(_150); _150 = (*_147); -- StorageLive(_151); -- _151 = _1; + StorageLive(_151); + _151 = _1; - _149 = Add(move _150, move _151); -- StorageDead(_151); + _149 = Add(move _150, _1); + StorageDead(_151); StorageDead(_150); _148 = opaque::(move _149) -> [return: bb35, unwind unreachable]; } @@ -788,11 +835,11 @@ StorageLive(_153); StorageLive(_154); _154 = (*_147); -- StorageLive(_155); -- _155 = _1; + StorageLive(_155); + _155 = _1; - _153 = Add(move _154, move _155); -- StorageDead(_155); + _153 = Add(move _154, _1); + StorageDead(_155); StorageDead(_154); _152 = opaque::(move _153) -> [return: bb36, unwind unreachable]; } @@ -806,11 +853,11 @@ StorageLive(_158); StorageLive(_159); _159 = (*_156); -- StorageLive(_160); -- _160 = _1; + StorageLive(_160); + _160 = _1; - _158 = Add(move _159, move _160); -- StorageDead(_160); + _158 = Add(move _159, _1); + StorageDead(_160); StorageDead(_159); _157 = opaque::(move _158) -> [return: bb37, unwind unreachable]; } @@ -822,11 +869,11 @@ StorageLive(_162); StorageLive(_163); _163 = (*_156); -- StorageLive(_164); -- _164 = _1; + StorageLive(_164); + _164 = _1; - _162 = Add(move _163, move _164); -- StorageDead(_164); + _162 = Add(move _163, _1); + StorageDead(_164); StorageDead(_163); _161 = opaque::(move _162) -> [return: bb38, unwind unreachable]; } @@ -834,44 +881,50 @@ bb38: { StorageDead(_162); StorageDead(_161); -- _146 = const (); + _146 = const (); StorageDead(_156); StorageDead(_147); -- StorageDead(_146); + StorageDead(_146); StorageLive(_165); _165 = &_3; StorageLive(_166); - StorageLive(_167); - StorageLive(_168); ++ nop; ++ nop; _168 = (*_165); -- StorageLive(_169); -- _169 = _1; + StorageLive(_169); + _169 = _1; - _167 = Add(move _168, move _169); -- StorageDead(_169); ++ _167 = Add(_168, _1); + StorageDead(_169); - StorageDead(_168); - _166 = opaque::(move _167) -> [return: bb39, unwind unreachable]; -+ _167 = Add(_168, _1); ++ nop; + _166 = opaque::(_167) -> [return: bb39, unwind unreachable]; } bb39: { - StorageDead(_167); ++ nop; StorageDead(_166); StorageLive(_170); -- StorageLive(_171); -- StorageLive(_172); + StorageLive(_171); + StorageLive(_172); - _172 = (*_165); -- StorageLive(_173); -- _173 = _1; ++ _172 = _168; + StorageLive(_173); + _173 = _1; - _171 = Add(move _172, move _173); -- StorageDead(_173); -- StorageDead(_172); ++ _171 = _167; + StorageDead(_173); + StorageDead(_172); - _170 = opaque::(move _171) -> [return: bb40, unwind unreachable]; + _170 = opaque::(_167) -> [return: bb40, unwind unreachable]; } bb40: { -- StorageDead(_171); + StorageDead(_171); StorageDead(_170); _0 = const (); StorageDead(_165); diff --git a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff index 68b052907192d..fb2c089827deb 100644 --- a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff @@ -197,61 +197,68 @@ bb0: { StorageLive(_4); - StorageLive(_5); -- StorageLive(_6); -- _6 = _1; -- StorageLive(_7); -- _7 = _2; ++ nop; + 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); + StorageDead(_7); + StorageDead(_6); +- _4 = opaque::(move _5) -> [return: bb1, unwind continue]; + _4 = opaque::(_5) -> [return: bb1, unwind continue]; } bb1: { - StorageDead(_5); ++ nop; StorageDead(_4); StorageLive(_8); - StorageLive(_9); -- StorageLive(_10); -- _10 = _1; -- StorageLive(_11); -- _11 = _2; ++ nop; + 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); + StorageDead(_11); + StorageDead(_10); +- _8 = opaque::(move _9) -> [return: bb2, unwind continue]; + _8 = opaque::(_9) -> [return: bb2, unwind continue]; } bb2: { - StorageDead(_9); ++ nop; StorageDead(_8); StorageLive(_12); - StorageLive(_13); -- StorageLive(_14); -- _14 = _1; -- StorageLive(_15); -- _15 = _2; ++ nop; + 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); + StorageDead(_15); + StorageDead(_14); +- _12 = opaque::(move _13) -> [return: bb3, unwind continue]; + _12 = opaque::(_13) -> [return: bb3, unwind continue]; } bb3: { - StorageDead(_13); ++ nop; StorageDead(_12); StorageLive(_16); - StorageLive(_17); -- StorageLive(_18); -- _18 = _1; -- StorageLive(_19); -- _19 = _2; ++ nop; + 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); @@ -260,131 +267,145 @@ bb4: { - _17 = Div(move _18, move _19); -- StorageDead(_19); -- StorageDead(_18); -- _16 = opaque::(move _17) -> [return: bb5, unwind continue]; + _17 = Div(_1, _2); + StorageDead(_19); + StorageDead(_18); +- _16 = opaque::(move _17) -> [return: bb5, unwind continue]; + _16 = opaque::(_17) -> [return: bb5, unwind continue]; } bb5: { - StorageDead(_17); ++ nop; StorageDead(_16); StorageLive(_21); - StorageLive(_22); -- StorageLive(_23); -- _23 = _1; -- StorageLive(_24); -- _24 = _2; ++ nop; + 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]; ++ _25 = _20; + 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); + StorageDead(_24); + StorageDead(_23); +- _21 = opaque::(move _22) -> [return: bb7, unwind continue]; + _21 = opaque::(_22) -> [return: bb7, unwind continue]; } bb7: { - StorageDead(_22); ++ nop; StorageDead(_21); StorageLive(_26); - StorageLive(_27); -- StorageLive(_28); -- _28 = _1; -- StorageLive(_29); -- _29 = _2; ++ nop; + 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); + StorageDead(_29); + StorageDead(_28); +- _26 = opaque::(move _27) -> [return: bb8, unwind continue]; + _26 = opaque::(_27) -> [return: bb8, unwind continue]; } bb8: { - StorageDead(_27); ++ nop; StorageDead(_26); StorageLive(_30); - StorageLive(_31); -- StorageLive(_32); -- _32 = _1; -- StorageLive(_33); -- _33 = _2; ++ nop; + 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); + StorageDead(_33); + StorageDead(_32); +- _30 = opaque::(move _31) -> [return: bb9, unwind continue]; + _30 = opaque::(_31) -> [return: bb9, unwind continue]; } bb9: { - StorageDead(_31); ++ nop; StorageDead(_30); StorageLive(_34); - StorageLive(_35); -- StorageLive(_36); -- _36 = _1; -- StorageLive(_37); -- _37 = _2; ++ nop; + 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); + StorageDead(_37); + StorageDead(_36); +- _34 = opaque::(move _35) -> [return: bb10, unwind continue]; + _34 = opaque::(_35) -> [return: bb10, unwind continue]; } bb10: { - StorageDead(_35); ++ nop; StorageDead(_34); StorageLive(_38); - StorageLive(_39); -- StorageLive(_40); -- _40 = _1; -- StorageLive(_41); -- _41 = _2; ++ nop; + 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); + StorageDead(_41); + StorageDead(_40); +- _38 = opaque::(move _39) -> [return: bb11, unwind continue]; + _38 = opaque::(_39) -> [return: bb11, unwind continue]; } bb11: { - StorageDead(_39); ++ nop; StorageDead(_38); StorageLive(_42); - StorageLive(_43); -- StorageLive(_44); -- _44 = _1; -- StorageLive(_45); -- _45 = _2; ++ nop; + 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); + StorageDead(_45); + StorageDead(_44); +- _42 = opaque::(move _43) -> [return: bb12, unwind continue]; + _42 = opaque::(_43) -> [return: bb12, unwind continue]; } bb12: { - StorageDead(_43); ++ nop; StorageDead(_42); StorageLive(_46); StorageLive(_47); -- StorageLive(_48); -- _48 = _1; + StorageLive(_48); + _48 = _1; - _47 = move _48 as u32 (IntToInt); -- StorageDead(_48); + _47 = _1 as u32 (IntToInt); + StorageDead(_48); _46 = opaque::(move _47) -> [return: bb13, unwind continue]; } @@ -393,11 +414,11 @@ StorageDead(_46); StorageLive(_49); StorageLive(_50); -- StorageLive(_51); -- _51 = _1; + StorageLive(_51); + _51 = _1; - _50 = move _51 as f32 (IntToFloat); -- StorageDead(_51); + _50 = _1 as f32 (IntToFloat); + StorageDead(_51); _49 = opaque::(move _50) -> [return: bb14, unwind continue]; } @@ -406,25 +427,29 @@ StorageDead(_49); StorageLive(_52); - StorageLive(_53); -- StorageLive(_54); -- _54 = _1; ++ nop; + StorageLive(_54); + _54 = _1; - _53 = S::(move _54); -- StorageDead(_54); -- _52 = opaque::>(move _53) -> [return: bb15, unwind continue]; + _53 = S::(_1); + StorageDead(_54); +- _52 = opaque::>(move _53) -> [return: bb15, unwind continue]; + _52 = opaque::>(_53) -> [return: bb15, unwind continue]; } bb15: { - StorageDead(_53); ++ nop; StorageDead(_52); StorageLive(_55); - StorageLive(_56); -- StorageLive(_57); -- StorageLive(_58); -- _58 = _1; ++ nop; + StorageLive(_57); + StorageLive(_58); + _58 = _1; - _57 = S::(move _58); -- StorageDead(_58); ++ _57 = _53; + StorageDead(_58); - _56 = (_57.0: u64); - _55 = opaque::(move _56) -> [return: bb16, unwind continue]; + _56 = (_53.0: u64); @@ -433,24 +458,26 @@ bb16: { - StorageDead(_56); -- StorageDead(_57); ++ nop; + StorageDead(_57); StorageDead(_55); StorageLive(_59); StorageLive(_60); -- StorageLive(_61); -- StorageLive(_62); -- _62 = _1; -- StorageLive(_63); -- _63 = _2; + StorageLive(_61); + StorageLive(_62); + _62 = _1; + StorageLive(_63); + _63 = _2; - _61 = Add(move _62, move _63); -- StorageDead(_63); -- StorageDead(_62); ++ _61 = _5; + StorageDead(_63); + StorageDead(_62); StorageLive(_64); _64 = _3; - _60 = Add(move _61, move _64); + _60 = Add(_5, move _64); StorageDead(_64); -- StorageDead(_61); + StorageDead(_61); _59 = opaque::(move _60) -> [return: bb17, unwind continue]; } @@ -459,20 +486,21 @@ StorageDead(_59); StorageLive(_65); StorageLive(_66); -- StorageLive(_67); -- StorageLive(_68); -- _68 = _1; -- StorageLive(_69); -- _69 = _2; + StorageLive(_67); + StorageLive(_68); + _68 = _1; + StorageLive(_69); + _69 = _2; - _67 = Mul(move _68, move _69); -- StorageDead(_69); -- StorageDead(_68); ++ _67 = _9; + StorageDead(_69); + StorageDead(_68); StorageLive(_70); _70 = _3; - _66 = Add(move _67, move _70); + _66 = Add(_9, move _70); StorageDead(_70); -- StorageDead(_67); + StorageDead(_67); _65 = opaque::(move _66) -> [return: bb18, unwind continue]; } @@ -481,20 +509,21 @@ StorageDead(_65); StorageLive(_71); StorageLive(_72); -- StorageLive(_73); -- StorageLive(_74); -- _74 = _1; -- StorageLive(_75); -- _75 = _2; + StorageLive(_73); + StorageLive(_74); + _74 = _1; + StorageLive(_75); + _75 = _2; - _73 = Sub(move _74, move _75); -- StorageDead(_75); -- StorageDead(_74); ++ _73 = _13; + StorageDead(_75); + StorageDead(_74); StorageLive(_76); _76 = _3; - _72 = Add(move _73, move _76); + _72 = Add(_13, move _76); StorageDead(_76); -- StorageDead(_73); + StorageDead(_73); _71 = opaque::(move _72) -> [return: bb19, unwind continue]; } @@ -503,26 +532,28 @@ StorageDead(_71); StorageLive(_77); StorageLive(_78); -- StorageLive(_79); -- StorageLive(_80); -- _80 = _1; -- StorageLive(_81); -- _81 = _2; + 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]; ++ _82 = _20; + assert(!_20, "attempt to divide `{}` by zero", _1) -> [success: bb20, unwind continue]; } bb20: { - _79 = Div(move _80, move _81); -- StorageDead(_81); -- StorageDead(_80); ++ _79 = _17; + StorageDead(_81); + StorageDead(_80); StorageLive(_83); _83 = _3; - _78 = Add(move _79, move _83); + _78 = Add(_17, move _83); StorageDead(_83); -- StorageDead(_79); + StorageDead(_79); _77 = opaque::(move _78) -> [return: bb21, unwind continue]; } @@ -531,26 +562,28 @@ StorageDead(_77); StorageLive(_84); StorageLive(_85); -- StorageLive(_86); -- StorageLive(_87); -- _87 = _1; -- StorageLive(_88); -- _88 = _2; + 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]; ++ _89 = _20; + 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); ++ _86 = _22; + StorageDead(_88); + StorageDead(_87); StorageLive(_90); _90 = _3; - _85 = Add(move _86, move _90); + _85 = Add(_22, move _90); StorageDead(_90); -- StorageDead(_86); + StorageDead(_86); _84 = opaque::(move _85) -> [return: bb23, unwind continue]; } @@ -559,20 +592,21 @@ StorageDead(_84); StorageLive(_91); StorageLive(_92); -- StorageLive(_93); -- StorageLive(_94); -- _94 = _1; -- StorageLive(_95); -- _95 = _2; + StorageLive(_93); + StorageLive(_94); + _94 = _1; + StorageLive(_95); + _95 = _2; - _93 = BitAnd(move _94, move _95); -- StorageDead(_95); -- StorageDead(_94); ++ _93 = _27; + StorageDead(_95); + StorageDead(_94); StorageLive(_96); _96 = _3; - _92 = Add(move _93, move _96); + _92 = Add(_27, move _96); StorageDead(_96); -- StorageDead(_93); + StorageDead(_93); _91 = opaque::(move _92) -> [return: bb24, unwind continue]; } @@ -581,20 +615,21 @@ StorageDead(_91); StorageLive(_97); StorageLive(_98); -- StorageLive(_99); -- StorageLive(_100); -- _100 = _1; -- StorageLive(_101); -- _101 = _2; + StorageLive(_99); + StorageLive(_100); + _100 = _1; + StorageLive(_101); + _101 = _2; - _99 = BitOr(move _100, move _101); -- StorageDead(_101); -- StorageDead(_100); ++ _99 = _31; + StorageDead(_101); + StorageDead(_100); StorageLive(_102); _102 = _3; - _98 = Add(move _99, move _102); + _98 = Add(_31, move _102); StorageDead(_102); -- StorageDead(_99); + StorageDead(_99); _97 = opaque::(move _98) -> [return: bb25, unwind continue]; } @@ -603,20 +638,21 @@ StorageDead(_97); StorageLive(_103); StorageLive(_104); -- StorageLive(_105); -- StorageLive(_106); -- _106 = _1; -- StorageLive(_107); -- _107 = _2; + StorageLive(_105); + StorageLive(_106); + _106 = _1; + StorageLive(_107); + _107 = _2; - _105 = BitXor(move _106, move _107); -- StorageDead(_107); -- StorageDead(_106); ++ _105 = _35; + StorageDead(_107); + StorageDead(_106); StorageLive(_108); _108 = _3; - _104 = Add(move _105, move _108); + _104 = Add(_35, move _108); StorageDead(_108); -- StorageDead(_105); + StorageDead(_105); _103 = opaque::(move _104) -> [return: bb26, unwind continue]; } @@ -625,20 +661,21 @@ StorageDead(_103); StorageLive(_109); StorageLive(_110); -- StorageLive(_111); -- StorageLive(_112); -- _112 = _1; -- StorageLive(_113); -- _113 = _2; + StorageLive(_111); + StorageLive(_112); + _112 = _1; + StorageLive(_113); + _113 = _2; - _111 = Shl(move _112, move _113); -- StorageDead(_113); -- StorageDead(_112); ++ _111 = _39; + StorageDead(_113); + StorageDead(_112); StorageLive(_114); _114 = _3; - _110 = Add(move _111, move _114); + _110 = Add(_39, move _114); StorageDead(_114); -- StorageDead(_111); + StorageDead(_111); _109 = opaque::(move _110) -> [return: bb27, unwind continue]; } @@ -647,20 +684,21 @@ StorageDead(_109); StorageLive(_115); StorageLive(_116); -- StorageLive(_117); -- StorageLive(_118); -- _118 = _1; -- StorageLive(_119); -- _119 = _2; + StorageLive(_117); + StorageLive(_118); + _118 = _1; + StorageLive(_119); + _119 = _2; - _117 = Shr(move _118, move _119); -- StorageDead(_119); -- StorageDead(_118); ++ _117 = _43; + StorageDead(_119); + StorageDead(_118); StorageLive(_120); _120 = _3; - _116 = Add(move _117, move _120); + _116 = Add(_43, move _120); StorageDead(_120); -- StorageDead(_117); + StorageDead(_117); _115 = opaque::(move _116) -> [return: bb28, unwind continue]; } @@ -668,68 +706,77 @@ StorageDead(_116); StorageDead(_115); StorageLive(_121); -- StorageLive(_122); -- StorageLive(_123); -- _123 = _1; + StorageLive(_122); + StorageLive(_123); + _123 = _1; - _122 = S::(move _123); -- StorageDead(_123); ++ _122 = _53; + StorageDead(_123); - _121 = opaque::>(move _122) -> [return: bb29, unwind continue]; + _121 = opaque::>(_53) -> [return: bb29, unwind continue]; } bb29: { -- StorageDead(_122); + StorageDead(_122); StorageDead(_121); StorageLive(_124); -- StorageLive(_125); -- StorageLive(_126); -- StorageLive(_127); -- _127 = _1; + StorageLive(_125); + StorageLive(_126); + StorageLive(_127); + _127 = _1; - _126 = S::(move _127); -- StorageDead(_127); ++ _126 = _53; + StorageDead(_127); - _125 = (_126.0: u64); - _124 = opaque::(move _125) -> [return: bb30, unwind continue]; ++ _125 = _56; + _124 = opaque::(_56) -> [return: bb30, unwind continue]; } bb30: { -- StorageDead(_125); -- StorageDead(_126); + StorageDead(_125); + StorageDead(_126); StorageDead(_124); StorageLive(_128); _128 = &_3; StorageLive(_129); - StorageLive(_130); - StorageLive(_131); ++ nop; ++ nop; _131 = (*_128); -- StorageLive(_132); -- _132 = _1; + StorageLive(_132); + _132 = _1; - _130 = Add(move _131, move _132); -- StorageDead(_132); ++ _130 = Add(_131, _1); + StorageDead(_132); - StorageDead(_131); - _129 = opaque::(move _130) -> [return: bb31, unwind continue]; -+ _130 = Add(_131, _1); ++ nop; + _129 = opaque::(_130) -> [return: bb31, unwind continue]; } bb31: { - StorageDead(_130); ++ nop; StorageDead(_129); StorageLive(_133); -- StorageLive(_134); -- StorageLive(_135); + StorageLive(_134); + StorageLive(_135); - _135 = (*_128); -- StorageLive(_136); -- _136 = _1; ++ _135 = _131; + StorageLive(_136); + _136 = _1; - _134 = Add(move _135, move _136); -- StorageDead(_136); -- StorageDead(_135); ++ _134 = _130; + StorageDead(_136); + StorageDead(_135); - _133 = opaque::(move _134) -> [return: bb32, unwind continue]; + _133 = opaque::(_130) -> [return: bb32, unwind continue]; } bb32: { -- StorageDead(_134); + StorageDead(_134); StorageDead(_133); StorageLive(_137); _137 = &mut _3; @@ -737,11 +784,11 @@ StorageLive(_139); StorageLive(_140); _140 = (*_137); -- StorageLive(_141); -- _141 = _1; + StorageLive(_141); + _141 = _1; - _139 = Add(move _140, move _141); -- StorageDead(_141); + _139 = Add(move _140, _1); + StorageDead(_141); StorageDead(_140); _138 = opaque::(move _139) -> [return: bb33, unwind continue]; } @@ -753,11 +800,11 @@ StorageLive(_143); StorageLive(_144); _144 = (*_137); -- StorageLive(_145); -- _145 = _1; + StorageLive(_145); + _145 = _1; - _143 = Add(move _144, move _145); -- StorageDead(_145); + _143 = Add(move _144, _1); + StorageDead(_145); StorageDead(_144); _142 = opaque::(move _143) -> [return: bb34, unwind continue]; } @@ -765,18 +812,18 @@ bb34: { StorageDead(_143); StorageDead(_142); -- StorageLive(_146); + StorageLive(_146); StorageLive(_147); _147 = &raw const _3; StorageLive(_148); StorageLive(_149); StorageLive(_150); _150 = (*_147); -- StorageLive(_151); -- _151 = _1; + StorageLive(_151); + _151 = _1; - _149 = Add(move _150, move _151); -- StorageDead(_151); + _149 = Add(move _150, _1); + StorageDead(_151); StorageDead(_150); _148 = opaque::(move _149) -> [return: bb35, unwind continue]; } @@ -788,11 +835,11 @@ StorageLive(_153); StorageLive(_154); _154 = (*_147); -- StorageLive(_155); -- _155 = _1; + StorageLive(_155); + _155 = _1; - _153 = Add(move _154, move _155); -- StorageDead(_155); + _153 = Add(move _154, _1); + StorageDead(_155); StorageDead(_154); _152 = opaque::(move _153) -> [return: bb36, unwind continue]; } @@ -806,11 +853,11 @@ StorageLive(_158); StorageLive(_159); _159 = (*_156); -- StorageLive(_160); -- _160 = _1; + StorageLive(_160); + _160 = _1; - _158 = Add(move _159, move _160); -- StorageDead(_160); + _158 = Add(move _159, _1); + StorageDead(_160); StorageDead(_159); _157 = opaque::(move _158) -> [return: bb37, unwind continue]; } @@ -822,11 +869,11 @@ StorageLive(_162); StorageLive(_163); _163 = (*_156); -- StorageLive(_164); -- _164 = _1; + StorageLive(_164); + _164 = _1; - _162 = Add(move _163, move _164); -- StorageDead(_164); + _162 = Add(move _163, _1); + StorageDead(_164); StorageDead(_163); _161 = opaque::(move _162) -> [return: bb38, unwind continue]; } @@ -834,44 +881,50 @@ bb38: { StorageDead(_162); StorageDead(_161); -- _146 = const (); + _146 = const (); StorageDead(_156); StorageDead(_147); -- StorageDead(_146); + StorageDead(_146); StorageLive(_165); _165 = &_3; StorageLive(_166); - StorageLive(_167); - StorageLive(_168); ++ nop; ++ nop; _168 = (*_165); -- StorageLive(_169); -- _169 = _1; + StorageLive(_169); + _169 = _1; - _167 = Add(move _168, move _169); -- StorageDead(_169); ++ _167 = Add(_168, _1); + StorageDead(_169); - StorageDead(_168); - _166 = opaque::(move _167) -> [return: bb39, unwind continue]; -+ _167 = Add(_168, _1); ++ nop; + _166 = opaque::(_167) -> [return: bb39, unwind continue]; } bb39: { - StorageDead(_167); ++ nop; StorageDead(_166); StorageLive(_170); -- StorageLive(_171); -- StorageLive(_172); + StorageLive(_171); + StorageLive(_172); - _172 = (*_165); -- StorageLive(_173); -- _173 = _1; ++ _172 = _168; + StorageLive(_173); + _173 = _1; - _171 = Add(move _172, move _173); -- StorageDead(_173); -- StorageDead(_172); ++ _171 = _167; + StorageDead(_173); + StorageDead(_172); - _170 = opaque::(move _171) -> [return: bb40, unwind continue]; + _170 = opaque::(_167) -> [return: bb40, unwind continue]; } bb40: { -- StorageDead(_171); + StorageDead(_171); StorageDead(_170); _0 = const (); StorageDead(_165); diff --git a/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-abort.diff b/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-abort.diff index f33845502ad94..2dd51934778ca 100644 --- a/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-abort.diff @@ -15,11 +15,11 @@ bb0: { StorageLive(_2); -- StorageLive(_3); -- _3 = _1; + StorageLive(_3); + _3 = _1; - _2 = Option::::Some(move _3); -- StorageDead(_3); + _2 = Option::::Some(_1); + StorageDead(_3); _4 = discriminant(_2); switchInt(move _4) -> [0: bb1, 1: bb3, otherwise: bb2]; } @@ -35,9 +35,11 @@ bb3: { - StorageLive(_5); ++ nop; _5 = ((_2 as Some).0: T); _0 = _5; - StorageDead(_5); ++ nop; 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 index edc05f99fe2f7..610d70576c9fd 100644 --- a/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-unwind.diff @@ -15,11 +15,11 @@ bb0: { StorageLive(_2); -- StorageLive(_3); -- _3 = _1; + StorageLive(_3); + _3 = _1; - _2 = Option::::Some(move _3); -- StorageDead(_3); + _2 = Option::::Some(_1); + StorageDead(_3); _4 = discriminant(_2); switchInt(move _4) -> [0: bb1, 1: bb3, otherwise: bb2]; } @@ -35,9 +35,11 @@ bb3: { - StorageLive(_5); ++ nop; _5 = ((_2 as Some).0: T); _0 = _5; - StorageDead(_5); ++ nop; StorageDead(_2); return; } diff --git a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff index 9d8f272abea3a..b2539f391d1a5 100644 --- a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff +++ b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff @@ -7,22 +7,18 @@ let _2: &[T]; let mut _3: &[T; 3]; let _4: [T; 3]; - let mut _5: T; - let mut _6: T; - let mut _7: T; - let mut _8: usize; - let mut _9: usize; - let mut _10: bool; - let mut _14: !; + let mut _5: usize; + let mut _6: bool; + let mut _10: !; scope 1 { debug v => _2; - let _11: &T; - let _12: &T; - let _13: &T; + let _7: &T; + let _8: &T; + let _9: &T; scope 2 { - debug v1 => _11; - debug v2 => _12; - debug v3 => _13; + debug v1 => _7; + debug v2 => _8; + debug v3 => _9; } } @@ -33,26 +29,25 @@ _3 = &_4; _2 = move _3 as &[T] (PointerCoercion(Unsize)); StorageDead(_3); - _8 = const 3_usize; - _9 = const 3_usize; - _10 = const true; + _5 = const 3_usize; + _6 = const true; goto -> bb2; } bb1: { - _14 = core::panicking::panic(const "internal error: entered unreachable code") -> unwind unreachable; + _10 = core::panicking::panic(const "internal error: entered unreachable code") -> unwind unreachable; } bb2: { - StorageLive(_11); - _11 = &(*_2)[0 of 3]; - StorageLive(_12); - _12 = &(*_2)[1 of 3]; - StorageLive(_13); - _13 = &(*_2)[2 of 3]; - StorageDead(_13); - StorageDead(_12); - StorageDead(_11); + StorageLive(_7); + _7 = &(*_2)[0 of 3]; + StorageLive(_8); + _8 = &(*_2)[1 of 3]; + StorageLive(_9); + _9 = &(*_2)[2 of 3]; + StorageDead(_9); + StorageDead(_8); + StorageDead(_7); StorageDead(_4); return; } diff --git a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff index 738b0b1b3e5ac..ff7f12c093ce4 100644 --- a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff +++ b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff @@ -7,22 +7,18 @@ let _2: &[T]; let mut _3: &[T; 3]; let _4: [T; 3]; - let mut _5: T; - let mut _6: T; - let mut _7: T; - let mut _8: usize; - let mut _9: usize; - let mut _10: bool; - let mut _14: !; + let mut _5: usize; + let mut _6: bool; + let mut _10: !; scope 1 { debug v => _2; - let _11: &T; - let _12: &T; - let _13: &T; + let _7: &T; + let _8: &T; + let _9: &T; scope 2 { - debug v1 => _11; - debug v2 => _12; - debug v3 => _13; + debug v1 => _7; + debug v2 => _8; + debug v3 => _9; } } @@ -33,26 +29,25 @@ _3 = &_4; _2 = move _3 as &[T] (PointerCoercion(Unsize)); StorageDead(_3); - _8 = const 3_usize; - _9 = const 3_usize; - _10 = const true; + _5 = const 3_usize; + _6 = const true; goto -> bb2; } bb1: { - _14 = core::panicking::panic(const "internal error: entered unreachable code") -> unwind continue; + _10 = core::panicking::panic(const "internal error: entered unreachable code") -> unwind continue; } bb2: { - StorageLive(_11); - _11 = &(*_2)[0 of 3]; - StorageLive(_12); - _12 = &(*_2)[1 of 3]; - StorageLive(_13); - _13 = &(*_2)[2 of 3]; - StorageDead(_13); - StorageDead(_12); - StorageDead(_11); + StorageLive(_7); + _7 = &(*_2)[0 of 3]; + StorageLive(_8); + _8 = &(*_2)[1 of 3]; + StorageLive(_9); + _9 = &(*_2)[2 of 3]; + StorageDead(_9); + StorageDead(_8); + StorageDead(_7); StorageDead(_4); return; } diff --git a/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-abort.diff b/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-abort.diff index d395715836064..64a435f224579 100644 --- a/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-abort.diff +++ b/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-abort.diff @@ -3,18 +3,15 @@ fn main() -> () { let mut _0: (); - let mut _1: bool; - let _2: (); + let _1: (); bb0: { - StorageLive(_1); - _1 = const false; - switchInt(const false) -> [0: bb3, otherwise: bb1]; + goto -> bb3; } bb1: { - _2 = noop() -> [return: bb2, unwind unreachable]; + _1 = noop() -> [return: bb2, unwind unreachable]; } bb2: { @@ -26,7 +23,6 @@ } bb4: { - StorageDead(_1); return; } } diff --git a/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-unwind.diff b/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-unwind.diff index 81903c64dbd4b..146e00686ed8d 100644 --- a/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-unwind.diff +++ b/tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-unwind.diff @@ -3,18 +3,15 @@ fn main() -> () { let mut _0: (); - let mut _1: bool; - let _2: (); + let _1: (); bb0: { - StorageLive(_1); - _1 = const false; - switchInt(const false) -> [0: bb3, otherwise: bb1]; + goto -> bb3; } bb1: { - _2 = noop() -> [return: bb2, unwind continue]; + _1 = noop() -> [return: bb2, unwind continue]; } bb2: { @@ -26,7 +23,6 @@ } bb4: { - StorageDead(_1); return; } } From c3f42e7fa5d4ad65dfdde28b2796feadd2671695 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 19 Sep 2023 19:20:22 +0000 Subject: [PATCH 11/18] Tolerate non-ptr indirect scalars in codegen. --- compiler/rustc_codegen_ssa/src/mir/operand.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/operand.rs b/compiler/rustc_codegen_ssa/src/mir/operand.rs index 9205acc527e53..63de6a7207284 100644 --- a/compiler/rustc_codegen_ssa/src/mir/operand.rs +++ b/compiler/rustc_codegen_ssa/src/mir/operand.rs @@ -156,7 +156,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { Abi::Scalar(s @ abi::Scalar::Initialized { .. }) => { let size = s.size(bx); assert_eq!(size, layout.size, "abi::Scalar size does not match layout size"); - let val = read_scalar(Size::ZERO, size, s, bx.type_ptr()); + let val = read_scalar(Size::ZERO, size, s, bx.backend_type(layout)); OperandRef { val: OperandValue::Immediate(val), layout } } Abi::ScalarPair( From 94de229ae0afe558096a997364e7ed780e9997f8 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 23 Sep 2023 09:35:44 +0000 Subject: [PATCH 12/18] Use correct offset when codegening mir::Const::Indirect. --- compiler/rustc_codegen_ssa/src/mir/operand.rs | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/operand.rs b/compiler/rustc_codegen_ssa/src/mir/operand.rs index 63de6a7207284..0ab2b7ecd9c80 100644 --- a/compiler/rustc_codegen_ssa/src/mir/operand.rs +++ b/compiler/rustc_codegen_ssa/src/mir/operand.rs @@ -135,15 +135,14 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { assert_eq!(alloc_align, layout.align.abi); let read_scalar = |start, size, s: abi::Scalar, ty| { - let val = alloc - .0 - .read_scalar( - bx, - alloc_range(start, size), - /*read_provenance*/ matches!(s.primitive(), abi::Pointer(_)), - ) - .unwrap(); - bx.scalar_to_backend(val, s, ty) + match alloc.0.read_scalar( + bx, + alloc_range(start, size), + /*read_provenance*/ matches!(s.primitive(), abi::Pointer(_)), + ) { + Ok(val) => bx.scalar_to_backend(val, s, ty), + Err(_) => bx.const_poison(ty), + } }; // It may seem like all types with `Scalar` or `ScalarPair` ABI are fair game at this point. @@ -156,7 +155,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { Abi::Scalar(s @ abi::Scalar::Initialized { .. }) => { let size = s.size(bx); assert_eq!(size, layout.size, "abi::Scalar size does not match layout size"); - let val = read_scalar(Size::ZERO, size, s, bx.backend_type(layout)); + let val = read_scalar(offset, size, s, bx.backend_type(layout)); OperandRef { val: OperandValue::Immediate(val), layout } } Abi::ScalarPair( @@ -164,10 +163,10 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { b @ abi::Scalar::Initialized { .. }, ) => { let (a_size, b_size) = (a.size(bx), b.size(bx)); - let b_offset = a_size.align_to(b.align(bx).abi); + let b_offset = (offset + a_size).align_to(b.align(bx).abi); assert!(b_offset.bytes() > 0); let a_val = read_scalar( - Size::ZERO, + offset, a_size, a, bx.scalar_pair_element_backend_type(layout, 0, true), From ccdb50fd3f7d79e70ad5b663ea47e6ccf01c2f0f Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 28 May 2023 12:55:36 +0000 Subject: [PATCH 13/18] Only visit reachable nodes in SsaLocals. --- compiler/rustc_mir_transform/src/ssa.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_mir_transform/src/ssa.rs b/compiler/rustc_mir_transform/src/ssa.rs index 3a675752fba91..92b13ddd0c708 100644 --- a/compiler/rustc_mir_transform/src/ssa.rs +++ b/compiler/rustc_mir_transform/src/ssa.rs @@ -78,14 +78,8 @@ impl SsaLocals { visitor.assignments[local] = Set1::One(LocationExtended::Arg); } - if body.basic_blocks.len() > 2 { - for (bb, data) in traversal::reverse_postorder(body) { - visitor.visit_basic_block_data(bb, data); - } - } else { - for (bb, data) in body.basic_blocks.iter_enumerated() { - visitor.visit_basic_block_data(bb, data); - } + for (bb, data) in traversal::reverse_postorder(body) { + visitor.visit_basic_block_data(bb, data); } for var_debug_info in &body.var_debug_info { From 2eb1917165f876e077f78961338fd29932e8e6a7 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 19 Sep 2023 20:12:48 +0000 Subject: [PATCH 14/18] Evaluated computed values to constants. --- .../src/interpret/discriminant.rs | 11 +- .../src/interpret/intrinsics.rs | 2 +- .../rustc_const_eval/src/interpret/operand.rs | 10 + .../rustc_const_eval/src/interpret/step.rs | 2 +- compiler/rustc_middle/src/mir/consts.rs | 12 + .../src/dataflow_const_prop.rs | 11 +- compiler/rustc_mir_transform/src/gvn.rs | 295 +++++++++++++++++- .../const_debuginfo.main.ConstDebugInfo.diff | 9 +- .../gvn.arithmetic.GVN.panic-abort.diff | 18 +- .../gvn.arithmetic.GVN.panic-unwind.diff | 18 +- ...vn.arithmetic_checked.GVN.panic-abort.diff | 31 +- ...n.arithmetic_checked.GVN.panic-unwind.diff | 31 +- tests/mir-opt/gvn.cast.GVN.panic-abort.diff | 135 ++++---- tests/mir-opt/gvn.cast.GVN.panic-unwind.diff | 135 ++++---- tests/mir-opt/gvn.slices.GVN.panic-abort.diff | 14 +- .../mir-opt/gvn.slices.GVN.panic-unwind.diff | 14 +- 16 files changed, 554 insertions(+), 194 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/discriminant.rs b/compiler/rustc_const_eval/src/interpret/discriminant.rs index 49e01728ff4b0..927e5abc85798 100644 --- a/compiler/rustc_const_eval/src/interpret/discriminant.rs +++ b/compiler/rustc_const_eval/src/interpret/discriminant.rs @@ -1,7 +1,8 @@ //! Functions for reading and writing discriminants of multi-variant layouts (enums and generators). -use rustc_middle::ty::layout::{LayoutOf, PrimitiveExt, TyAndLayout}; -use rustc_middle::{mir, ty}; +use rustc_middle::mir; +use rustc_middle::ty::layout::{LayoutOf, PrimitiveExt}; +use rustc_middle::ty::{self, Ty}; use rustc_target::abi::{self, TagEncoding}; use rustc_target::abi::{VariantIdx, Variants}; @@ -244,11 +245,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { pub fn discriminant_for_variant( &self, - layout: TyAndLayout<'tcx>, + ty: Ty<'tcx>, variant: VariantIdx, ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> { - let discr_layout = self.layout_of(layout.ty.discriminant_ty(*self.tcx))?; - let discr_value = match layout.ty.discriminant_for_variant(*self.tcx, variant) { + let discr_layout = self.layout_of(ty.discriminant_ty(*self.tcx))?; + let discr_value = match ty.discriminant_for_variant(*self.tcx, variant) { Some(discr) => { // This type actually has discriminants. assert_eq!(discr.ty, discr_layout.ty); diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index 2b26dbbba98fa..bbce785246d0e 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -219,7 +219,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { sym::discriminant_value => { let place = self.deref_pointer(&args[0])?; let variant = self.read_discriminant(&place)?; - let discr = self.discriminant_for_variant(place.layout, variant)?; + let discr = self.discriminant_for_variant(place.layout.ty, variant)?; self.write_immediate(*discr, dest)?; } sym::exact_div => { diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index a32ea204f9847..5f4863afec07d 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -163,6 +163,16 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> { ImmTy { imm: val.into(), layout } } + #[inline] + pub fn from_scalar_pair(a: Scalar, b: Scalar, layout: TyAndLayout<'tcx>) -> Self { + debug_assert!( + matches!(layout.abi, Abi::ScalarPair(..)), + "`ImmTy::from_scalar_pair` on non-scalar-pair layout" + ); + let imm = Immediate::ScalarPair(a, b); + ImmTy { imm, layout } + } + #[inline(always)] pub fn from_immediate(imm: Immediate, layout: TyAndLayout<'tcx>) -> Self { debug_assert!( diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index 284e13407f7e4..57469e4b9a3e1 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -300,7 +300,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Discriminant(place) => { let op = self.eval_place_to_op(place, None)?; let variant = self.read_discriminant(&op)?; - let discr = self.discriminant_for_variant(op.layout, variant)?; + let discr = self.discriminant_for_variant(op.layout.ty, variant)?; self.write_immediate(*discr, &dest)?; } } diff --git a/compiler/rustc_middle/src/mir/consts.rs b/compiler/rustc_middle/src/mir/consts.rs index 7c8a57b840b74..38f11a7833f50 100644 --- a/compiler/rustc_middle/src/mir/consts.rs +++ b/compiler/rustc_middle/src/mir/consts.rs @@ -172,6 +172,18 @@ impl<'tcx> ConstValue<'tcx> { let end = end.try_into().unwrap(); Some(data.inner().inspect_with_uninit_and_ptr_outside_interpreter(start..end)) } + + pub fn has_provenance(&self, tcx: TyCtxt<'tcx>, size: Size) -> bool { + let (alloc, start, end) = match *self { + ConstValue::ZeroSized | ConstValue::Scalar(Scalar::Int(_)) => return false, + ConstValue::Scalar(Scalar::Ptr(..)) => return true, + ConstValue::Slice { data, meta } => (data, Size::ZERO, Size::from_bytes(meta)), + ConstValue::Indirect { alloc_id, offset } => { + (tcx.global_alloc(alloc_id).unwrap_memory(), offset, offset + size) + } + }; + !alloc.inner().provenance().range_empty(super::AllocRange::from(start..end), &tcx) + } } /////////////////////////////////////////////////////////////////////////// diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index 7b14fef6153c5..ac0c69eca3c02 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -406,7 +406,8 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> { TrackElem::Variant(idx) => self.ecx.project_downcast(op, idx).ok(), TrackElem::Discriminant => { let variant = self.ecx.read_discriminant(op).ok()?; - let discr_value = self.ecx.discriminant_for_variant(op.layout, variant).ok()?; + let discr_value = + self.ecx.discriminant_for_variant(op.layout.ty, variant).ok()?; Some(discr_value.into()) } TrackElem::DerefLen => { @@ -507,7 +508,8 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> { return None; } let enum_ty_layout = self.tcx.layout_of(self.param_env.and(enum_ty)).ok()?; - let discr_value = self.ecx.discriminant_for_variant(enum_ty_layout, variant_index).ok()?; + let discr_value = + self.ecx.discriminant_for_variant(enum_ty_layout.ty, variant_index).ok()?; Some(discr_value.to_scalar()) } @@ -701,7 +703,7 @@ impl<'tcx> Visitor<'tcx> for OperandCollector<'tcx, '_, '_, '_> { } } -struct DummyMachine; +pub(crate) struct DummyMachine; impl<'mir, 'tcx: 'mir> rustc_const_eval::interpret::Machine<'mir, 'tcx> for DummyMachine { rustc_const_eval::interpret::compile_time_machine!(<'mir, 'tcx>); @@ -716,8 +718,9 @@ impl<'mir, 'tcx: 'mir> rustc_const_eval::interpret::Machine<'mir, 'tcx> for Dumm } fn enforce_validity(_ecx: &InterpCx<'mir, 'tcx, Self>, _layout: TyAndLayout<'tcx>) -> bool { - unimplemented!() + false } + fn alignment_check_failed( _ecx: &InterpCx<'mir, 'tcx, Self>, _has: Align, diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index d66bb2fa396c3..4767055aabcda 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -53,18 +53,24 @@ //! _c = *_b // replaced by _c = _a //! ``` +use rustc_const_eval::interpret::{ImmTy, InterpCx, MemPlaceMeta, OpTy, Projectable, Scalar}; 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::interpret::GlobalAlloc; use rustc_middle::mir::visit::*; use rustc_middle::mir::*; -use rustc_middle::ty::{self, Ty, TyCtxt}; -use rustc_target::abi::{VariantIdx, FIRST_VARIANT}; +use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeAndMut}; +use rustc_span::DUMMY_SP; +use rustc_target::abi::{self, Abi, Size, VariantIdx, FIRST_VARIANT}; +use crate::dataflow_const_prop::DummyMachine; use crate::ssa::SsaLocals; use crate::MirPass; +use either::Either; pub struct GVN; @@ -122,6 +128,12 @@ newtype_index! { struct VnIndex {} } +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +enum AddressKind { + Ref(BorrowKind), + Address(Mutability), +} + #[derive(Debug, PartialEq, Eq, Hash)] enum Value<'tcx> { // Root values. @@ -138,6 +150,7 @@ enum Value<'tcx> { /// The address of a place. Address { place: Place<'tcx>, + kind: AddressKind, /// Give each borrow and pointer a different provenance, so we don't merge them. provenance: usize, }, @@ -165,6 +178,7 @@ enum Value<'tcx> { struct VnState<'body, 'tcx> { tcx: TyCtxt<'tcx>, + ecx: InterpCx<'tcx, 'tcx, DummyMachine>, param_env: ty::ParamEnv<'tcx>, local_decls: &'body LocalDecls<'tcx>, /// Value stored in each local. @@ -172,6 +186,8 @@ struct VnState<'body, 'tcx> { /// First local to be assigned that value. rev_locals: FxHashMap>, values: FxIndexSet>, + /// Values evaluated as constants if possible. + evaluated: IndexVec>>, /// Counter to generate different values. /// This is an option to stop creating opaques during replacement. next_opaque: Option, @@ -190,11 +206,13 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { ) -> Self { VnState { tcx, + ecx: InterpCx::new(tcx, DUMMY_SP, param_env, DummyMachine), param_env, local_decls, locals: IndexVec::from_elem(None, local_decls), rev_locals: FxHashMap::default(), values: FxIndexSet::default(), + evaluated: IndexVec::new(), next_opaque: Some(0), ssa, dominators, @@ -204,8 +222,14 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { #[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) + let (index, new) = self.values.insert_full(value); + let index = VnIndex::from_usize(index); + if new { + let evaluated = self.eval_to_const(index); + let _index = self.evaluated.push(evaluated); + debug_assert_eq!(index, _index); + } + index } /// Create a new `Value` for which we have no information at all, except that it is distinct @@ -220,9 +244,9 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { /// 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 { + fn new_pointer(&mut self, place: Place<'tcx>, kind: AddressKind) -> Option { let next_opaque = self.next_opaque.as_mut()?; - let value = Value::Address { place, provenance: *next_opaque }; + let value = Value::Address { place, kind, provenance: *next_opaque }; *next_opaque += 1; Some(self.insert(value)) } @@ -244,6 +268,175 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { } } + #[instrument(level = "trace", skip(self), ret)] + fn eval_to_const(&mut self, value: VnIndex) -> Option> { + use Value::*; + let op = match *self.get(value) { + Opaque(_) => return None, + // Do not bother evaluating repeat expressions. This would uselessly consume memory. + Repeat(..) => return None, + + Constant(ref constant) => self.ecx.eval_mir_constant(constant, None, None).ok()?, + Aggregate(ty, variant, ref fields) => { + let fields = fields + .iter() + .map(|&f| self.evaluated[f].as_ref()) + .collect::>>()?; + let variant = if ty.is_enum() { Some(variant) } else { None }; + let ty = self.ecx.layout_of(ty).ok()?; + let alloc_id = self + .ecx + .intern_with_temp_alloc(ty, |ecx, dest| { + let variant_dest = if let Some(variant) = variant { + ecx.project_downcast(dest, variant)? + } else { + dest.clone() + }; + for (field_index, op) in fields.into_iter().enumerate() { + let field_dest = ecx.project_field(&variant_dest, field_index)?; + ecx.copy_op(op, &field_dest, /*allow_transmute*/ false)?; + } + ecx.write_discriminant(variant.unwrap_or(FIRST_VARIANT), dest) + }) + .ok()?; + let mplace = + self.ecx.raw_const_to_mplace(ConstAlloc { alloc_id, ty: ty.ty }).ok()?; + mplace.into() + } + + Projection(base, elem) => { + let value = self.evaluated[base].as_ref()?; + let elem = match elem { + ProjectionElem::Deref => ProjectionElem::Deref, + ProjectionElem::Downcast(name, read_variant) => { + ProjectionElem::Downcast(name, read_variant) + } + ProjectionElem::Field(f, ty) => ProjectionElem::Field(f, ty), + 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::OpaqueCast(ty) => ProjectionElem::OpaqueCast(ty), + // This should have been replaced by a `ConstantIndex` earlier. + ProjectionElem::Index(_) => return None, + }; + self.ecx.project(value, elem).ok()? + } + Address { place, kind, provenance: _ } => { + if !place.is_indirect_first_projection() { + return None; + } + let local = self.locals[place.local]?; + let pointer = self.evaluated[local].as_ref()?; + let mut mplace = self.ecx.deref_pointer(pointer).ok()?; + for proj in place.projection.iter().skip(1) { + // We have no call stack to associate a local with a value, so we cannot interpret indexing. + if matches!(proj, ProjectionElem::Index(_)) { + return None; + } + mplace = self.ecx.project(&mplace, proj).ok()?; + } + let pointer = mplace.to_ref(&self.ecx); + let ty = match kind { + AddressKind::Ref(bk) => Ty::new_ref( + self.tcx, + self.tcx.lifetimes.re_erased, + ty::TypeAndMut { ty: mplace.layout.ty, mutbl: bk.to_mutbl_lossy() }, + ), + AddressKind::Address(mutbl) => { + Ty::new_ptr(self.tcx, TypeAndMut { ty: mplace.layout.ty, mutbl }) + } + }; + let layout = self.ecx.layout_of(ty).ok()?; + ImmTy::from_immediate(pointer, layout).into() + } + + Discriminant(base) => { + let base = self.evaluated[base].as_ref()?; + let variant = self.ecx.read_discriminant(base).ok()?; + let discr_value = + self.ecx.discriminant_for_variant(base.layout.ty, variant).ok()?; + discr_value.into() + } + Len(slice) => { + let slice = self.evaluated[slice].as_ref()?; + let usize_layout = self.ecx.layout_of(self.tcx.types.usize).unwrap(); + let len = slice.len(&self.ecx).ok()?; + let imm = ImmTy::try_from_uint(len, usize_layout)?; + imm.into() + } + NullaryOp(null_op, ty) => { + let layout = self.ecx.layout_of(ty).ok()?; + if let NullOp::SizeOf | NullOp::AlignOf = null_op && layout.is_unsized() { + return None; + } + let val = match null_op { + NullOp::SizeOf => layout.size.bytes(), + NullOp::AlignOf => layout.align.abi.bytes(), + NullOp::OffsetOf(fields) => layout + .offset_of_subfield(&self.ecx, fields.iter().map(|f| f.index())) + .bytes(), + }; + let usize_layout = self.ecx.layout_of(self.tcx.types.usize).unwrap(); + let imm = ImmTy::try_from_uint(val, usize_layout)?; + imm.into() + } + UnaryOp(un_op, operand) => { + let operand = self.evaluated[operand].as_ref()?; + let operand = self.ecx.read_immediate(operand).ok()?; + let (val, _) = self.ecx.overflowing_unary_op(un_op, &operand).ok()?; + val.into() + } + BinaryOp(bin_op, lhs, rhs) => { + let lhs = self.evaluated[lhs].as_ref()?; + let lhs = self.ecx.read_immediate(lhs).ok()?; + let rhs = self.evaluated[rhs].as_ref()?; + let rhs = self.ecx.read_immediate(rhs).ok()?; + let (val, _) = self.ecx.overflowing_binary_op(bin_op, &lhs, &rhs).ok()?; + val.into() + } + CheckedBinaryOp(bin_op, lhs, rhs) => { + let lhs = self.evaluated[lhs].as_ref()?; + let lhs = self.ecx.read_immediate(lhs).ok()?; + let rhs = self.evaluated[rhs].as_ref()?; + let rhs = self.ecx.read_immediate(rhs).ok()?; + let (val, overflowed) = self.ecx.overflowing_binary_op(bin_op, &lhs, &rhs).ok()?; + let tuple = Ty::new_tup_from_iter( + self.tcx, + [val.layout.ty, self.tcx.types.bool].into_iter(), + ); + let tuple = self.ecx.layout_of(tuple).ok()?; + ImmTy::from_scalar_pair(val.to_scalar(), Scalar::from_bool(overflowed), tuple) + .into() + } + Cast { kind, value, from: _, to } => match kind { + CastKind::IntToInt | CastKind::IntToFloat => { + let value = self.evaluated[value].as_ref()?; + let value = self.ecx.read_immediate(value).ok()?; + let to = self.ecx.layout_of(to).ok()?; + let res = self.ecx.int_to_int_or_float(&value, to).ok()?; + res.into() + } + CastKind::FloatToFloat | CastKind::FloatToInt => { + let value = self.evaluated[value].as_ref()?; + let value = self.ecx.read_immediate(value).ok()?; + let to = self.ecx.layout_of(to).ok()?; + let res = self.ecx.float_to_float_or_int(&value, to).ok()?; + res.into() + } + CastKind::Transmute => { + let value = self.evaluated[value].as_ref()?; + let to = self.ecx.layout_of(to).ok()?; + value.offset(Size::ZERO, to, &self.ecx).ok()? + } + _ => return None, + }, + }; + Some(op) + } + /// Represent the *value* which would be read from `place`. #[instrument(level = "trace", skip(self), ret)] fn simplify_place(&mut self, place: &mut Place<'tcx>, location: Location) -> Option { @@ -365,7 +558,12 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { 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), + Rvalue::Ref(_, borrow_kind, place) => { + return self.new_pointer(place, AddressKind::Ref(borrow_kind)); + } + Rvalue::AddressOf(mutbl, place) => { + return self.new_pointer(place, AddressKind::Address(mutbl)); + } // Operations. Rvalue::Len(ref mut place) => { @@ -404,43 +602,106 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { } } +fn op_to_prop_const<'tcx>( + ecx: &mut InterpCx<'_, 'tcx, DummyMachine>, + op: &OpTy<'tcx>, +) -> Option> { + // Do not attempt to propagate unsized locals. + if op.layout.is_unsized() { + return None; + } + + // This constant is a ZST, just return an empty value. + if op.layout.is_zst() { + return Some(ConstValue::ZeroSized); + } + + // Do not synthetize too large constants. Codegen will just memcpy them, which we'd like to avoid. + if !matches!(op.layout.abi, Abi::Scalar(..) | Abi::ScalarPair(..)) { + return None; + } + + // If this constant has scalar ABI, return it as a `ConstValue::Scalar`. + if let Abi::Scalar(abi::Scalar::Initialized { .. }) = op.layout.abi + && let Ok(scalar) = ecx.read_scalar(op) + { + return Some(ConstValue::Scalar(scalar)); + } + + // If this constant is a projection of another, we can return it directly. + if let Either::Left(mplace) = op.as_mplace_or_imm() + && let MemPlaceMeta::None = mplace.meta() + { + let pointer = mplace.ptr().into_pointer_or_addr().ok()?; + let (alloc_id, offset) = pointer.into_parts(); + return if matches!(ecx.tcx.global_alloc(alloc_id), GlobalAlloc::Memory(_)) { + Some(ConstValue::Indirect { alloc_id, offset }) + } else { + None + } + } + + // Everything failed: create a new allocation to hold the data. + let alloc_id = + ecx.intern_with_temp_alloc(op.layout, |ecx, dest| ecx.copy_op(op, dest, false)).ok()?; + Some(ConstValue::Indirect { alloc_id, offset: Size::ZERO }) +} + 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> { + // This was already constant in MIR, do not change it. 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_ { + let const_ok = 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::ValTree::Leaf(_) => true, + ty::ValTree::Branch(_) => false, }, ty::ConstKind::Param(..) | ty::ConstKind::Unevaluated(..) - | ty::ConstKind::Expr(..) => {} + | ty::ConstKind::Expr(..) => true, // Should not appear in runtime MIR. ty::ConstKind::Infer(..) | ty::ConstKind::Bound(..) | ty::ConstKind::Placeholder(..) | ty::ConstKind::Error(..) => bug!(), }, - Const::Unevaluated(..) => {} + Const::Unevaluated(..) => true, // 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::Slice { .. }, _) => false, Const::Val( ConstValue::ZeroSized | ConstValue::Scalar(_) | ConstValue::Indirect { .. }, _, - ) => {} + ) => true, + }; + if const_ok { + return Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_ }); } - Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_ }) - } else { - None } + + let op = self.evaluated[index].as_ref()?; + if op.layout.is_unsized() { + // Do not attempt to propagate unsized locals. + return None; + } + + let value = op_to_prop_const(&mut self.ecx, op)?; + + // Check that we do not leak a pointer. + // Those pointers may lose part of their identity in codegen. + if value.has_provenance(self.tcx, op.layout.size) { + return None; + } + + let const_ = Const::Val(value, op.layout.ty); + Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_ }) } /// If there is a local which is assigned `index`, and its assignment strictly dominates `loc`, diff --git a/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff b/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff index ca58ecf3fbcde..9c980a6e9664e 100644 --- a/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff +++ b/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff @@ -35,7 +35,8 @@ + debug ((f: (bool, bool, u32)).2: u32) => const 123_u32; let _6: std::option::Option; scope 7 { - debug o => _6; +- debug o => _6; ++ debug o => const Option::::Some(99_u16); let _11: u32; let _12: u32; scope 8 { @@ -72,7 +73,7 @@ _9 = const false; _10 = const 123_u32; StorageLive(_6); - _6 = Option::::Some(const 99_u16); + _6 = const Option::::Some(99_u16); _11 = const 32_u32; _12 = const 32_u32; StorageLive(_7); @@ -88,3 +89,7 @@ } } + alloc11 (size: 4, align: 2) { + 01 00 63 00 │ ..c. + } + diff --git a/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff b/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff index 17ba0d3cef2d4..d524ad242fecc 100644 --- a/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff @@ -121,9 +121,10 @@ StorageLive(_15); StorageLive(_16); _16 = _1; - _17 = Eq(const 0_u64, const 0_u64); +- _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]; ++ _17 = const true; ++ assert(!const true, "attempt to divide `{}` by zero", _1) -> [success: bb5, unwind unreachable]; } bb5: { @@ -140,9 +141,10 @@ StorageLive(_19); StorageLive(_20); _20 = _1; - _21 = Eq(const 1_u64, const 0_u64); +- _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]; ++ _21 = const false; ++ assert(!const false, "attempt to divide `{}` by zero", _1) -> [success: bb7, unwind unreachable]; } bb7: { @@ -201,8 +203,8 @@ _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]; -+ _33 = _17; -+ assert(!_17, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb13, unwind unreachable]; ++ _33 = const true; ++ assert(!const true, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb13, unwind unreachable]; } bb13: { @@ -221,8 +223,8 @@ _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]; -+ _37 = _21; -+ assert(!_21, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb15, unwind unreachable]; ++ _37 = const false; ++ assert(!const false, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb15, unwind unreachable]; } bb15: { diff --git a/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff b/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff index f14fd409bea1c..9d69353934c79 100644 --- a/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff @@ -121,9 +121,10 @@ StorageLive(_15); StorageLive(_16); _16 = _1; - _17 = Eq(const 0_u64, const 0_u64); +- _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]; ++ _17 = const true; ++ assert(!const true, "attempt to divide `{}` by zero", _1) -> [success: bb5, unwind continue]; } bb5: { @@ -140,9 +141,10 @@ StorageLive(_19); StorageLive(_20); _20 = _1; - _21 = Eq(const 1_u64, const 0_u64); +- _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]; ++ _21 = const false; ++ assert(!const false, "attempt to divide `{}` by zero", _1) -> [success: bb7, unwind continue]; } bb7: { @@ -201,8 +203,8 @@ _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]; -+ _33 = _17; -+ assert(!_17, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb13, unwind continue]; ++ _33 = const true; ++ assert(!const true, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb13, unwind continue]; } bb13: { @@ -221,8 +223,8 @@ _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]; -+ _37 = _21; -+ assert(!_21, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb15, unwind continue]; ++ _37 = const false; ++ assert(!const false, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb15, unwind continue]; } bb15: { diff --git a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff index e586e4ac8898c..3efe7abc976f7 100644 --- a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff @@ -153,9 +153,10 @@ StorageLive(_19); StorageLive(_20); _20 = _1; - _21 = Eq(const 0_u64, const 0_u64); +- _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]; ++ _21 = const true; ++ assert(!const true, "attempt to divide `{}` by zero", _1) -> [success: bb9, unwind unreachable]; } bb9: { @@ -172,9 +173,10 @@ StorageLive(_23); StorageLive(_24); _24 = _1; - _25 = Eq(const 1_u64, const 0_u64); +- _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]; ++ _25 = const false; ++ assert(!const false, "attempt to divide `{}` by zero", _1) -> [success: bb11, unwind unreachable]; } bb11: { @@ -233,8 +235,8 @@ _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]; -+ _37 = _21; -+ assert(!_21, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb17, unwind unreachable]; ++ _37 = const true; ++ assert(!const true, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb17, unwind unreachable]; } bb17: { @@ -253,8 +255,8 @@ _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]; -+ _41 = _25; -+ assert(!_25, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb19, unwind unreachable]; ++ _41 = const false; ++ assert(!const false, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb19, unwind unreachable]; } bb19: { @@ -350,11 +352,12 @@ StorageLive(_60); StorageLive(_61); _61 = _1; - _62 = const 0_i32 as u32 (IntToInt); +- _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]; ++ _62 = const 0_u32; ++ _63 = const true; ++ assert(const true, "attempt to shift right by `{}`, which would overflow", const 0_i32) -> [success: bb28, unwind unreachable]; } bb28: { @@ -374,9 +377,9 @@ - _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]; -+ _67 = _62; -+ _68 = _63; -+ assert(_63, "attempt to shift left by `{}`, which would overflow", const 0_i32) -> [success: bb30, unwind unreachable]; ++ _67 = const 0_u32; ++ _68 = const true; ++ assert(const true, "attempt to shift left by `{}`, which would overflow", const 0_i32) -> [success: bb30, unwind unreachable]; } bb30: { diff --git a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff index f58a9116b8fe7..9fbb8df79a1db 100644 --- a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff @@ -153,9 +153,10 @@ StorageLive(_19); StorageLive(_20); _20 = _1; - _21 = Eq(const 0_u64, const 0_u64); +- _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]; ++ _21 = const true; ++ assert(!const true, "attempt to divide `{}` by zero", _1) -> [success: bb9, unwind continue]; } bb9: { @@ -172,9 +173,10 @@ StorageLive(_23); StorageLive(_24); _24 = _1; - _25 = Eq(const 1_u64, const 0_u64); +- _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]; ++ _25 = const false; ++ assert(!const false, "attempt to divide `{}` by zero", _1) -> [success: bb11, unwind continue]; } bb11: { @@ -233,8 +235,8 @@ _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]; -+ _37 = _21; -+ assert(!_21, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb17, unwind continue]; ++ _37 = const true; ++ assert(!const true, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb17, unwind continue]; } bb17: { @@ -253,8 +255,8 @@ _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]; -+ _41 = _25; -+ assert(!_25, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb19, unwind continue]; ++ _41 = const false; ++ assert(!const false, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb19, unwind continue]; } bb19: { @@ -350,11 +352,12 @@ StorageLive(_60); StorageLive(_61); _61 = _1; - _62 = const 0_i32 as u32 (IntToInt); +- _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]; ++ _62 = const 0_u32; ++ _63 = const true; ++ assert(const true, "attempt to shift right by `{}`, which would overflow", const 0_i32) -> [success: bb28, unwind continue]; } bb28: { @@ -374,9 +377,9 @@ - _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]; -+ _67 = _62; -+ _68 = _63; -+ assert(_63, "attempt to shift left by `{}`, which would overflow", const 0_i32) -> [success: bb30, unwind continue]; ++ _67 = const 0_u32; ++ _68 = const true; ++ assert(const true, "attempt to shift left by `{}`, which would overflow", const 0_i32) -> [success: bb30, unwind continue]; } bb30: { diff --git a/tests/mir-opt/gvn.cast.GVN.panic-abort.diff b/tests/mir-opt/gvn.cast.GVN.panic-abort.diff index 37b0d92931f68..d43198c99110d 100644 --- a/tests/mir-opt/gvn.cast.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.cast.GVN.panic-abort.diff @@ -119,9 +119,10 @@ - _6 = _1; - _5 = move _6 as u8 (IntToInt); + _6 = const 1_i64; -+ _5 = const 1_i64 as u8 (IntToInt); ++ _5 = const 1_u8; StorageDead(_6); - _4 = opaque::(move _5) -> [return: bb1, unwind unreachable]; +- _4 = opaque::(move _5) -> [return: bb1, unwind unreachable]; ++ _4 = opaque::(const 1_u8) -> [return: bb1, unwind unreachable]; } bb1: { @@ -133,9 +134,10 @@ - _9 = _1; - _8 = move _9 as u16 (IntToInt); + _9 = const 1_i64; -+ _8 = const 1_i64 as u16 (IntToInt); ++ _8 = const 1_u16; StorageDead(_9); - _7 = opaque::(move _8) -> [return: bb2, unwind unreachable]; +- _7 = opaque::(move _8) -> [return: bb2, unwind unreachable]; ++ _7 = opaque::(const 1_u16) -> [return: bb2, unwind unreachable]; } bb2: { @@ -147,9 +149,10 @@ - _12 = _1; - _11 = move _12 as u32 (IntToInt); + _12 = const 1_i64; -+ _11 = const 1_i64 as u32 (IntToInt); ++ _11 = const 1_u32; StorageDead(_12); - _10 = opaque::(move _11) -> [return: bb3, unwind unreachable]; +- _10 = opaque::(move _11) -> [return: bb3, unwind unreachable]; ++ _10 = opaque::(const 1_u32) -> [return: bb3, unwind unreachable]; } bb3: { @@ -161,9 +164,10 @@ - _15 = _1; - _14 = move _15 as u64 (IntToInt); + _15 = const 1_i64; -+ _14 = const 1_i64 as u64 (IntToInt); ++ _14 = const 1_u64; StorageDead(_15); - _13 = opaque::(move _14) -> [return: bb4, unwind unreachable]; +- _13 = opaque::(move _14) -> [return: bb4, unwind unreachable]; ++ _13 = opaque::(const 1_u64) -> [return: bb4, unwind unreachable]; } bb4: { @@ -175,9 +179,10 @@ - _18 = _1; - _17 = move _18 as i8 (IntToInt); + _18 = const 1_i64; -+ _17 = const 1_i64 as i8 (IntToInt); ++ _17 = const 1_i8; StorageDead(_18); - _16 = opaque::(move _17) -> [return: bb5, unwind unreachable]; +- _16 = opaque::(move _17) -> [return: bb5, unwind unreachable]; ++ _16 = opaque::(const 1_i8) -> [return: bb5, unwind unreachable]; } bb5: { @@ -189,9 +194,10 @@ - _21 = _1; - _20 = move _21 as i16 (IntToInt); + _21 = const 1_i64; -+ _20 = const 1_i64 as i16 (IntToInt); ++ _20 = const 1_i16; StorageDead(_21); - _19 = opaque::(move _20) -> [return: bb6, unwind unreachable]; +- _19 = opaque::(move _20) -> [return: bb6, unwind unreachable]; ++ _19 = opaque::(const 1_i16) -> [return: bb6, unwind unreachable]; } bb6: { @@ -203,9 +209,10 @@ - _24 = _1; - _23 = move _24 as i32 (IntToInt); + _24 = const 1_i64; -+ _23 = const 1_i64 as i32 (IntToInt); ++ _23 = const 1_i32; StorageDead(_24); - _22 = opaque::(move _23) -> [return: bb7, unwind unreachable]; +- _22 = opaque::(move _23) -> [return: bb7, unwind unreachable]; ++ _22 = opaque::(const 1_i32) -> [return: bb7, unwind unreachable]; } bb7: { @@ -228,9 +235,10 @@ - _29 = _1; - _28 = move _29 as f32 (IntToFloat); + _29 = const 1_i64; -+ _28 = const 1_i64 as f32 (IntToFloat); ++ _28 = const 1f32; StorageDead(_29); - _27 = opaque::(move _28) -> [return: bb9, unwind unreachable]; +- _27 = opaque::(move _28) -> [return: bb9, unwind unreachable]; ++ _27 = opaque::(const 1f32) -> [return: bb9, unwind unreachable]; } bb9: { @@ -242,9 +250,10 @@ - _32 = _1; - _31 = move _32 as f64 (IntToFloat); + _32 = const 1_i64; -+ _31 = const 1_i64 as f64 (IntToFloat); ++ _31 = const 1f64; StorageDead(_32); - _30 = opaque::(move _31) -> [return: bb10, unwind unreachable]; +- _30 = opaque::(move _31) -> [return: bb10, unwind unreachable]; ++ _30 = opaque::(const 1f64) -> [return: bb10, unwind unreachable]; } bb10: { @@ -256,9 +265,10 @@ - _35 = _2; - _34 = move _35 as u8 (IntToInt); + _35 = const 1_u64; -+ _34 = const 1_u64 as u8 (IntToInt); ++ _34 = const 1_u8; StorageDead(_35); - _33 = opaque::(move _34) -> [return: bb11, unwind unreachable]; +- _33 = opaque::(move _34) -> [return: bb11, unwind unreachable]; ++ _33 = opaque::(const 1_u8) -> [return: bb11, unwind unreachable]; } bb11: { @@ -270,9 +280,10 @@ - _38 = _2; - _37 = move _38 as u16 (IntToInt); + _38 = const 1_u64; -+ _37 = const 1_u64 as u16 (IntToInt); ++ _37 = const 1_u16; StorageDead(_38); - _36 = opaque::(move _37) -> [return: bb12, unwind unreachable]; +- _36 = opaque::(move _37) -> [return: bb12, unwind unreachable]; ++ _36 = opaque::(const 1_u16) -> [return: bb12, unwind unreachable]; } bb12: { @@ -284,9 +295,10 @@ - _41 = _2; - _40 = move _41 as u32 (IntToInt); + _41 = const 1_u64; -+ _40 = const 1_u64 as u32 (IntToInt); ++ _40 = const 1_u32; StorageDead(_41); - _39 = opaque::(move _40) -> [return: bb13, unwind unreachable]; +- _39 = opaque::(move _40) -> [return: bb13, unwind unreachable]; ++ _39 = opaque::(const 1_u32) -> [return: bb13, unwind unreachable]; } bb13: { @@ -309,9 +321,10 @@ - _46 = _2; - _45 = move _46 as i8 (IntToInt); + _46 = const 1_u64; -+ _45 = const 1_u64 as i8 (IntToInt); ++ _45 = const 1_i8; StorageDead(_46); - _44 = opaque::(move _45) -> [return: bb15, unwind unreachable]; +- _44 = opaque::(move _45) -> [return: bb15, unwind unreachable]; ++ _44 = opaque::(const 1_i8) -> [return: bb15, unwind unreachable]; } bb15: { @@ -323,9 +336,10 @@ - _49 = _2; - _48 = move _49 as i16 (IntToInt); + _49 = const 1_u64; -+ _48 = const 1_u64 as i16 (IntToInt); ++ _48 = const 1_i16; StorageDead(_49); - _47 = opaque::(move _48) -> [return: bb16, unwind unreachable]; +- _47 = opaque::(move _48) -> [return: bb16, unwind unreachable]; ++ _47 = opaque::(const 1_i16) -> [return: bb16, unwind unreachable]; } bb16: { @@ -337,9 +351,10 @@ - _52 = _2; - _51 = move _52 as i32 (IntToInt); + _52 = const 1_u64; -+ _51 = const 1_u64 as i32 (IntToInt); ++ _51 = const 1_i32; StorageDead(_52); - _50 = opaque::(move _51) -> [return: bb17, unwind unreachable]; +- _50 = opaque::(move _51) -> [return: bb17, unwind unreachable]; ++ _50 = opaque::(const 1_i32) -> [return: bb17, unwind unreachable]; } bb17: { @@ -351,9 +366,10 @@ - _55 = _2; - _54 = move _55 as i64 (IntToInt); + _55 = const 1_u64; -+ _54 = const 1_u64 as i64 (IntToInt); ++ _54 = const 1_i64; StorageDead(_55); - _53 = opaque::(move _54) -> [return: bb18, unwind unreachable]; +- _53 = opaque::(move _54) -> [return: bb18, unwind unreachable]; ++ _53 = opaque::(const 1_i64) -> [return: bb18, unwind unreachable]; } bb18: { @@ -365,9 +381,10 @@ - _58 = _2; - _57 = move _58 as f32 (IntToFloat); + _58 = const 1_u64; -+ _57 = const 1_u64 as f32 (IntToFloat); ++ _57 = const 1f32; StorageDead(_58); - _56 = opaque::(move _57) -> [return: bb19, unwind unreachable]; +- _56 = opaque::(move _57) -> [return: bb19, unwind unreachable]; ++ _56 = opaque::(const 1f32) -> [return: bb19, unwind unreachable]; } bb19: { @@ -379,9 +396,10 @@ - _61 = _2; - _60 = move _61 as f64 (IntToFloat); + _61 = const 1_u64; -+ _60 = const 1_u64 as f64 (IntToFloat); ++ _60 = const 1f64; StorageDead(_61); - _59 = opaque::(move _60) -> [return: bb20, unwind unreachable]; +- _59 = opaque::(move _60) -> [return: bb20, unwind unreachable]; ++ _59 = opaque::(const 1f64) -> [return: bb20, unwind unreachable]; } bb20: { @@ -393,9 +411,10 @@ - _64 = _3; - _63 = move _64 as u8 (FloatToInt); + _64 = const 1f64; -+ _63 = const 1f64 as u8 (FloatToInt); ++ _63 = const 1_u8; StorageDead(_64); - _62 = opaque::(move _63) -> [return: bb21, unwind unreachable]; +- _62 = opaque::(move _63) -> [return: bb21, unwind unreachable]; ++ _62 = opaque::(const 1_u8) -> [return: bb21, unwind unreachable]; } bb21: { @@ -407,9 +426,10 @@ - _67 = _3; - _66 = move _67 as u16 (FloatToInt); + _67 = const 1f64; -+ _66 = const 1f64 as u16 (FloatToInt); ++ _66 = const 1_u16; StorageDead(_67); - _65 = opaque::(move _66) -> [return: bb22, unwind unreachable]; +- _65 = opaque::(move _66) -> [return: bb22, unwind unreachable]; ++ _65 = opaque::(const 1_u16) -> [return: bb22, unwind unreachable]; } bb22: { @@ -421,9 +441,10 @@ - _70 = _3; - _69 = move _70 as u32 (FloatToInt); + _70 = const 1f64; -+ _69 = const 1f64 as u32 (FloatToInt); ++ _69 = const 1_u32; StorageDead(_70); - _68 = opaque::(move _69) -> [return: bb23, unwind unreachable]; +- _68 = opaque::(move _69) -> [return: bb23, unwind unreachable]; ++ _68 = opaque::(const 1_u32) -> [return: bb23, unwind unreachable]; } bb23: { @@ -435,9 +456,10 @@ - _73 = _3; - _72 = move _73 as u64 (FloatToInt); + _73 = const 1f64; -+ _72 = const 1f64 as u64 (FloatToInt); ++ _72 = const 1_u64; StorageDead(_73); - _71 = opaque::(move _72) -> [return: bb24, unwind unreachable]; +- _71 = opaque::(move _72) -> [return: bb24, unwind unreachable]; ++ _71 = opaque::(const 1_u64) -> [return: bb24, unwind unreachable]; } bb24: { @@ -449,9 +471,10 @@ - _76 = _3; - _75 = move _76 as i8 (FloatToInt); + _76 = const 1f64; -+ _75 = const 1f64 as i8 (FloatToInt); ++ _75 = const 1_i8; StorageDead(_76); - _74 = opaque::(move _75) -> [return: bb25, unwind unreachable]; +- _74 = opaque::(move _75) -> [return: bb25, unwind unreachable]; ++ _74 = opaque::(const 1_i8) -> [return: bb25, unwind unreachable]; } bb25: { @@ -463,9 +486,10 @@ - _79 = _3; - _78 = move _79 as i16 (FloatToInt); + _79 = const 1f64; -+ _78 = const 1f64 as i16 (FloatToInt); ++ _78 = const 1_i16; StorageDead(_79); - _77 = opaque::(move _78) -> [return: bb26, unwind unreachable]; +- _77 = opaque::(move _78) -> [return: bb26, unwind unreachable]; ++ _77 = opaque::(const 1_i16) -> [return: bb26, unwind unreachable]; } bb26: { @@ -477,9 +501,10 @@ - _82 = _3; - _81 = move _82 as i32 (FloatToInt); + _82 = const 1f64; -+ _81 = const 1f64 as i32 (FloatToInt); ++ _81 = const 1_i32; StorageDead(_82); - _80 = opaque::(move _81) -> [return: bb27, unwind unreachable]; +- _80 = opaque::(move _81) -> [return: bb27, unwind unreachable]; ++ _80 = opaque::(const 1_i32) -> [return: bb27, unwind unreachable]; } bb27: { @@ -491,9 +516,10 @@ - _85 = _3; - _84 = move _85 as i64 (FloatToInt); + _85 = const 1f64; -+ _84 = const 1f64 as i64 (FloatToInt); ++ _84 = const 1_i64; StorageDead(_85); - _83 = opaque::(move _84) -> [return: bb28, unwind unreachable]; +- _83 = opaque::(move _84) -> [return: bb28, unwind unreachable]; ++ _83 = opaque::(const 1_i64) -> [return: bb28, unwind unreachable]; } bb28: { @@ -505,9 +531,10 @@ - _88 = _3; - _87 = move _88 as f32 (FloatToFloat); + _88 = const 1f64; -+ _87 = const 1f64 as f32 (FloatToFloat); ++ _87 = const 1f32; StorageDead(_88); - _86 = opaque::(move _87) -> [return: bb29, unwind unreachable]; +- _86 = opaque::(move _87) -> [return: bb29, unwind unreachable]; ++ _86 = opaque::(const 1f32) -> [return: bb29, unwind unreachable]; } bb29: { diff --git a/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff b/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff index fbdec455188ab..08b97e13aa0ba 100644 --- a/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff @@ -119,9 +119,10 @@ - _6 = _1; - _5 = move _6 as u8 (IntToInt); + _6 = const 1_i64; -+ _5 = const 1_i64 as u8 (IntToInt); ++ _5 = const 1_u8; StorageDead(_6); - _4 = opaque::(move _5) -> [return: bb1, unwind continue]; +- _4 = opaque::(move _5) -> [return: bb1, unwind continue]; ++ _4 = opaque::(const 1_u8) -> [return: bb1, unwind continue]; } bb1: { @@ -133,9 +134,10 @@ - _9 = _1; - _8 = move _9 as u16 (IntToInt); + _9 = const 1_i64; -+ _8 = const 1_i64 as u16 (IntToInt); ++ _8 = const 1_u16; StorageDead(_9); - _7 = opaque::(move _8) -> [return: bb2, unwind continue]; +- _7 = opaque::(move _8) -> [return: bb2, unwind continue]; ++ _7 = opaque::(const 1_u16) -> [return: bb2, unwind continue]; } bb2: { @@ -147,9 +149,10 @@ - _12 = _1; - _11 = move _12 as u32 (IntToInt); + _12 = const 1_i64; -+ _11 = const 1_i64 as u32 (IntToInt); ++ _11 = const 1_u32; StorageDead(_12); - _10 = opaque::(move _11) -> [return: bb3, unwind continue]; +- _10 = opaque::(move _11) -> [return: bb3, unwind continue]; ++ _10 = opaque::(const 1_u32) -> [return: bb3, unwind continue]; } bb3: { @@ -161,9 +164,10 @@ - _15 = _1; - _14 = move _15 as u64 (IntToInt); + _15 = const 1_i64; -+ _14 = const 1_i64 as u64 (IntToInt); ++ _14 = const 1_u64; StorageDead(_15); - _13 = opaque::(move _14) -> [return: bb4, unwind continue]; +- _13 = opaque::(move _14) -> [return: bb4, unwind continue]; ++ _13 = opaque::(const 1_u64) -> [return: bb4, unwind continue]; } bb4: { @@ -175,9 +179,10 @@ - _18 = _1; - _17 = move _18 as i8 (IntToInt); + _18 = const 1_i64; -+ _17 = const 1_i64 as i8 (IntToInt); ++ _17 = const 1_i8; StorageDead(_18); - _16 = opaque::(move _17) -> [return: bb5, unwind continue]; +- _16 = opaque::(move _17) -> [return: bb5, unwind continue]; ++ _16 = opaque::(const 1_i8) -> [return: bb5, unwind continue]; } bb5: { @@ -189,9 +194,10 @@ - _21 = _1; - _20 = move _21 as i16 (IntToInt); + _21 = const 1_i64; -+ _20 = const 1_i64 as i16 (IntToInt); ++ _20 = const 1_i16; StorageDead(_21); - _19 = opaque::(move _20) -> [return: bb6, unwind continue]; +- _19 = opaque::(move _20) -> [return: bb6, unwind continue]; ++ _19 = opaque::(const 1_i16) -> [return: bb6, unwind continue]; } bb6: { @@ -203,9 +209,10 @@ - _24 = _1; - _23 = move _24 as i32 (IntToInt); + _24 = const 1_i64; -+ _23 = const 1_i64 as i32 (IntToInt); ++ _23 = const 1_i32; StorageDead(_24); - _22 = opaque::(move _23) -> [return: bb7, unwind continue]; +- _22 = opaque::(move _23) -> [return: bb7, unwind continue]; ++ _22 = opaque::(const 1_i32) -> [return: bb7, unwind continue]; } bb7: { @@ -228,9 +235,10 @@ - _29 = _1; - _28 = move _29 as f32 (IntToFloat); + _29 = const 1_i64; -+ _28 = const 1_i64 as f32 (IntToFloat); ++ _28 = const 1f32; StorageDead(_29); - _27 = opaque::(move _28) -> [return: bb9, unwind continue]; +- _27 = opaque::(move _28) -> [return: bb9, unwind continue]; ++ _27 = opaque::(const 1f32) -> [return: bb9, unwind continue]; } bb9: { @@ -242,9 +250,10 @@ - _32 = _1; - _31 = move _32 as f64 (IntToFloat); + _32 = const 1_i64; -+ _31 = const 1_i64 as f64 (IntToFloat); ++ _31 = const 1f64; StorageDead(_32); - _30 = opaque::(move _31) -> [return: bb10, unwind continue]; +- _30 = opaque::(move _31) -> [return: bb10, unwind continue]; ++ _30 = opaque::(const 1f64) -> [return: bb10, unwind continue]; } bb10: { @@ -256,9 +265,10 @@ - _35 = _2; - _34 = move _35 as u8 (IntToInt); + _35 = const 1_u64; -+ _34 = const 1_u64 as u8 (IntToInt); ++ _34 = const 1_u8; StorageDead(_35); - _33 = opaque::(move _34) -> [return: bb11, unwind continue]; +- _33 = opaque::(move _34) -> [return: bb11, unwind continue]; ++ _33 = opaque::(const 1_u8) -> [return: bb11, unwind continue]; } bb11: { @@ -270,9 +280,10 @@ - _38 = _2; - _37 = move _38 as u16 (IntToInt); + _38 = const 1_u64; -+ _37 = const 1_u64 as u16 (IntToInt); ++ _37 = const 1_u16; StorageDead(_38); - _36 = opaque::(move _37) -> [return: bb12, unwind continue]; +- _36 = opaque::(move _37) -> [return: bb12, unwind continue]; ++ _36 = opaque::(const 1_u16) -> [return: bb12, unwind continue]; } bb12: { @@ -284,9 +295,10 @@ - _41 = _2; - _40 = move _41 as u32 (IntToInt); + _41 = const 1_u64; -+ _40 = const 1_u64 as u32 (IntToInt); ++ _40 = const 1_u32; StorageDead(_41); - _39 = opaque::(move _40) -> [return: bb13, unwind continue]; +- _39 = opaque::(move _40) -> [return: bb13, unwind continue]; ++ _39 = opaque::(const 1_u32) -> [return: bb13, unwind continue]; } bb13: { @@ -309,9 +321,10 @@ - _46 = _2; - _45 = move _46 as i8 (IntToInt); + _46 = const 1_u64; -+ _45 = const 1_u64 as i8 (IntToInt); ++ _45 = const 1_i8; StorageDead(_46); - _44 = opaque::(move _45) -> [return: bb15, unwind continue]; +- _44 = opaque::(move _45) -> [return: bb15, unwind continue]; ++ _44 = opaque::(const 1_i8) -> [return: bb15, unwind continue]; } bb15: { @@ -323,9 +336,10 @@ - _49 = _2; - _48 = move _49 as i16 (IntToInt); + _49 = const 1_u64; -+ _48 = const 1_u64 as i16 (IntToInt); ++ _48 = const 1_i16; StorageDead(_49); - _47 = opaque::(move _48) -> [return: bb16, unwind continue]; +- _47 = opaque::(move _48) -> [return: bb16, unwind continue]; ++ _47 = opaque::(const 1_i16) -> [return: bb16, unwind continue]; } bb16: { @@ -337,9 +351,10 @@ - _52 = _2; - _51 = move _52 as i32 (IntToInt); + _52 = const 1_u64; -+ _51 = const 1_u64 as i32 (IntToInt); ++ _51 = const 1_i32; StorageDead(_52); - _50 = opaque::(move _51) -> [return: bb17, unwind continue]; +- _50 = opaque::(move _51) -> [return: bb17, unwind continue]; ++ _50 = opaque::(const 1_i32) -> [return: bb17, unwind continue]; } bb17: { @@ -351,9 +366,10 @@ - _55 = _2; - _54 = move _55 as i64 (IntToInt); + _55 = const 1_u64; -+ _54 = const 1_u64 as i64 (IntToInt); ++ _54 = const 1_i64; StorageDead(_55); - _53 = opaque::(move _54) -> [return: bb18, unwind continue]; +- _53 = opaque::(move _54) -> [return: bb18, unwind continue]; ++ _53 = opaque::(const 1_i64) -> [return: bb18, unwind continue]; } bb18: { @@ -365,9 +381,10 @@ - _58 = _2; - _57 = move _58 as f32 (IntToFloat); + _58 = const 1_u64; -+ _57 = const 1_u64 as f32 (IntToFloat); ++ _57 = const 1f32; StorageDead(_58); - _56 = opaque::(move _57) -> [return: bb19, unwind continue]; +- _56 = opaque::(move _57) -> [return: bb19, unwind continue]; ++ _56 = opaque::(const 1f32) -> [return: bb19, unwind continue]; } bb19: { @@ -379,9 +396,10 @@ - _61 = _2; - _60 = move _61 as f64 (IntToFloat); + _61 = const 1_u64; -+ _60 = const 1_u64 as f64 (IntToFloat); ++ _60 = const 1f64; StorageDead(_61); - _59 = opaque::(move _60) -> [return: bb20, unwind continue]; +- _59 = opaque::(move _60) -> [return: bb20, unwind continue]; ++ _59 = opaque::(const 1f64) -> [return: bb20, unwind continue]; } bb20: { @@ -393,9 +411,10 @@ - _64 = _3; - _63 = move _64 as u8 (FloatToInt); + _64 = const 1f64; -+ _63 = const 1f64 as u8 (FloatToInt); ++ _63 = const 1_u8; StorageDead(_64); - _62 = opaque::(move _63) -> [return: bb21, unwind continue]; +- _62 = opaque::(move _63) -> [return: bb21, unwind continue]; ++ _62 = opaque::(const 1_u8) -> [return: bb21, unwind continue]; } bb21: { @@ -407,9 +426,10 @@ - _67 = _3; - _66 = move _67 as u16 (FloatToInt); + _67 = const 1f64; -+ _66 = const 1f64 as u16 (FloatToInt); ++ _66 = const 1_u16; StorageDead(_67); - _65 = opaque::(move _66) -> [return: bb22, unwind continue]; +- _65 = opaque::(move _66) -> [return: bb22, unwind continue]; ++ _65 = opaque::(const 1_u16) -> [return: bb22, unwind continue]; } bb22: { @@ -421,9 +441,10 @@ - _70 = _3; - _69 = move _70 as u32 (FloatToInt); + _70 = const 1f64; -+ _69 = const 1f64 as u32 (FloatToInt); ++ _69 = const 1_u32; StorageDead(_70); - _68 = opaque::(move _69) -> [return: bb23, unwind continue]; +- _68 = opaque::(move _69) -> [return: bb23, unwind continue]; ++ _68 = opaque::(const 1_u32) -> [return: bb23, unwind continue]; } bb23: { @@ -435,9 +456,10 @@ - _73 = _3; - _72 = move _73 as u64 (FloatToInt); + _73 = const 1f64; -+ _72 = const 1f64 as u64 (FloatToInt); ++ _72 = const 1_u64; StorageDead(_73); - _71 = opaque::(move _72) -> [return: bb24, unwind continue]; +- _71 = opaque::(move _72) -> [return: bb24, unwind continue]; ++ _71 = opaque::(const 1_u64) -> [return: bb24, unwind continue]; } bb24: { @@ -449,9 +471,10 @@ - _76 = _3; - _75 = move _76 as i8 (FloatToInt); + _76 = const 1f64; -+ _75 = const 1f64 as i8 (FloatToInt); ++ _75 = const 1_i8; StorageDead(_76); - _74 = opaque::(move _75) -> [return: bb25, unwind continue]; +- _74 = opaque::(move _75) -> [return: bb25, unwind continue]; ++ _74 = opaque::(const 1_i8) -> [return: bb25, unwind continue]; } bb25: { @@ -463,9 +486,10 @@ - _79 = _3; - _78 = move _79 as i16 (FloatToInt); + _79 = const 1f64; -+ _78 = const 1f64 as i16 (FloatToInt); ++ _78 = const 1_i16; StorageDead(_79); - _77 = opaque::(move _78) -> [return: bb26, unwind continue]; +- _77 = opaque::(move _78) -> [return: bb26, unwind continue]; ++ _77 = opaque::(const 1_i16) -> [return: bb26, unwind continue]; } bb26: { @@ -477,9 +501,10 @@ - _82 = _3; - _81 = move _82 as i32 (FloatToInt); + _82 = const 1f64; -+ _81 = const 1f64 as i32 (FloatToInt); ++ _81 = const 1_i32; StorageDead(_82); - _80 = opaque::(move _81) -> [return: bb27, unwind continue]; +- _80 = opaque::(move _81) -> [return: bb27, unwind continue]; ++ _80 = opaque::(const 1_i32) -> [return: bb27, unwind continue]; } bb27: { @@ -491,9 +516,10 @@ - _85 = _3; - _84 = move _85 as i64 (FloatToInt); + _85 = const 1f64; -+ _84 = const 1f64 as i64 (FloatToInt); ++ _84 = const 1_i64; StorageDead(_85); - _83 = opaque::(move _84) -> [return: bb28, unwind continue]; +- _83 = opaque::(move _84) -> [return: bb28, unwind continue]; ++ _83 = opaque::(const 1_i64) -> [return: bb28, unwind continue]; } bb28: { @@ -505,9 +531,10 @@ - _88 = _3; - _87 = move _88 as f32 (FloatToFloat); + _88 = const 1f64; -+ _87 = const 1f64 as f32 (FloatToFloat); ++ _87 = const 1f32; StorageDead(_88); - _86 = opaque::(move _87) -> [return: bb29, unwind continue]; +- _86 = opaque::(move _87) -> [return: bb29, unwind continue]; ++ _86 = opaque::(const 1f32) -> [return: bb29, unwind continue]; } bb29: { diff --git a/tests/mir-opt/gvn.slices.GVN.panic-abort.diff b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff index d924c70d617dd..98255c42007d1 100644 --- a/tests/mir-opt/gvn.slices.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff @@ -176,12 +176,13 @@ StorageDead(_19); StorageDead(_18); - StorageLive(_21); +- _21 = core::panicking::AssertKind::Eq; + nop; - _21 = core::panicking::AssertKind::Eq; ++ _21 = const core::panicking::AssertKind::Eq; StorageLive(_22); StorageLive(_23); - _23 = move _21; -+ _23 = _21; ++ _23 = const core::panicking::AssertKind::Eq; StorageLive(_24); StorageLive(_25); _25 = &(*_15); @@ -193,7 +194,7 @@ 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; ++ _22 = core::panicking::assert_failed::<*const u8, *const u8>(const core::panicking::AssertKind::Eq, move _24, move _26, move _28) -> unwind unreachable; } bb7: { @@ -261,12 +262,13 @@ StorageDead(_45); StorageDead(_44); - StorageLive(_47); +- _47 = core::panicking::AssertKind::Eq; + nop; - _47 = core::panicking::AssertKind::Eq; ++ _47 = const core::panicking::AssertKind::Eq; StorageLive(_48); StorageLive(_49); - _49 = move _47; -+ _49 = _47; ++ _49 = const core::panicking::AssertKind::Eq; StorageLive(_50); StorageLive(_51); _51 = &(*_41); @@ -278,7 +280,7 @@ 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; ++ _48 = core::panicking::assert_failed::<*const u8, *const u8>(const core::panicking::AssertKind::Eq, 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 index 63225aa0a1016..0f79cc409f310 100644 --- a/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff @@ -176,12 +176,13 @@ StorageDead(_19); StorageDead(_18); - StorageLive(_21); +- _21 = core::panicking::AssertKind::Eq; + nop; - _21 = core::panicking::AssertKind::Eq; ++ _21 = const core::panicking::AssertKind::Eq; StorageLive(_22); StorageLive(_23); - _23 = move _21; -+ _23 = _21; ++ _23 = const core::panicking::AssertKind::Eq; StorageLive(_24); StorageLive(_25); _25 = &(*_15); @@ -193,7 +194,7 @@ 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; ++ _22 = core::panicking::assert_failed::<*const u8, *const u8>(const core::panicking::AssertKind::Eq, move _24, move _26, move _28) -> unwind continue; } bb7: { @@ -261,12 +262,13 @@ StorageDead(_45); StorageDead(_44); - StorageLive(_47); +- _47 = core::panicking::AssertKind::Eq; + nop; - _47 = core::panicking::AssertKind::Eq; ++ _47 = const core::panicking::AssertKind::Eq; StorageLive(_48); StorageLive(_49); - _49 = move _47; -+ _49 = _47; ++ _49 = const core::panicking::AssertKind::Eq; StorageLive(_50); StorageLive(_51); _51 = &(*_41); @@ -278,7 +280,7 @@ 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; ++ _48 = core::panicking::assert_failed::<*const u8, *const u8>(const core::panicking::AssertKind::Eq, move _50, move _52, move _54) -> unwind continue; } } From 298feffefa5feb1d32d89a0b162d33700613cb6f Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 23 Sep 2023 07:23:14 +0000 Subject: [PATCH 15/18] Do not transmute immediates to non-immediates. --- compiler/rustc_mir_transform/src/gvn.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 4767055aabcda..80428385091df 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -429,6 +429,16 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { CastKind::Transmute => { let value = self.evaluated[value].as_ref()?; let to = self.ecx.layout_of(to).ok()?; + // `offset` for immediates only supports scalar/scalar-pair ABIs, + // so bail out if the target is not one. + if value.as_mplace_or_imm().is_right() { + match to.abi { + Abi::Scalar(..) | Abi::ScalarPair(..) => {} + _ if to.is_zst() => {} + Abi::Aggregate { .. } if to.fields.count() == 0 => {} + _ => return None, + } + } value.offset(Size::ZERO, to, &self.ecx).ok()? } _ => return None, From 3c5b57c96fa8f425014c18465e280d91fed14db0 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 21 May 2023 10:33:03 +0000 Subject: [PATCH 16/18] Enable GVN by default. --- compiler/rustc_mir_transform/src/gvn.rs | 2 +- compiler/rustc_mir_transform/src/lib.rs | 2 +- .../issues/issue-105386-ub-in-debuginfo.rs | 2 - tests/codegen/slice-ref-equality.rs | 32 ++-- .../const_debuginfo.main.ConstDebugInfo.diff | 2 +- .../boolean_identities.test.ConstProp.diff | 12 +- ...ssue_66971.main.ConstProp.panic-abort.diff | 20 +-- ...sue_66971.main.ConstProp.panic-unwind.diff | 20 +-- ...ssue_67019.main.ConstProp.panic-abort.diff | 29 +--- ...sue_67019.main.ConstProp.panic-unwind.diff | 29 +--- ...onential_common.ConstProp.panic-abort.diff | 47 +++--- ...nential_common.ConstProp.panic-unwind.diff | 47 +++--- ...nto_box_place.main.Inline.panic-abort.diff | 148 ++++++++-------- ...to_box_place.main.Inline.panic-unwind.diff | 148 ++++++++-------- ...67_inline_as_ref_as_mut.b.Inline.after.mir | 2 +- ...67_inline_as_ref_as_mut.d.Inline.after.mir | 2 +- ...ue_101973.inner.ConstProp.panic-abort.diff | 56 +++---- ...e_101973.inner.ConstProp.panic-unwind.diff | 56 +++---- ...ecked_ops.checked_shl.PreCodegen.after.mir | 6 +- .../loops.int_range.PreCodegen.after.mir | 6 +- tests/mir-opt/pre-codegen/loops.rs | 1 + ...able.main.ConstProp.32bit.panic-abort.diff | 48 ++---- ...ble.main.ConstProp.32bit.panic-unwind.diff | 48 ++---- ...able.main.ConstProp.64bit.panic-abort.diff | 48 ++---- ...ble.main.ConstProp.64bit.panic-unwind.diff | 48 ++---- ...ward_loop.PreCodegen.after.panic-abort.mir | 6 +- ...ard_loop.PreCodegen.after.panic-unwind.mir | 6 +- ...iter_next.PreCodegen.after.panic-abort.mir | 6 +- ...ter_next.PreCodegen.after.panic-unwind.mir | 6 +- ...mple_option_map.ezmap.PreCodegen.after.mir | 6 +- ...variant_a-{closure#0}.PreCodegen.after.mir | 24 +-- ...variant_b-{closure#0}.PreCodegen.after.mir | 56 +++---- ...mut_range.PreCodegen.after.panic-abort.mir | 23 ++- ...ut_range.PreCodegen.after.panic-unwind.mir | 23 ++- ...ated_loop.PreCodegen.after.panic-abort.mir | 158 +++++++++--------- ...ted_loop.PreCodegen.after.panic-unwind.mir | 158 +++++++++--------- ...ward_loop.PreCodegen.after.panic-abort.mir | 140 ++++++++-------- ...ard_loop.PreCodegen.after.panic-unwind.mir | 140 ++++++++-------- ...ange_loop.PreCodegen.after.panic-abort.mir | 6 +- ...nge_loop.PreCodegen.after.panic-unwind.mir | 6 +- ...erse_loop.PreCodegen.after.panic-abort.mir | 156 +++++++++-------- ...rse_loop.PreCodegen.after.panic-unwind.mir | 156 +++++++++-------- ...lify_match.main.ConstProp.panic-abort.diff | 10 +- ...ify_match.main.ConstProp.panic-unwind.diff | 10 +- 44 files changed, 881 insertions(+), 1076 deletions(-) diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 80428385091df..d8d941272d188 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -76,7 +76,7 @@ pub struct GVN; impl<'tcx> MirPass<'tcx> for GVN { fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() >= 4 + sess.mir_opt_level() >= 2 } #[instrument(level = "trace", skip(self, tcx, body))] diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 84b6e8caac577..86910a6a1196c 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -551,9 +551,9 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { // destroy the SSA property. It should still happen before const-propagation, so the // latter pass will leverage the created opportunities. &separate_const_switch::SeparateConstSwitch, - &const_prop::ConstProp, &gvn::GVN, &simplify::SimplifyLocals::AfterGVN, + &const_prop::ConstProp, &dataflow_const_prop::DataflowConstProp, // // Const-prop runs unconditionally, but doesn't mutate the MIR at mir-opt-level=0. diff --git a/tests/codegen/issues/issue-105386-ub-in-debuginfo.rs b/tests/codegen/issues/issue-105386-ub-in-debuginfo.rs index 54c50f840c551..a9538da19757f 100644 --- a/tests/codegen/issues/issue-105386-ub-in-debuginfo.rs +++ b/tests/codegen/issues/issue-105386-ub-in-debuginfo.rs @@ -19,5 +19,3 @@ pub fn outer_function(x: S, y: S) -> usize { // CHECK-NOT: [[ptr_tmp:%.*]] = getelementptr inbounds %"{closure@{{.*.rs}}:9:23: 9:25}", ptr [[spill]] // CHECK-NOT: [[load:%.*]] = load ptr, ptr // CHECK: call void @llvm.lifetime.start{{.*}}({{.*}}, ptr [[spill]]) -// CHECK: [[inner:%.*]] = getelementptr inbounds %"{{.*}}", ptr [[spill]] -// CHECK: call void @llvm.memcpy{{.*}}(ptr {{align .*}} [[inner]], ptr {{align .*}} %x diff --git a/tests/codegen/slice-ref-equality.rs b/tests/codegen/slice-ref-equality.rs index afbdf66ce0aa8..4d0dce7b07437 100644 --- a/tests/codegen/slice-ref-equality.rs +++ b/tests/codegen/slice-ref-equality.rs @@ -44,48 +44,48 @@ pub fn is_zero_array(data: &[u8; 4]) -> bool { // equality for non-byte types also just emit a `bcmp`, not a loop. // CHECK-LABEL: @eq_slice_of_nested_u8( -// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1 -// CHECK-SAME: [[USIZE]] noundef %3 +// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %x.1 +// CHECK-SAME: [[USIZE]] noundef %y.1 #[no_mangle] fn eq_slice_of_nested_u8(x: &[[u8; 3]], y: &[[u8; 3]]) -> bool { - // CHECK: icmp eq [[USIZE]] %1, %3 - // CHECK: %[[BYTES:.+]] = mul nsw [[USIZE]] %1, 3 + // CHECK: icmp eq [[USIZE]] %x.1, %y.1 + // CHECK: %[[BYTES:.+]] = mul nsw [[USIZE]] %x.1, 3 // CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr // CHECK-SAME: , [[USIZE]]{{( noundef)?}} %[[BYTES]]) x == y } // CHECK-LABEL: @eq_slice_of_i32( -// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1 -// CHECK-SAME: [[USIZE]] noundef %3 +// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %x.1 +// CHECK-SAME: [[USIZE]] noundef %y.1 #[no_mangle] fn eq_slice_of_i32(x: &[i32], y: &[i32]) -> bool { - // CHECK: icmp eq [[USIZE]] %1, %3 - // CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 2 + // CHECK: icmp eq [[USIZE]] %x.1, %y.1 + // CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %x.1, 2 // CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr // CHECK-SAME: , [[USIZE]]{{( noundef)?}} %[[BYTES]]) x == y } // CHECK-LABEL: @eq_slice_of_nonzero( -// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1 -// CHECK-SAME: [[USIZE]] noundef %3 +// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %x.1 +// CHECK-SAME: [[USIZE]] noundef %y.1 #[no_mangle] fn eq_slice_of_nonzero(x: &[NonZeroU32], y: &[NonZeroU32]) -> bool { - // CHECK: icmp eq [[USIZE]] %1, %3 - // CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 2 + // CHECK: icmp eq [[USIZE]] %x.1, %y.1 + // CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %x.1, 2 // CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr // CHECK-SAME: , [[USIZE]]{{( noundef)?}} %[[BYTES]]) x == y } // CHECK-LABEL: @eq_slice_of_option_of_nonzero( -// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1 -// CHECK-SAME: [[USIZE]] noundef %3 +// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %x.1 +// CHECK-SAME: [[USIZE]] noundef %y.1 #[no_mangle] fn eq_slice_of_option_of_nonzero(x: &[Option], y: &[Option]) -> bool { - // CHECK: icmp eq [[USIZE]] %1, %3 - // CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 1 + // CHECK: icmp eq [[USIZE]] %x.1, %y.1 + // CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %x.1, 1 // CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr // CHECK-SAME: , [[USIZE]]{{( noundef)?}} %[[BYTES]]) x == y diff --git a/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff b/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff index 9c980a6e9664e..158de80e2b897 100644 --- a/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff +++ b/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff @@ -89,7 +89,7 @@ } } - alloc11 (size: 4, align: 2) { + alloc8 (size: 4, align: 2) { 01 00 63 00 │ ..c. } diff --git a/tests/mir-opt/const_prop/boolean_identities.test.ConstProp.diff b/tests/mir-opt/const_prop/boolean_identities.test.ConstProp.diff index d805341991d83..56f3e09e6b8dd 100644 --- a/tests/mir-opt/const_prop/boolean_identities.test.ConstProp.diff +++ b/tests/mir-opt/const_prop/boolean_identities.test.ConstProp.diff @@ -7,19 +7,17 @@ let mut _0: bool; let mut _3: bool; let mut _4: bool; - let mut _5: bool; - let mut _6: bool; bb0: { StorageLive(_3); - _3 = BitOr(_2, const true); + _3 = const true; - StorageLive(_5); -- _5 = BitAnd(_1, const false); -- _0 = BitAnd(move _3, move _5); -+ _5 = const false; + StorageLive(_4); +- _4 = BitAnd(_1, const false); +- _0 = BitAnd(move _3, move _4); ++ _4 = const false; + _0 = const false; - StorageDead(_5); + StorageDead(_4); StorageDead(_3); return; } diff --git a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff index 18341ba7db923..9e17d72df29cd 100644 --- a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff @@ -4,27 +4,17 @@ fn main() -> () { let mut _0: (); let _1: (); - let mut _2: ((), u8, u8); bb0: { - StorageLive(_2); -- _2 = (const (), const 0_u8, const 0_u8); -- _1 = encode(move _2) -> [return: bb1, unwind unreachable]; -+ _2 = const ((), 0_u8, 0_u8); -+ _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind unreachable]; + _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind unreachable]; } bb1: { - StorageDead(_2); return; } -+ } -+ -+ alloc8 (size: 2, align: 1) { -+ 00 00 │ .. -+ } -+ -+ alloc7 (size: 2, align: 1) { -+ 00 00 │ .. + } + + alloc5 (size: 2, align: 1) { + 00 00 │ .. } diff --git a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff index 50763c10f0c22..2b507ec449dc3 100644 --- a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff @@ -4,27 +4,17 @@ fn main() -> () { let mut _0: (); let _1: (); - let mut _2: ((), u8, u8); bb0: { - StorageLive(_2); -- _2 = (const (), const 0_u8, const 0_u8); -- _1 = encode(move _2) -> [return: bb1, unwind continue]; -+ _2 = const ((), 0_u8, 0_u8); -+ _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind continue]; + _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind continue]; } bb1: { - StorageDead(_2); return; } -+ } -+ -+ alloc8 (size: 2, align: 1) { -+ 00 00 │ .. -+ } -+ -+ alloc7 (size: 2, align: 1) { -+ 00 00 │ .. + } + + alloc5 (size: 2, align: 1) { + 00 00 │ .. } diff --git a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff index 015180db896b1..90d431069bdb0 100644 --- a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff @@ -4,36 +4,17 @@ fn main() -> () { let mut _0: (); let _1: (); - let mut _2: ((u8, u8),); - let mut _3: (u8, u8); bb0: { - StorageLive(_2); - StorageLive(_3); -- _3 = (const 1_u8, const 2_u8); -- _2 = (move _3,); -+ _3 = const (1_u8, 2_u8); -+ _2 = const ((1_u8, 2_u8),); - StorageDead(_3); -- _1 = test(move _2) -> [return: bb1, unwind unreachable]; -+ _1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind unreachable]; + _1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind unreachable]; } bb1: { - StorageDead(_2); return; } -+ } -+ -+ alloc12 (size: 2, align: 1) { -+ 01 02 │ .. -+ } -+ -+ alloc11 (size: 2, align: 1) { -+ 01 02 │ .. -+ } -+ -+ alloc8 (size: 2, align: 1) { -+ 01 02 │ .. + } + + alloc7 (size: 2, align: 1) { + 01 02 │ .. } diff --git a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff index 8e41705c1af21..5978061d96dc2 100644 --- a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff @@ -4,36 +4,17 @@ fn main() -> () { let mut _0: (); let _1: (); - let mut _2: ((u8, u8),); - let mut _3: (u8, u8); bb0: { - StorageLive(_2); - StorageLive(_3); -- _3 = (const 1_u8, const 2_u8); -- _2 = (move _3,); -+ _3 = const (1_u8, 2_u8); -+ _2 = const ((1_u8, 2_u8),); - StorageDead(_3); -- _1 = test(move _2) -> [return: bb1, unwind continue]; -+ _1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind continue]; + _1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind continue]; } bb1: { - StorageDead(_2); return; } -+ } -+ -+ alloc12 (size: 2, align: 1) { -+ 01 02 │ .. -+ } -+ -+ alloc11 (size: 2, align: 1) { -+ 01 02 │ .. -+ } -+ -+ alloc8 (size: 2, align: 1) { -+ 01 02 │ .. + } + + alloc7 (size: 2, align: 1) { + 01 02 │ .. } diff --git a/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-abort.diff b/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-abort.diff index a538756ba2d04..9b1d2ee890ef6 100644 --- a/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-abort.diff +++ b/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-abort.diff @@ -11,17 +11,10 @@ let mut _7: std::option::Option; let mut _8: &std::fmt::Formatter<'_>; let mut _9: isize; - let mut _11: &mut std::fmt::Formatter<'_>; - let mut _12: &T; - let mut _13: core::num::flt2dec::Sign; - let mut _14: u32; - let mut _15: u32; - let mut _16: usize; - let mut _17: bool; - let mut _18: &mut std::fmt::Formatter<'_>; - let mut _19: &T; - let mut _20: core::num::flt2dec::Sign; - let mut _21: bool; + let mut _11: core::num::flt2dec::Sign; + let mut _12: u32; + let mut _13: u32; + let mut _14: core::num::flt2dec::Sign; scope 1 { debug force_sign => _4; let _6: core::num::flt2dec::Sign; @@ -48,14 +41,12 @@ } bb2: { -- _6 = MinusPlus; -+ _6 = const MinusPlus; + _6 = const MinusPlus; goto -> bb4; } bb3: { -- _6 = Minus; -+ _6 = const Minus; + _6 = const Minus; goto -> bb4; } @@ -74,30 +65,30 @@ bb6: { _10 = ((_7 as Some).0: usize); + StorageLive(_11); + _11 = _6; + StorageLive(_12); StorageLive(_13); - _13 = _6; - StorageLive(_14); - StorageLive(_15); - _15 = _10 as u32 (IntToInt); - _14 = Add(move _15, const 1_u32); - StorageDead(_15); - _0 = float_to_exponential_common_exact::(_1, _2, move _13, move _14, _3) -> [return: bb7, unwind unreachable]; + _13 = _10 as u32 (IntToInt); + _12 = Add(move _13, const 1_u32); + StorageDead(_13); + _0 = float_to_exponential_common_exact::(_1, _2, move _11, move _12, _3) -> [return: bb7, unwind unreachable]; } bb7: { - StorageDead(_14); - StorageDead(_13); + StorageDead(_12); + StorageDead(_11); goto -> bb10; } bb8: { - StorageLive(_20); - _20 = _6; - _0 = float_to_exponential_common_shortest::(_1, _2, move _20, _3) -> [return: bb9, unwind unreachable]; + StorageLive(_14); + _14 = _6; + _0 = float_to_exponential_common_shortest::(_1, _2, move _14, _3) -> [return: bb9, unwind unreachable]; } bb9: { - StorageDead(_20); + StorageDead(_14); goto -> bb10; } diff --git a/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-unwind.diff b/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-unwind.diff index 8a3dcfab44bd2..4f8b8dc7c60c8 100644 --- a/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-unwind.diff @@ -11,17 +11,10 @@ let mut _7: std::option::Option; let mut _8: &std::fmt::Formatter<'_>; let mut _9: isize; - let mut _11: &mut std::fmt::Formatter<'_>; - let mut _12: &T; - let mut _13: core::num::flt2dec::Sign; - let mut _14: u32; - let mut _15: u32; - let mut _16: usize; - let mut _17: bool; - let mut _18: &mut std::fmt::Formatter<'_>; - let mut _19: &T; - let mut _20: core::num::flt2dec::Sign; - let mut _21: bool; + let mut _11: core::num::flt2dec::Sign; + let mut _12: u32; + let mut _13: u32; + let mut _14: core::num::flt2dec::Sign; scope 1 { debug force_sign => _4; let _6: core::num::flt2dec::Sign; @@ -48,14 +41,12 @@ } bb2: { -- _6 = MinusPlus; -+ _6 = const MinusPlus; + _6 = const MinusPlus; goto -> bb4; } bb3: { -- _6 = Minus; -+ _6 = const Minus; + _6 = const Minus; goto -> bb4; } @@ -74,30 +65,30 @@ bb6: { _10 = ((_7 as Some).0: usize); + StorageLive(_11); + _11 = _6; + StorageLive(_12); StorageLive(_13); - _13 = _6; - StorageLive(_14); - StorageLive(_15); - _15 = _10 as u32 (IntToInt); - _14 = Add(move _15, const 1_u32); - StorageDead(_15); - _0 = float_to_exponential_common_exact::(_1, _2, move _13, move _14, _3) -> [return: bb7, unwind continue]; + _13 = _10 as u32 (IntToInt); + _12 = Add(move _13, const 1_u32); + StorageDead(_13); + _0 = float_to_exponential_common_exact::(_1, _2, move _11, move _12, _3) -> [return: bb7, unwind continue]; } bb7: { - StorageDead(_14); - StorageDead(_13); + StorageDead(_12); + StorageDead(_11); goto -> bb10; } bb8: { - StorageLive(_20); - _20 = _6; - _0 = float_to_exponential_common_shortest::(_1, _2, move _20, _3) -> [return: bb9, unwind continue]; + StorageLive(_14); + _14 = _6; + _0 = float_to_exponential_common_shortest::(_1, _2, move _14, _3) -> [return: bb9, unwind continue]; } bb9: { - StorageDead(_20); + StorageDead(_14); goto -> bb10; } diff --git a/tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-abort.diff b/tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-abort.diff index dc0ab255afd9d..52f4e9a84c270 100644 --- a/tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-abort.diff @@ -9,60 +9,58 @@ debug _x => _1; } + scope 2 (inlined Vec::::new) { -+ let mut _3: alloc::raw_vec::RawVec; + } + scope 3 (inlined Box::>::new) { + debug x => _2; ++ let mut _3: usize; + let mut _4: usize; -+ let mut _5: usize; -+ let mut _6: *mut u8; -+ let mut _7: *const std::vec::Vec; ++ let mut _5: *mut u8; ++ let mut _6: *const std::vec::Vec; + scope 4 { + scope 5 (inlined alloc::alloc::exchange_malloc) { -+ debug size => _4; -+ debug align => _5; -+ let _8: std::alloc::Layout; -+ let mut _9: std::result::Result, std::alloc::AllocError>; -+ let mut _10: isize; -+ let mut _12: !; ++ debug size => _3; ++ debug align => _4; ++ let _7: std::alloc::Layout; ++ let mut _8: std::result::Result, std::alloc::AllocError>; ++ let mut _9: isize; ++ let mut _11: !; + scope 6 { -+ debug layout => _8; -+ let _11: std::ptr::NonNull<[u8]>; -+ let mut _13: &std::alloc::Global; ++ debug layout => _7; ++ let _10: std::ptr::NonNull<[u8]>; + scope 8 { -+ debug ptr => _11; ++ debug ptr => _10; + scope 18 (inlined NonNull::<[u8]>::as_mut_ptr) { -+ debug self => _11; -+ let mut _15: std::ptr::NonNull; ++ debug self => _10; ++ let mut _13: std::ptr::NonNull; + scope 19 (inlined NonNull::<[u8]>::as_non_null_ptr) { -+ debug self => _11; -+ let mut _16: *mut u8; -+ let mut _17: *mut [u8]; ++ debug self => _10; ++ let mut _14: *mut u8; ++ let mut _15: *mut [u8]; + scope 20 { + scope 21 (inlined NonNull::<[u8]>::as_ptr) { -+ debug self => _11; -+ let mut _18: *const [u8]; ++ debug self => _10; ++ let mut _16: *const [u8]; + } + scope 22 (inlined ptr::mut_ptr::::as_mut_ptr) { -+ debug self => _17; ++ debug self => _15; + } + scope 23 (inlined NonNull::::new_unchecked) { -+ debug ptr => _16; -+ let mut _19: *const u8; ++ debug ptr => _14; ++ let mut _17: *const u8; + scope 24 { + scope 25 (inlined NonNull::::new_unchecked::runtime::) { -+ debug ptr => _16; ++ debug ptr => _14; + scope 26 (inlined ptr::mut_ptr::::is_null) { -+ debug self => _16; -+ let mut _20: *mut u8; ++ debug self => _14; ++ let mut _18: *mut u8; + scope 27 { + scope 28 (inlined ptr::mut_ptr::::is_null::runtime_impl) { -+ debug ptr => _20; ++ debug ptr => _18; + scope 29 (inlined ptr::mut_ptr::::addr) { -+ debug self => _20; ++ debug self => _18; + scope 30 { + scope 31 (inlined ptr::mut_ptr::::cast::<()>) { -+ debug self => _20; ++ debug self => _18; + } + } + } @@ -75,31 +73,31 @@ + } + } + scope 32 (inlined NonNull::::as_ptr) { -+ debug self => _15; -+ let mut _21: *const u8; ++ debug self => _13; ++ let mut _19: *const u8; + } + } + } + scope 17 (inlined ::allocate) { + debug self => const _; -+ debug layout => _8; ++ debug layout => _7; + } + } + scope 7 { + scope 9 (inlined Layout::from_size_align_unchecked) { -+ debug size => _4; -+ debug align => _5; -+ let mut _14: std::ptr::Alignment; ++ debug size => _3; ++ debug align => _4; ++ let mut _12: std::ptr::Alignment; + scope 10 { + scope 11 (inlined std::ptr::Alignment::new_unchecked) { -+ debug align => _5; ++ debug align => _4; + scope 12 { + scope 14 (inlined std::ptr::Alignment::new_unchecked::runtime) { -+ debug align => _5; ++ debug align => _4; + scope 15 (inlined core::num::::is_power_of_two) { -+ debug self => _5; ++ debug self => _4; + scope 16 (inlined core::num::::count_ones) { -+ debug self => _5; ++ debug self => _4; + } + } + } @@ -118,23 +116,18 @@ StorageLive(_1); StorageLive(_2); - _2 = Vec::::new() -> [return: bb1, unwind unreachable]; -+ StorageLive(_3); -+ _3 = const _; -+ _2 = Vec:: { buf: move _3, len: const 0_usize }; -+ StorageDead(_3); -+ _4 = SizeOf(std::vec::Vec); -+ _5 = AlignOf(std::vec::Vec); -+ StorageLive(_8); ++ _2 = Vec:: { buf: const _, len: const 0_usize }; ++ _3 = SizeOf(std::vec::Vec); ++ _4 = AlignOf(std::vec::Vec); ++ StorageLive(_7); ++ StorageLive(_10); + StorageLive(_11); + StorageLive(_12); -+ StorageLive(_13); -+ StorageLive(_14); -+ _14 = _5 as std::ptr::Alignment (Transmute); -+ _8 = Layout { size: _4, align: move _14 }; -+ StorageDead(_14); -+ StorageLive(_9); -+ _13 = const _; -+ _9 = std::alloc::Global::alloc_impl(move _13, _8, const false) -> [return: bb5, unwind unreachable]; ++ _12 = _4 as std::ptr::Alignment (Transmute); ++ _7 = Layout { size: _3, align: move _12 }; ++ StorageDead(_12); ++ StorageLive(_8); ++ _8 = std::alloc::Global::alloc_impl(const _, _7, const false) -> [return: bb5, unwind unreachable]; } bb1: { @@ -144,7 +137,7 @@ } bb2: { -+ _12 = handle_alloc_error(move _8) -> unwind unreachable; ++ _11 = handle_alloc_error(move _7) -> unwind unreachable; + } + + bb3: { @@ -152,36 +145,35 @@ + } + + bb4: { -+ _11 = ((_9 as Ok).0: std::ptr::NonNull<[u8]>); ++ _10 = ((_8 as Ok).0: std::ptr::NonNull<[u8]>); ++ StorageLive(_13); ++ StorageLive(_14); + StorageLive(_15); + StorageLive(_16); ++ _16 = (_10.0: *const [u8]); ++ _15 = move _16 as *mut [u8] (PtrToPtr); ++ StorageDead(_16); ++ _14 = _15 as *mut u8 (PtrToPtr); ++ StorageDead(_15); + StorageLive(_17); + StorageLive(_18); -+ _18 = (_11.0: *const [u8]); -+ _17 = move _18 as *mut [u8] (PtrToPtr); ++ _17 = _14 as *const u8 (PointerCoercion(MutToConstPointer)); ++ _13 = NonNull:: { pointer: _17 }; + StorageDead(_18); -+ _16 = _17 as *mut u8 (PtrToPtr); + StorageDead(_17); ++ StorageDead(_14); + StorageLive(_19); -+ StorageLive(_20); -+ _19 = _16 as *const u8 (PointerCoercion(MutToConstPointer)); -+ _15 = NonNull:: { pointer: _19 }; -+ StorageDead(_20); ++ _19 = (_13.0: *const u8); ++ _5 = move _19 as *mut u8 (PtrToPtr); + StorageDead(_19); -+ StorageDead(_16); -+ StorageLive(_21); -+ _21 = (_15.0: *const u8); -+ _6 = move _21 as *mut u8 (PtrToPtr); -+ StorageDead(_21); -+ StorageDead(_15); -+ StorageDead(_9); + StorageDead(_13); -+ StorageDead(_12); -+ StorageDead(_11); + StorageDead(_8); -+ _1 = ShallowInitBox(move _6, std::vec::Vec); -+ _7 = (((_1.0: std::ptr::Unique>).0: std::ptr::NonNull>).0: *const std::vec::Vec); -+ (*_7) = move _2; ++ StorageDead(_11); ++ StorageDead(_10); ++ StorageDead(_7); ++ _1 = ShallowInitBox(move _5, std::vec::Vec); ++ _6 = (((_1.0: std::ptr::Unique>).0: std::ptr::NonNull>).0: *const std::vec::Vec); ++ (*_6) = move _2; StorageDead(_2); _0 = const (); - drop(_1) -> [return: bb3, unwind unreachable]; @@ -192,8 +184,8 @@ - StorageDead(_1); - return; + bb5: { -+ _10 = discriminant(_9); -+ switchInt(move _10) -> [0: bb4, 1: bb2, otherwise: bb3]; ++ _9 = discriminant(_8); ++ switchInt(move _9) -> [0: bb4, 1: bb2, otherwise: bb3]; } } diff --git a/tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-unwind.diff b/tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-unwind.diff index 675292f06d669..4eab3fec06939 100644 --- a/tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-unwind.diff @@ -9,60 +9,58 @@ debug _x => _1; } + scope 2 (inlined Vec::::new) { -+ let mut _3: alloc::raw_vec::RawVec; + } + scope 3 (inlined Box::>::new) { + debug x => _2; ++ let mut _3: usize; + let mut _4: usize; -+ let mut _5: usize; -+ let mut _6: *mut u8; -+ let mut _7: *const std::vec::Vec; ++ let mut _5: *mut u8; ++ let mut _6: *const std::vec::Vec; + scope 4 { + scope 5 (inlined alloc::alloc::exchange_malloc) { -+ debug size => _4; -+ debug align => _5; -+ let _8: std::alloc::Layout; -+ let mut _9: std::result::Result, std::alloc::AllocError>; -+ let mut _10: isize; -+ let mut _12: !; ++ debug size => _3; ++ debug align => _4; ++ let _7: std::alloc::Layout; ++ let mut _8: std::result::Result, std::alloc::AllocError>; ++ let mut _9: isize; ++ let mut _11: !; + scope 6 { -+ debug layout => _8; -+ let _11: std::ptr::NonNull<[u8]>; -+ let mut _13: &std::alloc::Global; ++ debug layout => _7; ++ let _10: std::ptr::NonNull<[u8]>; + scope 8 { -+ debug ptr => _11; ++ debug ptr => _10; + scope 18 (inlined NonNull::<[u8]>::as_mut_ptr) { -+ debug self => _11; -+ let mut _15: std::ptr::NonNull; ++ debug self => _10; ++ let mut _13: std::ptr::NonNull; + scope 19 (inlined NonNull::<[u8]>::as_non_null_ptr) { -+ debug self => _11; -+ let mut _16: *mut u8; -+ let mut _17: *mut [u8]; ++ debug self => _10; ++ let mut _14: *mut u8; ++ let mut _15: *mut [u8]; + scope 20 { + scope 21 (inlined NonNull::<[u8]>::as_ptr) { -+ debug self => _11; -+ let mut _18: *const [u8]; ++ debug self => _10; ++ let mut _16: *const [u8]; + } + scope 22 (inlined ptr::mut_ptr::::as_mut_ptr) { -+ debug self => _17; ++ debug self => _15; + } + scope 23 (inlined NonNull::::new_unchecked) { -+ debug ptr => _16; -+ let mut _19: *const u8; ++ debug ptr => _14; ++ let mut _17: *const u8; + scope 24 { + scope 25 (inlined NonNull::::new_unchecked::runtime::) { -+ debug ptr => _16; ++ debug ptr => _14; + scope 26 (inlined ptr::mut_ptr::::is_null) { -+ debug self => _16; -+ let mut _20: *mut u8; ++ debug self => _14; ++ let mut _18: *mut u8; + scope 27 { + scope 28 (inlined ptr::mut_ptr::::is_null::runtime_impl) { -+ debug ptr => _20; ++ debug ptr => _18; + scope 29 (inlined ptr::mut_ptr::::addr) { -+ debug self => _20; ++ debug self => _18; + scope 30 { + scope 31 (inlined ptr::mut_ptr::::cast::<()>) { -+ debug self => _20; ++ debug self => _18; + } + } + } @@ -75,31 +73,31 @@ + } + } + scope 32 (inlined NonNull::::as_ptr) { -+ debug self => _15; -+ let mut _21: *const u8; ++ debug self => _13; ++ let mut _19: *const u8; + } + } + } + scope 17 (inlined ::allocate) { + debug self => const _; -+ debug layout => _8; ++ debug layout => _7; + } + } + scope 7 { + scope 9 (inlined Layout::from_size_align_unchecked) { -+ debug size => _4; -+ debug align => _5; -+ let mut _14: std::ptr::Alignment; ++ debug size => _3; ++ debug align => _4; ++ let mut _12: std::ptr::Alignment; + scope 10 { + scope 11 (inlined std::ptr::Alignment::new_unchecked) { -+ debug align => _5; ++ debug align => _4; + scope 12 { + scope 14 (inlined std::ptr::Alignment::new_unchecked::runtime) { -+ debug align => _5; ++ debug align => _4; + scope 15 (inlined core::num::::is_power_of_two) { -+ debug self => _5; ++ debug self => _4; + scope 16 (inlined core::num::::count_ones) { -+ debug self => _5; ++ debug self => _4; + } + } + } @@ -118,23 +116,18 @@ StorageLive(_1); StorageLive(_2); - _2 = Vec::::new() -> [return: bb1, unwind continue]; -+ StorageLive(_3); -+ _3 = const _; -+ _2 = Vec:: { buf: move _3, len: const 0_usize }; -+ StorageDead(_3); -+ _4 = SizeOf(std::vec::Vec); -+ _5 = AlignOf(std::vec::Vec); -+ StorageLive(_8); ++ _2 = Vec:: { buf: const _, len: const 0_usize }; ++ _3 = SizeOf(std::vec::Vec); ++ _4 = AlignOf(std::vec::Vec); ++ StorageLive(_7); ++ StorageLive(_10); + StorageLive(_11); + StorageLive(_12); -+ StorageLive(_13); -+ StorageLive(_14); -+ _14 = _5 as std::ptr::Alignment (Transmute); -+ _8 = Layout { size: _4, align: move _14 }; -+ StorageDead(_14); -+ StorageLive(_9); -+ _13 = const _; -+ _9 = std::alloc::Global::alloc_impl(move _13, _8, const false) -> [return: bb7, unwind: bb3]; ++ _12 = _4 as std::ptr::Alignment (Transmute); ++ _7 = Layout { size: _3, align: move _12 }; ++ StorageDead(_12); ++ StorageLive(_8); ++ _8 = std::alloc::Global::alloc_impl(const _, _7, const false) -> [return: bb7, unwind: bb3]; } bb1: { @@ -161,7 +154,7 @@ - bb4 (cleanup): { - resume; + bb4: { -+ _12 = handle_alloc_error(move _8) -> bb3; ++ _11 = handle_alloc_error(move _7) -> bb3; + } + + bb5: { @@ -169,44 +162,43 @@ + } + + bb6: { -+ _11 = ((_9 as Ok).0: std::ptr::NonNull<[u8]>); ++ _10 = ((_8 as Ok).0: std::ptr::NonNull<[u8]>); ++ StorageLive(_13); ++ StorageLive(_14); + StorageLive(_15); + StorageLive(_16); ++ _16 = (_10.0: *const [u8]); ++ _15 = move _16 as *mut [u8] (PtrToPtr); ++ StorageDead(_16); ++ _14 = _15 as *mut u8 (PtrToPtr); ++ StorageDead(_15); + StorageLive(_17); + StorageLive(_18); -+ _18 = (_11.0: *const [u8]); -+ _17 = move _18 as *mut [u8] (PtrToPtr); ++ _17 = _14 as *const u8 (PointerCoercion(MutToConstPointer)); ++ _13 = NonNull:: { pointer: _17 }; + StorageDead(_18); -+ _16 = _17 as *mut u8 (PtrToPtr); + StorageDead(_17); ++ StorageDead(_14); + StorageLive(_19); -+ StorageLive(_20); -+ _19 = _16 as *const u8 (PointerCoercion(MutToConstPointer)); -+ _15 = NonNull:: { pointer: _19 }; -+ StorageDead(_20); ++ _19 = (_13.0: *const u8); ++ _5 = move _19 as *mut u8 (PtrToPtr); + StorageDead(_19); -+ StorageDead(_16); -+ StorageLive(_21); -+ _21 = (_15.0: *const u8); -+ _6 = move _21 as *mut u8 (PtrToPtr); -+ StorageDead(_21); -+ StorageDead(_15); -+ StorageDead(_9); + StorageDead(_13); -+ StorageDead(_12); -+ StorageDead(_11); + StorageDead(_8); -+ _1 = ShallowInitBox(move _6, std::vec::Vec); -+ _7 = (((_1.0: std::ptr::Unique>).0: std::ptr::NonNull>).0: *const std::vec::Vec); -+ (*_7) = move _2; ++ StorageDead(_11); ++ StorageDead(_10); ++ StorageDead(_7); ++ _1 = ShallowInitBox(move _5, std::vec::Vec); ++ _6 = (((_1.0: std::ptr::Unique>).0: std::ptr::NonNull>).0: *const std::vec::Vec); ++ (*_6) = move _2; + StorageDead(_2); + _0 = const (); + drop(_1) -> [return: bb1, unwind: bb2]; + } + + bb7: { -+ _10 = discriminant(_9); -+ switchInt(move _10) -> [0: bb6, 1: bb4, otherwise: bb5]; ++ _9 = discriminant(_8); ++ switchInt(move _9) -> [0: bb6, 1: bb4, otherwise: bb5]; } } diff --git a/tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir b/tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir index 6837da27a96f9..a07e06c14ed7c 100644 --- a/tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir +++ b/tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir @@ -17,7 +17,7 @@ fn b(_1: &mut Box) -> &mut T { StorageLive(_3); StorageLive(_4); _4 = &mut (*_1); - _5 = deref_copy (*_4); + _5 = (*_4); _6 = (((_5.0: std::ptr::Unique).0: std::ptr::NonNull).0: *const T); _3 = &mut (*_6); _2 = &mut (*_3); diff --git a/tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir b/tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir index d09bfc33ff13a..f6a48b8700251 100644 --- a/tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir +++ b/tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir @@ -15,7 +15,7 @@ fn d(_1: &Box) -> &T { StorageLive(_2); StorageLive(_3); _3 = &(*_1); - _4 = deref_copy (*_3); + _4 = (*_3); _5 = (((_4.0: std::ptr::Unique).0: std::ptr::NonNull).0: *const T); _2 = &(*_5); _0 = &(*_2); diff --git a/tests/mir-opt/issue_101973.inner.ConstProp.panic-abort.diff b/tests/mir-opt/issue_101973.inner.ConstProp.panic-abort.diff index ce490e894f038..e9f492769d818 100644 --- a/tests/mir-opt/issue_101973.inner.ConstProp.panic-abort.diff +++ b/tests/mir-opt/issue_101973.inner.ConstProp.panic-abort.diff @@ -10,67 +10,51 @@ let mut _5: u32; let mut _6: u32; let mut _7: u32; - let mut _8: u32; - let mut _9: u32; - let mut _10: u32; - let mut _11: bool; - let mut _12: u32; - let mut _13: bool; scope 1 (inlined imm8) { debug x => _1; - let mut _14: u32; - let mut _15: u32; + let mut _8: u32; + let mut _9: u32; scope 2 { debug out => _4; } } scope 3 (inlined core::num::::rotate_right) { debug self => _4; - debug n => _6; + debug n => _5; } bb0: { StorageLive(_2); StorageLive(_3); StorageLive(_4); - StorageLive(_15); - StorageLive(_14); - _14 = Shr(_1, const 0_i32); - _15 = BitAnd(move _14, const 255_u32); - StorageDead(_14); - _4 = BitOr(const 0_u32, move _15); - StorageDead(_15); + StorageLive(_9); + StorageLive(_8); + _8 = Shr(_1, const 0_i32); + _9 = BitAnd(move _8, const 255_u32); + StorageDead(_8); + _4 = BitOr(const 0_u32, move _9); + StorageDead(_9); + StorageLive(_5); StorageLive(_6); StorageLive(_7); - StorageLive(_8); -- _10 = const 8_i32 as u32 (IntToInt); -- _11 = Lt(move _10, const 32_u32); -- assert(move _11, "attempt to shift right by `{}`, which would overflow", const 8_i32) -> [success: bb1, unwind unreachable]; -+ _10 = const 8_u32; -+ _11 = const true; -+ assert(const true, "attempt to shift right by `{}`, which would overflow", const 8_i32) -> [success: bb1, unwind unreachable]; + assert(const true, "attempt to shift right by `{}`, which would overflow", const 8_i32) -> [success: bb1, unwind unreachable]; } bb1: { - _8 = Shr(_1, const 8_i32); - _7 = BitAnd(move _8, const 15_u32); - StorageDead(_8); -- _12 = const 1_i32 as u32 (IntToInt); -- _13 = Lt(move _12, const 32_u32); -- assert(move _13, "attempt to shift left by `{}`, which would overflow", const 1_i32) -> [success: bb2, unwind unreachable]; -+ _12 = const 1_u32; -+ _13 = const true; -+ assert(const true, "attempt to shift left by `{}`, which would overflow", const 1_i32) -> [success: bb2, unwind unreachable]; + _7 = Shr(_1, const 8_i32); + _6 = BitAnd(move _7, const 15_u32); + StorageDead(_7); + assert(const true, "attempt to shift left by `{}`, which would overflow", const 1_i32) -> [success: bb2, unwind unreachable]; } bb2: { - _6 = Shl(move _7, const 1_i32); - StorageDead(_7); - _3 = rotate_right::(move _4, move _6) -> [return: bb3, unwind unreachable]; + _5 = Shl(move _6, const 1_i32); + StorageDead(_6); + _3 = rotate_right::(move _4, move _5) -> [return: bb3, unwind unreachable]; } bb3: { - StorageDead(_6); + StorageDead(_5); StorageDead(_4); _2 = move _3 as i32 (IntToInt); StorageDead(_3); diff --git a/tests/mir-opt/issue_101973.inner.ConstProp.panic-unwind.diff b/tests/mir-opt/issue_101973.inner.ConstProp.panic-unwind.diff index 254557b9947f1..c0b49ad6e6d4b 100644 --- a/tests/mir-opt/issue_101973.inner.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/issue_101973.inner.ConstProp.panic-unwind.diff @@ -10,67 +10,51 @@ let mut _5: u32; let mut _6: u32; let mut _7: u32; - let mut _8: u32; - let mut _9: u32; - let mut _10: u32; - let mut _11: bool; - let mut _12: u32; - let mut _13: bool; scope 1 (inlined imm8) { debug x => _1; - let mut _14: u32; - let mut _15: u32; + let mut _8: u32; + let mut _9: u32; scope 2 { debug out => _4; } } scope 3 (inlined core::num::::rotate_right) { debug self => _4; - debug n => _6; + debug n => _5; } bb0: { StorageLive(_2); StorageLive(_3); StorageLive(_4); - StorageLive(_15); - StorageLive(_14); - _14 = Shr(_1, const 0_i32); - _15 = BitAnd(move _14, const 255_u32); - StorageDead(_14); - _4 = BitOr(const 0_u32, move _15); - StorageDead(_15); + StorageLive(_9); + StorageLive(_8); + _8 = Shr(_1, const 0_i32); + _9 = BitAnd(move _8, const 255_u32); + StorageDead(_8); + _4 = BitOr(const 0_u32, move _9); + StorageDead(_9); + StorageLive(_5); StorageLive(_6); StorageLive(_7); - StorageLive(_8); -- _10 = const 8_i32 as u32 (IntToInt); -- _11 = Lt(move _10, const 32_u32); -- assert(move _11, "attempt to shift right by `{}`, which would overflow", const 8_i32) -> [success: bb1, unwind continue]; -+ _10 = const 8_u32; -+ _11 = const true; -+ assert(const true, "attempt to shift right by `{}`, which would overflow", const 8_i32) -> [success: bb1, unwind continue]; + assert(const true, "attempt to shift right by `{}`, which would overflow", const 8_i32) -> [success: bb1, unwind continue]; } bb1: { - _8 = Shr(_1, const 8_i32); - _7 = BitAnd(move _8, const 15_u32); - StorageDead(_8); -- _12 = const 1_i32 as u32 (IntToInt); -- _13 = Lt(move _12, const 32_u32); -- assert(move _13, "attempt to shift left by `{}`, which would overflow", const 1_i32) -> [success: bb2, unwind continue]; -+ _12 = const 1_u32; -+ _13 = const true; -+ assert(const true, "attempt to shift left by `{}`, which would overflow", const 1_i32) -> [success: bb2, unwind continue]; + _7 = Shr(_1, const 8_i32); + _6 = BitAnd(move _7, const 15_u32); + StorageDead(_7); + assert(const true, "attempt to shift left by `{}`, which would overflow", const 1_i32) -> [success: bb2, unwind continue]; } bb2: { - _6 = Shl(move _7, const 1_i32); - StorageDead(_7); - _3 = rotate_right::(move _4, move _6) -> [return: bb3, unwind unreachable]; + _5 = Shl(move _6, const 1_i32); + StorageDead(_6); + _3 = rotate_right::(move _4, move _5) -> [return: bb3, unwind unreachable]; } bb3: { - StorageDead(_6); + StorageDead(_5); StorageDead(_4); _2 = move _3 as i32 (IntToInt); StorageDead(_3); diff --git a/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.mir index 8304cb45b3544..a5a07383a6b12 100644 --- a/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.mir @@ -55,7 +55,7 @@ fn checked_shl(_1: u32, _2: u32) -> Option { } bb3: { - _0 = Option::::None; + _0 = const Option::::None; goto -> bb4; } @@ -66,3 +66,7 @@ fn checked_shl(_1: u32, _2: u32) -> Option { return; } } + +alloc8 (size: 8, align: 4) { + 00 00 00 00 __ __ __ __ │ ....░░░░ +} diff --git a/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir index 0d79f2de10d7b..5d58bdb9e7392 100644 --- a/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir @@ -69,7 +69,7 @@ fn int_range(_1: usize, _2: usize) -> () { bb2: { StorageDead(_16); StorageDead(_15); - _8 = Option::::None; + _8 = const Option::::None; goto -> bb5; } @@ -115,3 +115,7 @@ fn int_range(_1: usize, _2: usize) -> () { unreachable; } } + +alloc11 (size: 16, align: 8) { + 00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ │ ........░░░░░░░░ +} diff --git a/tests/mir-opt/pre-codegen/loops.rs b/tests/mir-opt/pre-codegen/loops.rs index f3ba409229d6e..15c155de58655 100644 --- a/tests/mir-opt/pre-codegen/loops.rs +++ b/tests/mir-opt/pre-codegen/loops.rs @@ -1,5 +1,6 @@ // compile-flags: -O -Zmir-opt-level=2 -g // needs-unwind +// only-64bit #![crate_type = "lib"] diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-abort.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-abort.diff index 681e9666e0fb0..4c26145e5752d 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-abort.diff +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-abort.diff @@ -4,60 +4,44 @@ fn main() -> () { let mut _0: (); let _1: i32; - let mut _2: (i32, bool); - let mut _4: [i32; 6]; - let _5: usize; - let mut _6: usize; - let mut _7: bool; - let mut _9: u32; + let mut _3: [i32; 6]; + let _4: usize; + let mut _5: u32; scope 1 { debug x => _1; - let _3: i32; + let _2: i32; scope 2 { - debug y => _3; - let _8: u32; + debug y => _2; scope 3 { - debug z => _9; + debug z => _5; } } } bb0: { StorageLive(_1); -- _2 = CheckedAdd(const 2_i32, const 2_i32); -- assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind unreachable]; -+ _2 = const (4_i32, false); -+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind unreachable]; + assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind unreachable]; } bb1: { -- _1 = move (_2.0: i32); -+ _1 = const 4_i32; + _1 = const 4_i32; + StorageLive(_2); StorageLive(_3); + _3 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32]; StorageLive(_4); - _4 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32]; - StorageLive(_5); - _5 = const 3_usize; - _6 = const 6_usize; -- _7 = Lt(_5, _6); -- assert(move _7, "index out of bounds: the length is {} but the index is {}", move _6, _5) -> [success: bb2, unwind unreachable]; -+ _7 = const true; -+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 6_usize, const 3_usize) -> [success: bb2, unwind unreachable]; + _4 = const 3_usize; + assert(const true, "index out of bounds: the length is {} but the index is {}", const 6_usize, const 3_usize) -> [success: bb2, unwind unreachable]; } bb2: { -- _3 = _4[_5]; -+ _3 = const 3_i32; - StorageDead(_5); +- _2 = _3[_4]; ++ _2 = const 3_i32; StorageDead(_4); - _9 = const 42_u32; StorageDead(_3); + _5 = const 42_u32; + StorageDead(_2); StorageDead(_1); return; } -+ } -+ -+ alloc5 (size: 8, align: 4) { -+ 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-unwind.diff index db16b8d82d2cb..2a0bc5dcfd8dd 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-unwind.diff @@ -4,60 +4,44 @@ fn main() -> () { let mut _0: (); let _1: i32; - let mut _2: (i32, bool); - let mut _4: [i32; 6]; - let _5: usize; - let mut _6: usize; - let mut _7: bool; - let mut _9: u32; + let mut _3: [i32; 6]; + let _4: usize; + let mut _5: u32; scope 1 { debug x => _1; - let _3: i32; + let _2: i32; scope 2 { - debug y => _3; - let _8: u32; + debug y => _2; scope 3 { - debug z => _9; + debug z => _5; } } } bb0: { StorageLive(_1); -- _2 = CheckedAdd(const 2_i32, const 2_i32); -- assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind continue]; -+ _2 = const (4_i32, false); -+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind continue]; + assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind continue]; } bb1: { -- _1 = move (_2.0: i32); -+ _1 = const 4_i32; + _1 = const 4_i32; + StorageLive(_2); StorageLive(_3); + _3 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32]; StorageLive(_4); - _4 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32]; - StorageLive(_5); - _5 = const 3_usize; - _6 = const 6_usize; -- _7 = Lt(_5, _6); -- assert(move _7, "index out of bounds: the length is {} but the index is {}", move _6, _5) -> [success: bb2, unwind continue]; -+ _7 = const true; -+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 6_usize, const 3_usize) -> [success: bb2, unwind continue]; + _4 = const 3_usize; + assert(const true, "index out of bounds: the length is {} but the index is {}", const 6_usize, const 3_usize) -> [success: bb2, unwind continue]; } bb2: { -- _3 = _4[_5]; -+ _3 = const 3_i32; - StorageDead(_5); +- _2 = _3[_4]; ++ _2 = const 3_i32; StorageDead(_4); - _9 = const 42_u32; StorageDead(_3); + _5 = const 42_u32; + StorageDead(_2); StorageDead(_1); return; } -+ } -+ -+ alloc5 (size: 8, align: 4) { -+ 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-abort.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-abort.diff index 681e9666e0fb0..4c26145e5752d 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-abort.diff @@ -4,60 +4,44 @@ fn main() -> () { let mut _0: (); let _1: i32; - let mut _2: (i32, bool); - let mut _4: [i32; 6]; - let _5: usize; - let mut _6: usize; - let mut _7: bool; - let mut _9: u32; + let mut _3: [i32; 6]; + let _4: usize; + let mut _5: u32; scope 1 { debug x => _1; - let _3: i32; + let _2: i32; scope 2 { - debug y => _3; - let _8: u32; + debug y => _2; scope 3 { - debug z => _9; + debug z => _5; } } } bb0: { StorageLive(_1); -- _2 = CheckedAdd(const 2_i32, const 2_i32); -- assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind unreachable]; -+ _2 = const (4_i32, false); -+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind unreachable]; + assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind unreachable]; } bb1: { -- _1 = move (_2.0: i32); -+ _1 = const 4_i32; + _1 = const 4_i32; + StorageLive(_2); StorageLive(_3); + _3 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32]; StorageLive(_4); - _4 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32]; - StorageLive(_5); - _5 = const 3_usize; - _6 = const 6_usize; -- _7 = Lt(_5, _6); -- assert(move _7, "index out of bounds: the length is {} but the index is {}", move _6, _5) -> [success: bb2, unwind unreachable]; -+ _7 = const true; -+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 6_usize, const 3_usize) -> [success: bb2, unwind unreachable]; + _4 = const 3_usize; + assert(const true, "index out of bounds: the length is {} but the index is {}", const 6_usize, const 3_usize) -> [success: bb2, unwind unreachable]; } bb2: { -- _3 = _4[_5]; -+ _3 = const 3_i32; - StorageDead(_5); +- _2 = _3[_4]; ++ _2 = const 3_i32; StorageDead(_4); - _9 = const 42_u32; StorageDead(_3); + _5 = const 42_u32; + StorageDead(_2); StorageDead(_1); return; } -+ } -+ -+ alloc5 (size: 8, align: 4) { -+ 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-unwind.diff index db16b8d82d2cb..2a0bc5dcfd8dd 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-unwind.diff @@ -4,60 +4,44 @@ fn main() -> () { let mut _0: (); let _1: i32; - let mut _2: (i32, bool); - let mut _4: [i32; 6]; - let _5: usize; - let mut _6: usize; - let mut _7: bool; - let mut _9: u32; + let mut _3: [i32; 6]; + let _4: usize; + let mut _5: u32; scope 1 { debug x => _1; - let _3: i32; + let _2: i32; scope 2 { - debug y => _3; - let _8: u32; + debug y => _2; scope 3 { - debug z => _9; + debug z => _5; } } } bb0: { StorageLive(_1); -- _2 = CheckedAdd(const 2_i32, const 2_i32); -- assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind continue]; -+ _2 = const (4_i32, false); -+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind continue]; + assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind continue]; } bb1: { -- _1 = move (_2.0: i32); -+ _1 = const 4_i32; + _1 = const 4_i32; + StorageLive(_2); StorageLive(_3); + _3 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32]; StorageLive(_4); - _4 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32]; - StorageLive(_5); - _5 = const 3_usize; - _6 = const 6_usize; -- _7 = Lt(_5, _6); -- assert(move _7, "index out of bounds: the length is {} but the index is {}", move _6, _5) -> [success: bb2, unwind continue]; -+ _7 = const true; -+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 6_usize, const 3_usize) -> [success: bb2, unwind continue]; + _4 = const 3_usize; + assert(const true, "index out of bounds: the length is {} but the index is {}", const 6_usize, const 3_usize) -> [success: bb2, unwind continue]; } bb2: { -- _3 = _4[_5]; -+ _3 = const 3_i32; - StorageDead(_5); +- _2 = _3[_4]; ++ _2 = const 3_i32; StorageDead(_4); - _9 = const 42_u32; StorageDead(_3); + _5 = const 42_u32; + StorageDead(_2); StorageDead(_1); return; } -+ } -+ -+ alloc5 (size: 8, align: 4) { -+ 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir index 9664ccfb094f7..e483d0ae0ecea 100644 --- a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir @@ -72,7 +72,7 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { bb2: { StorageDead(_19); StorageDead(_18); - _9 = Option::::None; + _9 = const Option::::None; goto -> bb5; } @@ -128,3 +128,7 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { unreachable; } } + +alloc8 (size: 8, align: 4) { + 00 00 00 00 __ __ __ __ │ ....░░░░ +} diff --git a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir index dc8b46b6c08e3..3c24f4da7aac6 100644 --- a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir @@ -72,7 +72,7 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { bb2: { StorageDead(_19); StorageDead(_18); - _9 = Option::::None; + _9 = const Option::::None; goto -> bb5; } @@ -136,3 +136,7 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { resume; } } + +alloc8 (size: 8, align: 4) { + 00 00 00 00 __ __ __ __ │ ....░░░░ +} diff --git a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir index fff713b5a795d..04cd61aced593 100644 --- a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir @@ -44,7 +44,7 @@ fn range_iter_next(_1: &mut std::ops::Range) -> Option { bb1: { StorageDead(_8); StorageDead(_7); - _0 = Option::::None; + _0 = const Option::::None; goto -> bb4; } @@ -69,3 +69,7 @@ fn range_iter_next(_1: &mut std::ops::Range) -> Option { return; } } + +alloc17 (size: 8, align: 4) { + 00 00 00 00 __ __ __ __ │ ....░░░░ +} diff --git a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir index cc12c0122b7eb..f766699c3e74d 100644 --- a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir @@ -44,7 +44,7 @@ fn range_iter_next(_1: &mut std::ops::Range) -> Option { bb1: { StorageDead(_8); StorageDead(_7); - _0 = Option::::None; + _0 = const Option::::None; goto -> bb4; } @@ -69,3 +69,7 @@ fn range_iter_next(_1: &mut std::ops::Range) -> Option { return; } } + +alloc17 (size: 8, align: 4) { + 00 00 00 00 __ __ __ __ │ ....░░░░ +} diff --git a/tests/mir-opt/pre-codegen/simple_option_map.ezmap.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/simple_option_map.ezmap.PreCodegen.after.mir index 48b780aea62e0..116e64170d16d 100644 --- a/tests/mir-opt/pre-codegen/simple_option_map.ezmap.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/simple_option_map.ezmap.PreCodegen.after.mir @@ -23,7 +23,7 @@ fn ezmap(_1: Option) -> Option { } bb1: { - _0 = Option::::None; + _0 = const Option::::None; goto -> bb3; } @@ -44,3 +44,7 @@ fn ezmap(_1: Option) -> Option { unreachable; } } + +alloc18 (size: 8, align: 4) { + 00 00 00 00 __ __ __ __ │ ....░░░░ +} diff --git a/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir index ed286beb4ca6b..d94939e8b5998 100644 --- a/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir @@ -82,24 +82,24 @@ fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:7:25: 7:39}, _2 bb0: { StorageLive(_4); - _3 = deref_copy (*_2); + _3 = (*_2); _4 = &((*_3).0: usize); StorageLive(_6); - _5 = deref_copy (*_2); + _5 = _3; _6 = &((*_5).1: usize); StorageLive(_8); - _7 = deref_copy (*_2); + _7 = _3; _8 = &((*_7).2: usize); StorageLive(_10); - _9 = deref_copy (*_2); + _9 = _3; _10 = &((*_9).3: usize); StorageLive(_16); StorageLive(_34); StorageLive(_35); StorageLive(_11); _11 = _8; - _12 = deref_copy _4; - _13 = deref_copy _11; + _12 = _4; + _13 = _11; StorageLive(_14); _14 = (*_12); StorageLive(_15); @@ -126,8 +126,8 @@ fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:7:25: 7:39}, _2 StorageLive(_37); StorageLive(_17); _17 = _6; - _18 = deref_copy _10; - _19 = deref_copy _17; + _18 = _10; + _19 = _17; StorageLive(_20); _20 = (*_18); StorageLive(_21); @@ -151,8 +151,8 @@ fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:7:25: 7:39}, _2 StorageLive(_39); StorageLive(_23); _23 = _4; - _24 = deref_copy _8; - _25 = deref_copy _23; + _24 = _8; + _25 = _23; StorageLive(_26); _26 = (*_24); StorageLive(_27); @@ -179,8 +179,8 @@ fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:7:25: 7:39}, _2 StorageLive(_41); StorageLive(_29); _29 = _10; - _30 = deref_copy _6; - _31 = deref_copy _29; + _30 = _6; + _31 = _29; StorageLive(_32); _32 = (*_30); StorageLive(_33); diff --git a/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir index 80c8cebff45c8..d9e118d879a6a 100644 --- a/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir @@ -4,46 +4,40 @@ fn variant_b::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:11:25: 11:41}, let mut _0: bool; let mut _3: &(usize, usize, usize, usize); let _4: usize; - let mut _5: &(usize, usize, usize, usize); + let _5: usize; let _6: usize; - let mut _7: &(usize, usize, usize, usize); - let _8: usize; - let mut _9: &(usize, usize, usize, usize); - let _10: usize; - let mut _11: bool; - let mut _12: bool; - let mut _13: bool; + let _7: usize; + let mut _8: bool; + let mut _9: bool; + let mut _10: bool; scope 1 { debug a => _4; - debug b => _6; - debug c => _8; - debug d => _10; + debug b => _5; + debug c => _6; + debug d => _7; } bb0: { - _3 = deref_copy (*_2); + _3 = (*_2); _4 = ((*_3).0: usize); - _5 = deref_copy (*_2); - _6 = ((*_5).1: usize); - _7 = deref_copy (*_2); - _8 = ((*_7).2: usize); - _9 = deref_copy (*_2); - _10 = ((*_9).3: usize); - StorageLive(_11); - _11 = Le(_4, _8); - switchInt(move _11) -> [0: bb2, otherwise: bb1]; + _5 = ((*_3).1: usize); + _6 = ((*_3).2: usize); + _7 = ((*_3).3: usize); + StorageLive(_8); + _8 = Le(_4, _6); + switchInt(move _8) -> [0: bb2, otherwise: bb1]; } bb1: { - StorageLive(_12); - _12 = Le(_10, _6); - switchInt(move _12) -> [0: bb2, otherwise: bb6]; + StorageLive(_9); + _9 = Le(_7, _5); + switchInt(move _9) -> [0: bb2, otherwise: bb6]; } bb2: { - StorageLive(_13); - _13 = Le(_8, _4); - switchInt(move _13) -> [0: bb3, otherwise: bb4]; + StorageLive(_10); + _10 = Le(_6, _4); + switchInt(move _10) -> [0: bb3, otherwise: bb4]; } bb3: { @@ -52,12 +46,12 @@ fn variant_b::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:11:25: 11:41}, } bb4: { - _0 = Le(_6, _10); + _0 = Le(_5, _7); goto -> bb5; } bb5: { - StorageDead(_13); + StorageDead(_10); goto -> bb7; } @@ -67,8 +61,8 @@ fn variant_b::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:11:25: 11:41}, } bb7: { - StorageDead(_12); - StorageDead(_11); + StorageDead(_9); + StorageDead(_8); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir index 2fd669aeeb61d..56ff7e5361be2 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir @@ -19,11 +19,10 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> debug slice => _5; let mut _7: *mut u32; let mut _8: *mut u32; - let _15: usize; - let _16: usize; + let mut _14: usize; scope 4 { - debug ((this: std::ops::Range).0: usize) => _15; - debug ((this: std::ops::Range).1: usize) => _16; + debug ((this: std::ops::Range).0: usize) => _3; + debug ((this: std::ops::Range).1: usize) => _4; scope 5 { let _6: usize; scope 6 { @@ -33,7 +32,7 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> } scope 12 (inlined ptr::mut_ptr::::add) { debug self => _7; - debug count => _3; + debug count => _14; scope 13 { } } @@ -56,14 +55,14 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> } } scope 7 (inlined as SliceIndex<[T]>>::get_unchecked_mut::runtime::) { - debug ((this: std::ops::Range).0: usize) => _15; - debug ((this: std::ops::Range).1: usize) => _16; + debug ((this: std::ops::Range).0: usize) => _3; + debug ((this: std::ops::Range).1: usize) => _4; debug slice => _5; scope 8 (inlined ptr::mut_ptr::::len) { debug self => _5; - let mut _14: *const [u32]; + let mut _15: *const [u32]; scope 9 (inlined std::ptr::metadata::<[u32]>) { - debug ptr => _14; + debug ptr => _15; scope 10 { } } @@ -81,14 +80,14 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> StorageLive(_5); _5 = &raw mut (*_1); StorageLive(_6); - StorageLive(_14); StorageLive(_15); - StorageLive(_16); _6 = SubUnchecked(_4, _3); StorageLive(_8); StorageLive(_7); _7 = _5 as *mut u32 (PtrToPtr); + StorageLive(_14); _8 = Offset(_7, _3); + StorageDead(_14); StorageDead(_7); StorageLive(_9); _9 = _8 as *mut () (PtrToPtr); @@ -104,9 +103,7 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> StorageDead(_12); StorageDead(_9); StorageDead(_8); - StorageDead(_16); StorageDead(_15); - StorageDead(_14); StorageDead(_6); StorageDead(_5); _0 = &mut (*_13); diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir index 2fd669aeeb61d..56ff7e5361be2 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir @@ -19,11 +19,10 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> debug slice => _5; let mut _7: *mut u32; let mut _8: *mut u32; - let _15: usize; - let _16: usize; + let mut _14: usize; scope 4 { - debug ((this: std::ops::Range).0: usize) => _15; - debug ((this: std::ops::Range).1: usize) => _16; + debug ((this: std::ops::Range).0: usize) => _3; + debug ((this: std::ops::Range).1: usize) => _4; scope 5 { let _6: usize; scope 6 { @@ -33,7 +32,7 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> } scope 12 (inlined ptr::mut_ptr::::add) { debug self => _7; - debug count => _3; + debug count => _14; scope 13 { } } @@ -56,14 +55,14 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> } } scope 7 (inlined as SliceIndex<[T]>>::get_unchecked_mut::runtime::) { - debug ((this: std::ops::Range).0: usize) => _15; - debug ((this: std::ops::Range).1: usize) => _16; + debug ((this: std::ops::Range).0: usize) => _3; + debug ((this: std::ops::Range).1: usize) => _4; debug slice => _5; scope 8 (inlined ptr::mut_ptr::::len) { debug self => _5; - let mut _14: *const [u32]; + let mut _15: *const [u32]; scope 9 (inlined std::ptr::metadata::<[u32]>) { - debug ptr => _14; + debug ptr => _15; scope 10 { } } @@ -81,14 +80,14 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> StorageLive(_5); _5 = &raw mut (*_1); StorageLive(_6); - StorageLive(_14); StorageLive(_15); - StorageLive(_16); _6 = SubUnchecked(_4, _3); StorageLive(_8); StorageLive(_7); _7 = _5 as *mut u32 (PtrToPtr); + StorageLive(_14); _8 = Offset(_7, _3); + StorageDead(_14); StorageDead(_7); StorageLive(_9); _9 = _8 as *mut () (PtrToPtr); @@ -104,9 +103,7 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> StorageDead(_12); StorageDead(_9); StorageDead(_8); - StorageDead(_16); StorageDead(_15); - StorageDead(_14); StorageDead(_6); StorageDead(_5); _0 = &mut (*_13); diff --git a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir index 89009864c3293..b2f2cc4c58252 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir @@ -4,22 +4,22 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { debug slice => _1; debug f => _2; let mut _0: (); - let mut _13: std::slice::Iter<'_, T>; + let mut _12: std::slice::Iter<'_, T>; + let mut _13: std::iter::Enumerate>; let mut _14: std::iter::Enumerate>; - let mut _15: std::iter::Enumerate>; - let mut _16: &mut std::iter::Enumerate>; - let mut _17: std::option::Option<(usize, &T)>; - let mut _18: isize; - let mut _21: &impl Fn(usize, &T); - let mut _22: (usize, &T); - let _23: (); + let mut _15: &mut std::iter::Enumerate>; + let mut _16: std::option::Option<(usize, &T)>; + let mut _17: isize; + let mut _20: &impl Fn(usize, &T); + let mut _21: (usize, &T); + let _22: (); scope 1 { - debug iter => _15; - let _19: usize; - let _20: &T; + debug iter => _14; + let _18: usize; + let _19: &T; scope 2 { - debug i => _19; - debug x => _20; + debug i => _18; + debug x => _19; } } scope 3 (inlined core::slice::::iter) { @@ -27,35 +27,34 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { scope 4 (inlined std::slice::Iter::<'_, T>::new) { debug slice => _1; let _4: *const T; - let mut _5: bool; - let mut _6: usize; - let mut _8: usize; - let mut _9: *mut T; - let mut _11: std::ptr::NonNull; - let mut _12: *const T; + let mut _5: usize; + let mut _7: usize; + let mut _8: *mut T; + let mut _10: std::ptr::NonNull; + let mut _11: *const T; scope 5 { debug ptr => _4; scope 6 { - let _7: *const T; + let _6: *const T; scope 7 { - debug end_or_len => _7; + debug end_or_len => _6; scope 13 (inlined NonNull::::new_unchecked) { - debug ptr => _9; - let mut _10: *const T; + debug ptr => _8; + let mut _9: *const T; scope 14 { scope 15 (inlined NonNull::::new_unchecked::runtime::) { - debug ptr => _9; + debug ptr => _8; scope 16 (inlined ptr::mut_ptr::::is_null) { - debug self => _9; - let mut _24: *mut u8; + debug self => _8; + let mut _23: *mut u8; scope 17 { scope 18 (inlined ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _24; + debug ptr => _23; scope 19 (inlined ptr::mut_ptr::::addr) { - debug self => _24; + debug self => _23; scope 20 { scope 21 (inlined ptr::mut_ptr::::cast::<()>) { - debug self => _24; + debug self => _23; } } } @@ -67,13 +66,13 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } } scope 9 (inlined invalid::) { - debug addr => _8; + debug addr => _7; scope 10 { } } scope 11 (inlined ptr::const_ptr::::add) { debug self => _4; - debug count => _6; + debug count => _5; scope 12 { } } @@ -86,86 +85,83 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } } scope 22 (inlined as Iterator>::enumerate) { - debug self => _13; + debug self => _12; scope 23 (inlined Enumerate::>::new) { - debug iter => _13; + debug iter => _12; } } scope 24 (inlined > as IntoIterator>::into_iter) { - debug self => _14; + debug self => _13; } bb0: { - StorageLive(_13); + StorageLive(_12); StorageLive(_4); StorageLive(_3); _3 = &raw const (*_1); _4 = move _3 as *const T (PtrToPtr); StorageDead(_3); - StorageLive(_7); - StorageLive(_5); - _5 = const _; - switchInt(move _5) -> [0: bb1, otherwise: bb2]; + StorageLive(_6); + switchInt(const _) -> [0: bb1, otherwise: bb2]; } bb1: { - StorageLive(_6); - _6 = Len((*_1)); - _7 = Offset(_4, _6); - StorageDead(_6); + StorageLive(_5); + _5 = Len((*_1)); + _6 = Offset(_4, _5); + StorageDead(_5); goto -> bb3; } bb2: { - StorageLive(_8); - _8 = Len((*_1)); - _7 = _8 as *const T (Transmute); - StorageDead(_8); + StorageLive(_7); + _7 = Len((*_1)); + _6 = _7 as *const T (Transmute); + StorageDead(_7); goto -> bb3; } bb3: { - StorageDead(_5); - StorageLive(_11); - StorageLive(_9); - _9 = _4 as *mut T (PtrToPtr); StorageLive(_10); - StorageLive(_24); - _10 = _9 as *const T (PointerCoercion(MutToConstPointer)); - _11 = NonNull:: { pointer: _10 }; - StorageDead(_24); - StorageDead(_10); + StorageLive(_8); + _8 = _4 as *mut T (PtrToPtr); + StorageLive(_9); + StorageLive(_23); + _9 = _8 as *const T (PointerCoercion(MutToConstPointer)); + _10 = NonNull:: { pointer: _9 }; + StorageDead(_23); StorageDead(_9); - StorageLive(_12); - _12 = _7; - _13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> }; - StorageDead(_12); + StorageDead(_8); + StorageLive(_11); + _11 = _6; + _12 = std::slice::Iter::<'_, T> { ptr: move _10, end_or_len: move _11, _marker: const ZeroSized: PhantomData<&T> }; StorageDead(_11); - StorageDead(_7); + StorageDead(_10); + StorageDead(_6); StorageDead(_4); - _14 = Enumerate::> { iter: move _13, count: const 0_usize }; - StorageDead(_13); - StorageLive(_15); - _15 = move _14; + _13 = Enumerate::> { iter: move _12, count: const 0_usize }; + StorageDead(_12); + StorageLive(_14); + _14 = move _13; goto -> bb4; } bb4: { - StorageLive(_17); StorageLive(_16); - _16 = &mut _15; - _17 = > as Iterator>::next(move _16) -> [return: bb5, unwind unreachable]; + StorageLive(_15); + _15 = &mut _14; + _16 = > as Iterator>::next(move _15) -> [return: bb5, unwind unreachable]; } bb5: { - StorageDead(_16); - _18 = discriminant(_17); - switchInt(move _18) -> [0: bb6, 1: bb8, otherwise: bb10]; + StorageDead(_15); + _17 = discriminant(_16); + switchInt(move _17) -> [0: bb6, 1: bb8, otherwise: bb10]; } bb6: { - StorageDead(_17); - StorageDead(_15); + StorageDead(_16); + StorageDead(_14); drop(_2) -> [return: bb7, unwind unreachable]; } @@ -174,19 +170,19 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } bb8: { - _19 = (((_17 as Some).0: (usize, &T)).0: usize); - _20 = (((_17 as Some).0: (usize, &T)).1: &T); + _18 = (((_16 as Some).0: (usize, &T)).0: usize); + _19 = (((_16 as Some).0: (usize, &T)).1: &T); + StorageLive(_20); + _20 = &_2; StorageLive(_21); - _21 = &_2; - StorageLive(_22); - _22 = (_19, _20); - _23 = >::call(move _21, move _22) -> [return: bb9, unwind unreachable]; + _21 = (_18, _19); + _22 = >::call(move _20, move _21) -> [return: bb9, unwind unreachable]; } bb9: { - StorageDead(_22); StorageDead(_21); - StorageDead(_17); + StorageDead(_20); + StorageDead(_16); goto -> bb4; } diff --git a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir index 3d76bab7ce70e..97375a5c5d101 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir @@ -4,22 +4,22 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { debug slice => _1; debug f => _2; let mut _0: (); - let mut _13: std::slice::Iter<'_, T>; + let mut _12: std::slice::Iter<'_, T>; + let mut _13: std::iter::Enumerate>; let mut _14: std::iter::Enumerate>; - let mut _15: std::iter::Enumerate>; - let mut _16: &mut std::iter::Enumerate>; - let mut _17: std::option::Option<(usize, &T)>; - let mut _18: isize; - let mut _21: &impl Fn(usize, &T); - let mut _22: (usize, &T); - let _23: (); + let mut _15: &mut std::iter::Enumerate>; + let mut _16: std::option::Option<(usize, &T)>; + let mut _17: isize; + let mut _20: &impl Fn(usize, &T); + let mut _21: (usize, &T); + let _22: (); scope 1 { - debug iter => _15; - let _19: usize; - let _20: &T; + debug iter => _14; + let _18: usize; + let _19: &T; scope 2 { - debug i => _19; - debug x => _20; + debug i => _18; + debug x => _19; } } scope 3 (inlined core::slice::::iter) { @@ -27,35 +27,34 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { scope 4 (inlined std::slice::Iter::<'_, T>::new) { debug slice => _1; let _4: *const T; - let mut _5: bool; - let mut _6: usize; - let mut _8: usize; - let mut _9: *mut T; - let mut _11: std::ptr::NonNull; - let mut _12: *const T; + let mut _5: usize; + let mut _7: usize; + let mut _8: *mut T; + let mut _10: std::ptr::NonNull; + let mut _11: *const T; scope 5 { debug ptr => _4; scope 6 { - let _7: *const T; + let _6: *const T; scope 7 { - debug end_or_len => _7; + debug end_or_len => _6; scope 13 (inlined NonNull::::new_unchecked) { - debug ptr => _9; - let mut _10: *const T; + debug ptr => _8; + let mut _9: *const T; scope 14 { scope 15 (inlined NonNull::::new_unchecked::runtime::) { - debug ptr => _9; + debug ptr => _8; scope 16 (inlined ptr::mut_ptr::::is_null) { - debug self => _9; - let mut _24: *mut u8; + debug self => _8; + let mut _23: *mut u8; scope 17 { scope 18 (inlined ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _24; + debug ptr => _23; scope 19 (inlined ptr::mut_ptr::::addr) { - debug self => _24; + debug self => _23; scope 20 { scope 21 (inlined ptr::mut_ptr::::cast::<()>) { - debug self => _24; + debug self => _23; } } } @@ -67,13 +66,13 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } } scope 9 (inlined invalid::) { - debug addr => _8; + debug addr => _7; scope 10 { } } scope 11 (inlined ptr::const_ptr::::add) { debug self => _4; - debug count => _6; + debug count => _5; scope 12 { } } @@ -86,86 +85,83 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } } scope 22 (inlined as Iterator>::enumerate) { - debug self => _13; + debug self => _12; scope 23 (inlined Enumerate::>::new) { - debug iter => _13; + debug iter => _12; } } scope 24 (inlined > as IntoIterator>::into_iter) { - debug self => _14; + debug self => _13; } bb0: { - StorageLive(_13); + StorageLive(_12); StorageLive(_4); StorageLive(_3); _3 = &raw const (*_1); _4 = move _3 as *const T (PtrToPtr); StorageDead(_3); - StorageLive(_7); - StorageLive(_5); - _5 = const _; - switchInt(move _5) -> [0: bb1, otherwise: bb2]; + StorageLive(_6); + switchInt(const _) -> [0: bb1, otherwise: bb2]; } bb1: { - StorageLive(_6); - _6 = Len((*_1)); - _7 = Offset(_4, _6); - StorageDead(_6); + StorageLive(_5); + _5 = Len((*_1)); + _6 = Offset(_4, _5); + StorageDead(_5); goto -> bb3; } bb2: { - StorageLive(_8); - _8 = Len((*_1)); - _7 = _8 as *const T (Transmute); - StorageDead(_8); + StorageLive(_7); + _7 = Len((*_1)); + _6 = _7 as *const T (Transmute); + StorageDead(_7); goto -> bb3; } bb3: { - StorageDead(_5); - StorageLive(_11); - StorageLive(_9); - _9 = _4 as *mut T (PtrToPtr); StorageLive(_10); - StorageLive(_24); - _10 = _9 as *const T (PointerCoercion(MutToConstPointer)); - _11 = NonNull:: { pointer: _10 }; - StorageDead(_24); - StorageDead(_10); + StorageLive(_8); + _8 = _4 as *mut T (PtrToPtr); + StorageLive(_9); + StorageLive(_23); + _9 = _8 as *const T (PointerCoercion(MutToConstPointer)); + _10 = NonNull:: { pointer: _9 }; + StorageDead(_23); StorageDead(_9); - StorageLive(_12); - _12 = _7; - _13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> }; - StorageDead(_12); + StorageDead(_8); + StorageLive(_11); + _11 = _6; + _12 = std::slice::Iter::<'_, T> { ptr: move _10, end_or_len: move _11, _marker: const ZeroSized: PhantomData<&T> }; StorageDead(_11); - StorageDead(_7); + StorageDead(_10); + StorageDead(_6); StorageDead(_4); - _14 = Enumerate::> { iter: move _13, count: const 0_usize }; - StorageDead(_13); - StorageLive(_15); - _15 = move _14; + _13 = Enumerate::> { iter: move _12, count: const 0_usize }; + StorageDead(_12); + StorageLive(_14); + _14 = move _13; goto -> bb4; } bb4: { - StorageLive(_17); StorageLive(_16); - _16 = &mut _15; - _17 = > as Iterator>::next(move _16) -> [return: bb5, unwind: bb11]; + StorageLive(_15); + _15 = &mut _14; + _16 = > as Iterator>::next(move _15) -> [return: bb5, unwind: bb11]; } bb5: { - StorageDead(_16); - _18 = discriminant(_17); - switchInt(move _18) -> [0: bb6, 1: bb8, otherwise: bb10]; + StorageDead(_15); + _17 = discriminant(_16); + switchInt(move _17) -> [0: bb6, 1: bb8, otherwise: bb10]; } bb6: { - StorageDead(_17); - StorageDead(_15); + StorageDead(_16); + StorageDead(_14); drop(_2) -> [return: bb7, unwind continue]; } @@ -174,19 +170,19 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } bb8: { - _19 = (((_17 as Some).0: (usize, &T)).0: usize); - _20 = (((_17 as Some).0: (usize, &T)).1: &T); + _18 = (((_16 as Some).0: (usize, &T)).0: usize); + _19 = (((_16 as Some).0: (usize, &T)).1: &T); + StorageLive(_20); + _20 = &_2; StorageLive(_21); - _21 = &_2; - StorageLive(_22); - _22 = (_19, _20); - _23 = >::call(move _21, move _22) -> [return: bb9, unwind: bb11]; + _21 = (_18, _19); + _22 = >::call(move _20, move _21) -> [return: bb9, unwind: bb11]; } bb9: { - StorageDead(_22); StorageDead(_21); - StorageDead(_17); + StorageDead(_20); + StorageDead(_16); goto -> bb4; } diff --git a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir index 146fa57a0b188..ee2bf92a9e7a3 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir @@ -4,19 +4,19 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { debug slice => _1; debug f => _2; let mut _0: (); + let mut _12: std::slice::Iter<'_, T>; let mut _13: std::slice::Iter<'_, T>; - let mut _14: std::slice::Iter<'_, T>; - let mut _15: &mut std::slice::Iter<'_, T>; - let mut _16: std::option::Option<&T>; - let mut _17: isize; - let mut _19: &impl Fn(&T); - let mut _20: (&T,); - let _21: (); + let mut _14: &mut std::slice::Iter<'_, T>; + let mut _15: std::option::Option<&T>; + let mut _16: isize; + let mut _18: &impl Fn(&T); + let mut _19: (&T,); + let _20: (); scope 1 { - debug iter => _14; - let _18: &T; + debug iter => _13; + let _17: &T; scope 2 { - debug x => _18; + debug x => _17; } } scope 3 (inlined core::slice::::iter) { @@ -24,35 +24,34 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { scope 4 (inlined std::slice::Iter::<'_, T>::new) { debug slice => _1; let _4: *const T; - let mut _5: bool; - let mut _6: usize; - let mut _8: usize; - let mut _9: *mut T; - let mut _11: std::ptr::NonNull; - let mut _12: *const T; + let mut _5: usize; + let mut _7: usize; + let mut _8: *mut T; + let mut _10: std::ptr::NonNull; + let mut _11: *const T; scope 5 { debug ptr => _4; scope 6 { - let _7: *const T; + let _6: *const T; scope 7 { - debug end_or_len => _7; + debug end_or_len => _6; scope 13 (inlined NonNull::::new_unchecked) { - debug ptr => _9; - let mut _10: *const T; + debug ptr => _8; + let mut _9: *const T; scope 14 { scope 15 (inlined NonNull::::new_unchecked::runtime::) { - debug ptr => _9; + debug ptr => _8; scope 16 (inlined ptr::mut_ptr::::is_null) { - debug self => _9; - let mut _22: *mut u8; + debug self => _8; + let mut _21: *mut u8; scope 17 { scope 18 (inlined ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _22; + debug ptr => _21; scope 19 (inlined ptr::mut_ptr::::addr) { - debug self => _22; + debug self => _21; scope 20 { scope 21 (inlined ptr::mut_ptr::::cast::<()>) { - debug self => _22; + debug self => _21; } } } @@ -64,13 +63,13 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } scope 9 (inlined invalid::) { - debug addr => _8; + debug addr => _7; scope 10 { } } scope 11 (inlined ptr::const_ptr::::add) { debug self => _4; - debug count => _6; + debug count => _5; scope 12 { } } @@ -83,7 +82,7 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } scope 22 (inlined as IntoIterator>::into_iter) { - debug self => _13; + debug self => _12; } bb0: { @@ -92,68 +91,65 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { _3 = &raw const (*_1); _4 = move _3 as *const T (PtrToPtr); StorageDead(_3); - StorageLive(_7); - StorageLive(_5); - _5 = const _; - switchInt(move _5) -> [0: bb1, otherwise: bb2]; + StorageLive(_6); + switchInt(const _) -> [0: bb1, otherwise: bb2]; } bb1: { - StorageLive(_6); - _6 = Len((*_1)); - _7 = Offset(_4, _6); - StorageDead(_6); + StorageLive(_5); + _5 = Len((*_1)); + _6 = Offset(_4, _5); + StorageDead(_5); goto -> bb3; } bb2: { - StorageLive(_8); - _8 = Len((*_1)); - _7 = _8 as *const T (Transmute); - StorageDead(_8); + StorageLive(_7); + _7 = Len((*_1)); + _6 = _7 as *const T (Transmute); + StorageDead(_7); goto -> bb3; } bb3: { - StorageDead(_5); - StorageLive(_11); - StorageLive(_9); - _9 = _4 as *mut T (PtrToPtr); StorageLive(_10); - StorageLive(_22); - _10 = _9 as *const T (PointerCoercion(MutToConstPointer)); - _11 = NonNull:: { pointer: _10 }; - StorageDead(_22); - StorageDead(_10); + StorageLive(_8); + _8 = _4 as *mut T (PtrToPtr); + StorageLive(_9); + StorageLive(_21); + _9 = _8 as *const T (PointerCoercion(MutToConstPointer)); + _10 = NonNull:: { pointer: _9 }; + StorageDead(_21); StorageDead(_9); - StorageLive(_12); - _12 = _7; - _13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> }; - StorageDead(_12); + StorageDead(_8); + StorageLive(_11); + _11 = _6; + _12 = std::slice::Iter::<'_, T> { ptr: move _10, end_or_len: move _11, _marker: const ZeroSized: PhantomData<&T> }; StorageDead(_11); - StorageDead(_7); + StorageDead(_10); + StorageDead(_6); StorageDead(_4); - StorageLive(_14); - _14 = move _13; + StorageLive(_13); + _13 = move _12; goto -> bb4; } bb4: { - StorageLive(_16); StorageLive(_15); - _15 = &mut _14; - _16 = as Iterator>::next(move _15) -> [return: bb5, unwind unreachable]; + StorageLive(_14); + _14 = &mut _13; + _15 = as Iterator>::next(move _14) -> [return: bb5, unwind unreachable]; } bb5: { - StorageDead(_15); - _17 = discriminant(_16); - switchInt(move _17) -> [0: bb6, 1: bb8, otherwise: bb10]; + StorageDead(_14); + _16 = discriminant(_15); + switchInt(move _16) -> [0: bb6, 1: bb8, otherwise: bb10]; } bb6: { - StorageDead(_16); - StorageDead(_14); + StorageDead(_15); + StorageDead(_13); drop(_2) -> [return: bb7, unwind unreachable]; } @@ -162,18 +158,18 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb8: { - _18 = ((_16 as Some).0: &T); + _17 = ((_15 as Some).0: &T); + StorageLive(_18); + _18 = &_2; StorageLive(_19); - _19 = &_2; - StorageLive(_20); - _20 = (_18,); - _21 = >::call(move _19, move _20) -> [return: bb9, unwind unreachable]; + _19 = (_17,); + _20 = >::call(move _18, move _19) -> [return: bb9, unwind unreachable]; } bb9: { - StorageDead(_20); StorageDead(_19); - StorageDead(_16); + StorageDead(_18); + StorageDead(_15); goto -> bb4; } diff --git a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir index e8586cec981c3..dc6ed3c722b9e 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir @@ -4,19 +4,19 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { debug slice => _1; debug f => _2; let mut _0: (); + let mut _12: std::slice::Iter<'_, T>; let mut _13: std::slice::Iter<'_, T>; - let mut _14: std::slice::Iter<'_, T>; - let mut _15: &mut std::slice::Iter<'_, T>; - let mut _16: std::option::Option<&T>; - let mut _17: isize; - let mut _19: &impl Fn(&T); - let mut _20: (&T,); - let _21: (); + let mut _14: &mut std::slice::Iter<'_, T>; + let mut _15: std::option::Option<&T>; + let mut _16: isize; + let mut _18: &impl Fn(&T); + let mut _19: (&T,); + let _20: (); scope 1 { - debug iter => _14; - let _18: &T; + debug iter => _13; + let _17: &T; scope 2 { - debug x => _18; + debug x => _17; } } scope 3 (inlined core::slice::::iter) { @@ -24,35 +24,34 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { scope 4 (inlined std::slice::Iter::<'_, T>::new) { debug slice => _1; let _4: *const T; - let mut _5: bool; - let mut _6: usize; - let mut _8: usize; - let mut _9: *mut T; - let mut _11: std::ptr::NonNull; - let mut _12: *const T; + let mut _5: usize; + let mut _7: usize; + let mut _8: *mut T; + let mut _10: std::ptr::NonNull; + let mut _11: *const T; scope 5 { debug ptr => _4; scope 6 { - let _7: *const T; + let _6: *const T; scope 7 { - debug end_or_len => _7; + debug end_or_len => _6; scope 13 (inlined NonNull::::new_unchecked) { - debug ptr => _9; - let mut _10: *const T; + debug ptr => _8; + let mut _9: *const T; scope 14 { scope 15 (inlined NonNull::::new_unchecked::runtime::) { - debug ptr => _9; + debug ptr => _8; scope 16 (inlined ptr::mut_ptr::::is_null) { - debug self => _9; - let mut _22: *mut u8; + debug self => _8; + let mut _21: *mut u8; scope 17 { scope 18 (inlined ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _22; + debug ptr => _21; scope 19 (inlined ptr::mut_ptr::::addr) { - debug self => _22; + debug self => _21; scope 20 { scope 21 (inlined ptr::mut_ptr::::cast::<()>) { - debug self => _22; + debug self => _21; } } } @@ -64,13 +63,13 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } scope 9 (inlined invalid::) { - debug addr => _8; + debug addr => _7; scope 10 { } } scope 11 (inlined ptr::const_ptr::::add) { debug self => _4; - debug count => _6; + debug count => _5; scope 12 { } } @@ -83,7 +82,7 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } scope 22 (inlined as IntoIterator>::into_iter) { - debug self => _13; + debug self => _12; } bb0: { @@ -92,68 +91,65 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { _3 = &raw const (*_1); _4 = move _3 as *const T (PtrToPtr); StorageDead(_3); - StorageLive(_7); - StorageLive(_5); - _5 = const _; - switchInt(move _5) -> [0: bb1, otherwise: bb2]; + StorageLive(_6); + switchInt(const _) -> [0: bb1, otherwise: bb2]; } bb1: { - StorageLive(_6); - _6 = Len((*_1)); - _7 = Offset(_4, _6); - StorageDead(_6); + StorageLive(_5); + _5 = Len((*_1)); + _6 = Offset(_4, _5); + StorageDead(_5); goto -> bb3; } bb2: { - StorageLive(_8); - _8 = Len((*_1)); - _7 = _8 as *const T (Transmute); - StorageDead(_8); + StorageLive(_7); + _7 = Len((*_1)); + _6 = _7 as *const T (Transmute); + StorageDead(_7); goto -> bb3; } bb3: { - StorageDead(_5); - StorageLive(_11); - StorageLive(_9); - _9 = _4 as *mut T (PtrToPtr); StorageLive(_10); - StorageLive(_22); - _10 = _9 as *const T (PointerCoercion(MutToConstPointer)); - _11 = NonNull:: { pointer: _10 }; - StorageDead(_22); - StorageDead(_10); + StorageLive(_8); + _8 = _4 as *mut T (PtrToPtr); + StorageLive(_9); + StorageLive(_21); + _9 = _8 as *const T (PointerCoercion(MutToConstPointer)); + _10 = NonNull:: { pointer: _9 }; + StorageDead(_21); StorageDead(_9); - StorageLive(_12); - _12 = _7; - _13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> }; - StorageDead(_12); + StorageDead(_8); + StorageLive(_11); + _11 = _6; + _12 = std::slice::Iter::<'_, T> { ptr: move _10, end_or_len: move _11, _marker: const ZeroSized: PhantomData<&T> }; StorageDead(_11); - StorageDead(_7); + StorageDead(_10); + StorageDead(_6); StorageDead(_4); - StorageLive(_14); - _14 = move _13; + StorageLive(_13); + _13 = move _12; goto -> bb4; } bb4: { - StorageLive(_16); StorageLive(_15); - _15 = &mut _14; - _16 = as Iterator>::next(move _15) -> [return: bb5, unwind: bb11]; + StorageLive(_14); + _14 = &mut _13; + _15 = as Iterator>::next(move _14) -> [return: bb5, unwind: bb11]; } bb5: { - StorageDead(_15); - _17 = discriminant(_16); - switchInt(move _17) -> [0: bb6, 1: bb8, otherwise: bb10]; + StorageDead(_14); + _16 = discriminant(_15); + switchInt(move _16) -> [0: bb6, 1: bb8, otherwise: bb10]; } bb6: { - StorageDead(_16); - StorageDead(_14); + StorageDead(_15); + StorageDead(_13); drop(_2) -> [return: bb7, unwind continue]; } @@ -162,18 +158,18 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb8: { - _18 = ((_16 as Some).0: &T); + _17 = ((_15 as Some).0: &T); + StorageLive(_18); + _18 = &_2; StorageLive(_19); - _19 = &_2; - StorageLive(_20); - _20 = (_18,); - _21 = >::call(move _19, move _20) -> [return: bb9, unwind: bb11]; + _19 = (_17,); + _20 = >::call(move _18, move _19) -> [return: bb9, unwind: bb11]; } bb9: { - StorageDead(_20); StorageDead(_19); - StorageDead(_16); + StorageDead(_18); + StorageDead(_15); goto -> bb4; } diff --git a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir index 4afe2eda188fb..2ba456dcb206c 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir @@ -81,7 +81,7 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { bb2: { StorageDead(_22); StorageDead(_21); - _9 = Option::::None; + _9 = const Option::::None; goto -> bb5; } @@ -144,3 +144,7 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { unreachable; } } + +alloc24 (size: 16, align: 8) { + 00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ │ ........░░░░░░░░ +} diff --git a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir index 48092608d9ca2..25df1aeff7934 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir @@ -81,7 +81,7 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { bb2: { StorageDead(_22); StorageDead(_21); - _9 = Option::::None; + _9 = const Option::::None; goto -> bb5; } @@ -152,3 +152,7 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { resume; } } + +alloc24 (size: 16, align: 8) { + 00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ │ ........░░░░░░░░ +} diff --git a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir index 549cb4f46a0e2..5d969ecbf8f44 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir @@ -4,24 +4,24 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { debug slice => _1; debug f => _2; let mut _0: (); - let mut _13: std::slice::Iter<'_, T>; + let mut _12: std::slice::Iter<'_, T>; + let mut _13: std::iter::Rev>; let mut _14: std::iter::Rev>; - let mut _15: std::iter::Rev>; - let mut _17: std::option::Option<&T>; - let mut _18: isize; - let mut _20: &impl Fn(&T); - let mut _21: (&T,); - let _22: (); - let mut _23: &mut std::iter::Rev>; + let mut _16: std::option::Option<&T>; + let mut _17: isize; + let mut _19: &impl Fn(&T); + let mut _20: (&T,); + let _21: (); + let mut _22: &mut std::iter::Rev>; scope 1 { - debug iter => _15; - let _19: &T; + debug iter => _14; + let _18: &T; scope 2 { - debug x => _19; + debug x => _18; } scope 25 (inlined > as Iterator>::next) { - debug self => _23; - let mut _16: &mut std::slice::Iter<'_, T>; + debug self => _22; + let mut _15: &mut std::slice::Iter<'_, T>; } } scope 3 (inlined core::slice::::iter) { @@ -29,35 +29,34 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { scope 4 (inlined std::slice::Iter::<'_, T>::new) { debug slice => _1; let _4: *const T; - let mut _5: bool; - let mut _6: usize; - let mut _8: usize; - let mut _9: *mut T; - let mut _11: std::ptr::NonNull; - let mut _12: *const T; + let mut _5: usize; + let mut _7: usize; + let mut _8: *mut T; + let mut _10: std::ptr::NonNull; + let mut _11: *const T; scope 5 { debug ptr => _4; scope 6 { - let _7: *const T; + let _6: *const T; scope 7 { - debug end_or_len => _7; + debug end_or_len => _6; scope 13 (inlined NonNull::::new_unchecked) { - debug ptr => _9; - let mut _10: *const T; + debug ptr => _8; + let mut _9: *const T; scope 14 { scope 15 (inlined NonNull::::new_unchecked::runtime::) { - debug ptr => _9; + debug ptr => _8; scope 16 (inlined ptr::mut_ptr::::is_null) { - debug self => _9; - let mut _24: *mut u8; + debug self => _8; + let mut _23: *mut u8; scope 17 { scope 18 (inlined ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _24; + debug ptr => _23; scope 19 (inlined ptr::mut_ptr::::addr) { - debug self => _24; + debug self => _23; scope 20 { scope 21 (inlined ptr::mut_ptr::::cast::<()>) { - debug self => _24; + debug self => _23; } } } @@ -69,13 +68,13 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } scope 9 (inlined invalid::) { - debug addr => _8; + debug addr => _7; scope 10 { } } scope 11 (inlined ptr::const_ptr::::add) { debug self => _4; - debug count => _6; + debug count => _5; scope 12 { } } @@ -88,86 +87,83 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } scope 22 (inlined as Iterator>::rev) { - debug self => _13; + debug self => _12; scope 23 (inlined Rev::>::new) { - debug iter => _13; + debug iter => _12; } } scope 24 (inlined > as IntoIterator>::into_iter) { - debug self => _14; + debug self => _13; } bb0: { - StorageLive(_13); + StorageLive(_12); StorageLive(_4); StorageLive(_3); _3 = &raw const (*_1); _4 = move _3 as *const T (PtrToPtr); StorageDead(_3); - StorageLive(_7); - StorageLive(_5); - _5 = const _; - switchInt(move _5) -> [0: bb1, otherwise: bb2]; + StorageLive(_6); + switchInt(const _) -> [0: bb1, otherwise: bb2]; } bb1: { - StorageLive(_6); - _6 = Len((*_1)); - _7 = Offset(_4, _6); - StorageDead(_6); + StorageLive(_5); + _5 = Len((*_1)); + _6 = Offset(_4, _5); + StorageDead(_5); goto -> bb3; } bb2: { - StorageLive(_8); - _8 = Len((*_1)); - _7 = _8 as *const T (Transmute); - StorageDead(_8); + StorageLive(_7); + _7 = Len((*_1)); + _6 = _7 as *const T (Transmute); + StorageDead(_7); goto -> bb3; } bb3: { - StorageDead(_5); - StorageLive(_11); - StorageLive(_9); - _9 = _4 as *mut T (PtrToPtr); StorageLive(_10); - StorageLive(_24); - _10 = _9 as *const T (PointerCoercion(MutToConstPointer)); - _11 = NonNull:: { pointer: _10 }; - StorageDead(_24); - StorageDead(_10); + StorageLive(_8); + _8 = _4 as *mut T (PtrToPtr); + StorageLive(_9); + StorageLive(_23); + _9 = _8 as *const T (PointerCoercion(MutToConstPointer)); + _10 = NonNull:: { pointer: _9 }; + StorageDead(_23); StorageDead(_9); - StorageLive(_12); - _12 = _7; - _13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> }; - StorageDead(_12); + StorageDead(_8); + StorageLive(_11); + _11 = _6; + _12 = std::slice::Iter::<'_, T> { ptr: move _10, end_or_len: move _11, _marker: const ZeroSized: PhantomData<&T> }; StorageDead(_11); - StorageDead(_7); + StorageDead(_10); + StorageDead(_6); StorageDead(_4); - _14 = Rev::> { iter: move _13 }; - StorageDead(_13); - StorageLive(_15); - _15 = move _14; + _13 = Rev::> { iter: move _12 }; + StorageDead(_12); + StorageLive(_14); + _14 = move _13; goto -> bb4; } bb4: { - StorageLive(_17); StorageLive(_16); - _16 = &mut (_15.0: std::slice::Iter<'_, T>); - _17 = as DoubleEndedIterator>::next_back(move _16) -> [return: bb5, unwind unreachable]; + StorageLive(_15); + _15 = &mut (_14.0: std::slice::Iter<'_, T>); + _16 = as DoubleEndedIterator>::next_back(move _15) -> [return: bb5, unwind unreachable]; } bb5: { - StorageDead(_16); - _18 = discriminant(_17); - switchInt(move _18) -> [0: bb6, 1: bb8, otherwise: bb10]; + StorageDead(_15); + _17 = discriminant(_16); + switchInt(move _17) -> [0: bb6, 1: bb8, otherwise: bb10]; } bb6: { - StorageDead(_17); - StorageDead(_15); + StorageDead(_16); + StorageDead(_14); drop(_2) -> [return: bb7, unwind unreachable]; } @@ -176,18 +172,18 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb8: { - _19 = ((_17 as Some).0: &T); + _18 = ((_16 as Some).0: &T); + StorageLive(_19); + _19 = &_2; StorageLive(_20); - _20 = &_2; - StorageLive(_21); - _21 = (_19,); - _22 = >::call(move _20, move _21) -> [return: bb9, unwind unreachable]; + _20 = (_18,); + _21 = >::call(move _19, move _20) -> [return: bb9, unwind unreachable]; } bb9: { - StorageDead(_21); StorageDead(_20); - StorageDead(_17); + StorageDead(_19); + StorageDead(_16); goto -> bb4; } diff --git a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir index 3cdc49f6056bd..e50bc56560d31 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir @@ -4,24 +4,24 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { debug slice => _1; debug f => _2; let mut _0: (); - let mut _13: std::slice::Iter<'_, T>; + let mut _12: std::slice::Iter<'_, T>; + let mut _13: std::iter::Rev>; let mut _14: std::iter::Rev>; - let mut _15: std::iter::Rev>; - let mut _17: std::option::Option<&T>; - let mut _18: isize; - let mut _20: &impl Fn(&T); - let mut _21: (&T,); - let _22: (); - let mut _23: &mut std::iter::Rev>; + let mut _16: std::option::Option<&T>; + let mut _17: isize; + let mut _19: &impl Fn(&T); + let mut _20: (&T,); + let _21: (); + let mut _22: &mut std::iter::Rev>; scope 1 { - debug iter => _15; - let _19: &T; + debug iter => _14; + let _18: &T; scope 2 { - debug x => _19; + debug x => _18; } scope 25 (inlined > as Iterator>::next) { - debug self => _23; - let mut _16: &mut std::slice::Iter<'_, T>; + debug self => _22; + let mut _15: &mut std::slice::Iter<'_, T>; } } scope 3 (inlined core::slice::::iter) { @@ -29,35 +29,34 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { scope 4 (inlined std::slice::Iter::<'_, T>::new) { debug slice => _1; let _4: *const T; - let mut _5: bool; - let mut _6: usize; - let mut _8: usize; - let mut _9: *mut T; - let mut _11: std::ptr::NonNull; - let mut _12: *const T; + let mut _5: usize; + let mut _7: usize; + let mut _8: *mut T; + let mut _10: std::ptr::NonNull; + let mut _11: *const T; scope 5 { debug ptr => _4; scope 6 { - let _7: *const T; + let _6: *const T; scope 7 { - debug end_or_len => _7; + debug end_or_len => _6; scope 13 (inlined NonNull::::new_unchecked) { - debug ptr => _9; - let mut _10: *const T; + debug ptr => _8; + let mut _9: *const T; scope 14 { scope 15 (inlined NonNull::::new_unchecked::runtime::) { - debug ptr => _9; + debug ptr => _8; scope 16 (inlined ptr::mut_ptr::::is_null) { - debug self => _9; - let mut _24: *mut u8; + debug self => _8; + let mut _23: *mut u8; scope 17 { scope 18 (inlined ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _24; + debug ptr => _23; scope 19 (inlined ptr::mut_ptr::::addr) { - debug self => _24; + debug self => _23; scope 20 { scope 21 (inlined ptr::mut_ptr::::cast::<()>) { - debug self => _24; + debug self => _23; } } } @@ -69,13 +68,13 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } scope 9 (inlined invalid::) { - debug addr => _8; + debug addr => _7; scope 10 { } } scope 11 (inlined ptr::const_ptr::::add) { debug self => _4; - debug count => _6; + debug count => _5; scope 12 { } } @@ -88,86 +87,83 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } scope 22 (inlined as Iterator>::rev) { - debug self => _13; + debug self => _12; scope 23 (inlined Rev::>::new) { - debug iter => _13; + debug iter => _12; } } scope 24 (inlined > as IntoIterator>::into_iter) { - debug self => _14; + debug self => _13; } bb0: { - StorageLive(_13); + StorageLive(_12); StorageLive(_4); StorageLive(_3); _3 = &raw const (*_1); _4 = move _3 as *const T (PtrToPtr); StorageDead(_3); - StorageLive(_7); - StorageLive(_5); - _5 = const _; - switchInt(move _5) -> [0: bb1, otherwise: bb2]; + StorageLive(_6); + switchInt(const _) -> [0: bb1, otherwise: bb2]; } bb1: { - StorageLive(_6); - _6 = Len((*_1)); - _7 = Offset(_4, _6); - StorageDead(_6); + StorageLive(_5); + _5 = Len((*_1)); + _6 = Offset(_4, _5); + StorageDead(_5); goto -> bb3; } bb2: { - StorageLive(_8); - _8 = Len((*_1)); - _7 = _8 as *const T (Transmute); - StorageDead(_8); + StorageLive(_7); + _7 = Len((*_1)); + _6 = _7 as *const T (Transmute); + StorageDead(_7); goto -> bb3; } bb3: { - StorageDead(_5); - StorageLive(_11); - StorageLive(_9); - _9 = _4 as *mut T (PtrToPtr); StorageLive(_10); - StorageLive(_24); - _10 = _9 as *const T (PointerCoercion(MutToConstPointer)); - _11 = NonNull:: { pointer: _10 }; - StorageDead(_24); - StorageDead(_10); + StorageLive(_8); + _8 = _4 as *mut T (PtrToPtr); + StorageLive(_9); + StorageLive(_23); + _9 = _8 as *const T (PointerCoercion(MutToConstPointer)); + _10 = NonNull:: { pointer: _9 }; + StorageDead(_23); StorageDead(_9); - StorageLive(_12); - _12 = _7; - _13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> }; - StorageDead(_12); + StorageDead(_8); + StorageLive(_11); + _11 = _6; + _12 = std::slice::Iter::<'_, T> { ptr: move _10, end_or_len: move _11, _marker: const ZeroSized: PhantomData<&T> }; StorageDead(_11); - StorageDead(_7); + StorageDead(_10); + StorageDead(_6); StorageDead(_4); - _14 = Rev::> { iter: move _13 }; - StorageDead(_13); - StorageLive(_15); - _15 = move _14; + _13 = Rev::> { iter: move _12 }; + StorageDead(_12); + StorageLive(_14); + _14 = move _13; goto -> bb4; } bb4: { - StorageLive(_17); StorageLive(_16); - _16 = &mut (_15.0: std::slice::Iter<'_, T>); - _17 = as DoubleEndedIterator>::next_back(move _16) -> [return: bb5, unwind: bb11]; + StorageLive(_15); + _15 = &mut (_14.0: std::slice::Iter<'_, T>); + _16 = as DoubleEndedIterator>::next_back(move _15) -> [return: bb5, unwind: bb11]; } bb5: { - StorageDead(_16); - _18 = discriminant(_17); - switchInt(move _18) -> [0: bb6, 1: bb8, otherwise: bb10]; + StorageDead(_15); + _17 = discriminant(_16); + switchInt(move _17) -> [0: bb6, 1: bb8, otherwise: bb10]; } bb6: { - StorageDead(_17); - StorageDead(_15); + StorageDead(_16); + StorageDead(_14); drop(_2) -> [return: bb7, unwind continue]; } @@ -176,18 +172,18 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb8: { - _19 = ((_17 as Some).0: &T); + _18 = ((_16 as Some).0: &T); + StorageLive(_19); + _19 = &_2; StorageLive(_20); - _20 = &_2; - StorageLive(_21); - _21 = (_19,); - _22 = >::call(move _20, move _21) -> [return: bb9, unwind: bb11]; + _20 = (_18,); + _21 = >::call(move _19, move _20) -> [return: bb9, unwind: bb11]; } bb9: { - StorageDead(_21); StorageDead(_20); - StorageDead(_17); + StorageDead(_19); + StorageDead(_16); goto -> bb4; } diff --git a/tests/mir-opt/simplify_match.main.ConstProp.panic-abort.diff b/tests/mir-opt/simplify_match.main.ConstProp.panic-abort.diff index 6025abb73825c..2bb54d5a66694 100644 --- a/tests/mir-opt/simplify_match.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/simplify_match.main.ConstProp.panic-abort.diff @@ -3,16 +3,14 @@ fn main() -> () { let mut _0: (); - let mut _1: bool; - let _2: bool; + let _1: bool; scope 1 { - debug x => _2; + debug x => _1; } bb0: { - _2 = const false; -- switchInt(_2) -> [0: bb1, otherwise: bb2]; -+ switchInt(const false) -> [0: bb1, otherwise: bb2]; + _1 = const false; + switchInt(const false) -> [0: bb1, otherwise: bb2]; } bb1: { diff --git a/tests/mir-opt/simplify_match.main.ConstProp.panic-unwind.diff b/tests/mir-opt/simplify_match.main.ConstProp.panic-unwind.diff index c881dec28c77d..2d60e234e066d 100644 --- a/tests/mir-opt/simplify_match.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/simplify_match.main.ConstProp.panic-unwind.diff @@ -3,16 +3,14 @@ fn main() -> () { let mut _0: (); - let mut _1: bool; - let _2: bool; + let _1: bool; scope 1 { - debug x => _2; + debug x => _1; } bb0: { - _2 = const false; -- switchInt(_2) -> [0: bb1, otherwise: bb2]; -+ switchInt(const false) -> [0: bb1, otherwise: bb2]; + _1 = const false; + switchInt(const false) -> [0: bb1, otherwise: bb2]; } bb1: { From 96205a4c52cbd3ecb5fc42d8b7c9ade4ec425561 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 20 Sep 2023 21:43:33 +0000 Subject: [PATCH 17/18] Replace legacy ConstProp by GVN. --- .../rustc_mir_transform/src/const_prop.rs | 514 +----------------- compiler/rustc_mir_transform/src/lib.rs | 1 - tests/codegen/inherit_overflow.rs | 2 +- ...const_allocation.main.GVN.after.32bit.mir} | 2 +- ...const_allocation.main.GVN.after.64bit.mir} | 2 +- tests/mir-opt/const_allocation.rs | 4 +- ...onst_allocation2.main.GVN.after.32bit.mir} | 2 +- ...onst_allocation2.main.GVN.after.64bit.mir} | 2 +- tests/mir-opt/const_allocation2.rs | 4 +- ...onst_allocation3.main.GVN.after.32bit.mir} | 2 +- ...onst_allocation3.main.GVN.after.64bit.mir} | 2 +- tests/mir-opt/const_allocation3.rs | 4 +- ...Prop.diff => address_of_pair.fn0.GVN.diff} | 20 +- tests/mir-opt/const_prop/address_of_pair.rs | 4 +- ...iff => aggregate.foo.GVN.panic-abort.diff} | 22 +- ...ff => aggregate.foo.GVN.panic-unwind.diff} | 22 +- ...egate.foo.PreCodegen.after.panic-abort.mir | 12 +- ...gate.foo.PreCodegen.after.panic-unwind.mir | 12 +- ...ff => aggregate.main.GVN.panic-abort.diff} | 10 +- ...f => aggregate.main.GVN.panic-unwind.diff} | 10 +- ...gate.main.PreCodegen.after.panic-abort.mir | 4 +- ...ate.main.PreCodegen.after.panic-unwind.mir | 4 +- tests/mir-opt/const_prop/aggregate.rs | 6 +- ...ndex.main.ConstProp.32bit.panic-abort.diff | 39 -- ...ray_index.main.GVN.32bit.panic-abort.diff} | 7 +- ...ay_index.main.GVN.32bit.panic-unwind.diff} | 7 +- ...ay_index.main.GVN.64bit.panic-unwind.diff} | 7 +- tests/mir-opt/const_prop/array_index.rs | 4 +- ..._op_div_by_zero.main.GVN.panic-abort.diff} | 10 +- ...op_div_by_zero.main.GVN.panic-unwind.diff} | 10 +- .../mir-opt/const_prop/bad_op_div_by_zero.rs | 4 +- ..._op_mod_by_zero.main.GVN.panic-abort.diff} | 10 +- ...op_mod_by_zero.main.GVN.panic-unwind.diff} | 10 +- .../mir-opt/const_prop/bad_op_mod_by_zero.rs | 4 +- ...ices.main.ConstProp.32bit.panic-abort.diff | 54 -- ...or_slices.main.GVN.32bit.panic-abort.diff} | 7 +- ...r_slices.main.GVN.32bit.panic-unwind.diff} | 7 +- ...r_slices.main.GVN.64bit.panic-unwind.diff} | 7 +- .../bad_op_unsafe_oob_for_slices.rs | 4 +- .../mir-opt/const_prop/boolean_identities.rs | 4 +- .../boolean_identities.test.ConstProp.diff | 25 - .../boolean_identities.test.GVN.diff | 24 + ...t.diff => boxes.main.GVN.panic-abort.diff} | 4 +- ....diff => boxes.main.GVN.panic-unwind.diff} | 4 +- tests/mir-opt/const_prop/boxes.rs | 4 +- ...main.ConstProp.diff => cast.main.GVN.diff} | 4 +- tests/mir-opt/const_prop/cast.rs | 4 +- ... => checked_add.main.GVN.panic-abort.diff} | 6 +- ...=> checked_add.main.GVN.panic-unwind.diff} | 6 +- tests/mir-opt/const_prop/checked_add.rs | 4 +- ...ails_gracefully.main.GVN.panic-abort.diff} | 13 +- ...ils_gracefully.main.GVN.panic-unwind.diff} | 13 +- .../const_prop/const_prop_fails_gracefully.rs | 4 +- ...simplification.hello.GVN.panic-abort.diff} | 9 +- ...implification.hello.GVN.panic-unwind.diff} | 9 +- .../const_prop/control_flow_simplification.rs | 4 +- ....diff => discriminant.main.GVN.32bit.diff} | 4 +- ....diff => discriminant.main.GVN.64bit.diff} | 4 +- tests/mir-opt/const_prop/discriminant.rs | 4 +- ...iff => indirect.main.GVN.panic-abort.diff} | 6 +- ...ff => indirect.main.GVN.panic-unwind.diff} | 6 +- tests/mir-opt/const_prop/indirect.rs | 4 +- ...nherit_overflow.main.GVN.panic-abort.diff} | 6 +- ...herit_overflow.main.GVN.panic-unwind.diff} | 6 +- tests/mir-opt/const_prop/inherit_overflow.rs | 4 +- ...op.diff => invalid_constant.main.GVN.diff} | 13 +- tests/mir-opt/const_prop/invalid_constant.rs | 4 +- ...ssue_66971.main.ConstProp.panic-abort.diff | 20 - ...sue_66971.main.ConstProp.panic-unwind.diff | 20 - .../issue_66971.main.GVN.panic-abort.diff | 26 + .../issue_66971.main.GVN.panic-unwind.diff | 26 + tests/mir-opt/const_prop/issue_66971.rs | 6 +- ...ssue_67019.main.ConstProp.panic-abort.diff | 20 - ...sue_67019.main.ConstProp.panic-unwind.diff | 20 - .../issue_67019.main.GVN.panic-abort.diff | 39 ++ .../issue_67019.main.GVN.panic-unwind.diff | 39 ++ tests/mir-opt/const_prop/issue_67019.rs | 4 +- ...ndex.main.ConstProp.64bit.panic-abort.diff | 39 -- ...ray_index.main.GVN.32bit.panic-abort.diff} | 14 +- ...ay_index.main.GVN.32bit.panic-unwind.diff} | 14 +- ...ay_index.main.GVN.64bit.panic-unwind.diff} | 14 +- tests/mir-opt/const_prop/large_array_index.rs | 4 +- tests/mir-opt/const_prop/mult_by_zero.rs | 4 +- ...stProp.diff => mult_by_zero.test.GVN.diff} | 6 +- ...op.diff => mutable_variable.main.GVN.diff} | 7 +- tests/mir-opt/const_prop/mutable_variable.rs | 4 +- ... mutable_variable_aggregate.main.GVN.diff} | 13 +- .../const_prop/mutable_variable_aggregate.rs | 4 +- ..._variable_aggregate_mut_ref.main.GVN.diff} | 11 +- .../mutable_variable_aggregate_mut_ref.rs | 4 +- ...te_partial_read.main.GVN.panic-abort.diff} | 7 +- ...e_partial_read.main.GVN.panic-unwind.diff} | 7 +- ...mutable_variable_aggregate_partial_read.rs | 4 +- ...=> mutable_variable_no_prop.main.GVN.diff} | 4 +- .../const_prop/mutable_variable_no_prop.rs | 4 +- ...e_unprop_assign.main.GVN.panic-abort.diff} | 9 +- ..._unprop_assign.main.GVN.panic-unwind.diff} | 9 +- .../mutable_variable_unprop_assign.rs | 4 +- ...> offset_of.concrete.GVN.panic-abort.diff} | 4 +- ... offset_of.concrete.GVN.panic-unwind.diff} | 4 +- ...=> offset_of.generic.GVN.panic-abort.diff} | 16 +- ...> offset_of.generic.GVN.panic-unwind.diff} | 16 +- tests/mir-opt/const_prop/offset_of.rs | 6 +- ...ff => read_immutable_static.main.GVN.diff} | 10 +- .../const_prop/read_immutable_static.rs | 4 +- ...ConstProp.diff => ref_deref.main.GVN.diff} | 7 +- tests/mir-opt/const_prop/ref_deref.rs | 4 +- ...p.diff => ref_deref_project.main.GVN.diff} | 7 +- tests/mir-opt/const_prop/ref_deref_project.rs | 4 +- ...stProp.diff => reify_fn_ptr.main.GVN.diff} | 4 +- tests/mir-opt/const_prop/reify_fn_ptr.rs | 4 +- ...peat.main.ConstProp.32bit.panic-abort.diff | 44 -- ...=> repeat.main.GVN.32bit.panic-abort.diff} | 17 +- ...> repeat.main.GVN.32bit.panic-unwind.diff} | 17 +- ...> repeat.main.GVN.64bit.panic-unwind.diff} | 17 +- tests/mir-opt/const_prop/repeat.rs | 4 +- ... => return_place.add.GVN.panic-abort.diff} | 6 +- ...=> return_place.add.GVN.panic-unwind.diff} | 6 +- ...lace.add.PreCodegen.before.panic-abort.mir | 2 +- ...ace.add.PreCodegen.before.panic-unwind.mir | 2 +- tests/mir-opt/const_prop/return_place.rs | 4 +- ...ral_propagation.main.GVN.panic-abort.diff} | 10 +- ...al_propagation.main.GVN.panic-unwind.diff} | 10 +- .../const_prop/scalar_literal_propagation.rs | 4 +- ..._len.main.ConstProp.32bit.panic-abort.diff | 47 -- ...slice_len.main.GVN.32bit.panic-abort.diff} | 23 +- ...lice_len.main.GVN.32bit.panic-unwind.diff} | 23 +- ...lice_len.main.GVN.64bit.panic-unwind.diff} | 23 +- tests/mir-opt/const_prop/slice_len.rs | 4 +- ...f => switch_int.main.GVN.panic-abort.diff} | 4 +- ... => switch_int.main.GVN.panic-unwind.diff} | 4 +- tests/mir-opt/const_prop/switch_int.rs | 4 +- ...iff => transmute.from_char.GVN.32bit.diff} | 4 +- ...iff => transmute.from_char.GVN.64bit.diff} | 4 +- ... => transmute.invalid_bool.GVN.32bit.diff} | 4 +- ... => transmute.invalid_bool.GVN.64bit.diff} | 4 +- ... => transmute.invalid_char.GVN.32bit.diff} | 4 +- ... => transmute.invalid_char.GVN.64bit.diff} | 4 +- ...ff => transmute.less_as_i8.GVN.32bit.diff} | 4 +- ...ff => transmute.less_as_i8.GVN.64bit.diff} | 4 +- tests/mir-opt/const_prop/transmute.rs | 22 +- ...ute.undef_union_as_integer.GVN.32bit.diff} | 10 +- ...ute.undef_union_as_integer.GVN.64bit.diff} | 10 +- ... transmute.unreachable_box.GVN.32bit.diff} | 4 +- ... transmute.unreachable_box.GVN.64bit.diff} | 4 +- ...ansmute.unreachable_direct.GVN.32bit.diff} | 10 +- ...ansmute.unreachable_direct.GVN.64bit.diff} | 10 +- ... transmute.unreachable_mut.GVN.32bit.diff} | 4 +- ... transmute.unreachable_mut.GVN.64bit.diff} | 4 +- ... transmute.unreachable_ref.GVN.32bit.diff} | 4 +- ... transmute.unreachable_ref.GVN.64bit.diff} | 4 +- ...ff => transmute.valid_char.GVN.32bit.diff} | 4 +- ...ff => transmute.valid_char.GVN.64bit.diff} | 4 +- ...ral_propagation.main.GVN.panic-abort.diff} | 20 +- ...al_propagation.main.GVN.panic-unwind.diff} | 20 +- .../const_prop/tuple_literal_propagation.rs | 4 +- ...while_let_loops.change_loop_body.GVN.diff} | 14 +- tests/mir-opt/const_prop/while_let_loops.rs | 4 +- ...iff => const_prop_miscompile.bar.GVN.diff} | 7 +- ...iff => const_prop_miscompile.foo.GVN.diff} | 7 +- tests/mir-opt/const_prop_miscompile.rs | 6 +- ....f.DestinationPropagation.panic-abort.diff | 22 +- ...f.DestinationPropagation.panic-unwind.diff | 22 +- tests/mir-opt/dest-prop/unreachable.rs | 2 +- ...o_exponential_common.GVN.panic-abort.diff} | 51 +- ..._exponential_common.GVN.panic-unwind.diff} | 51 +- tests/mir-opt/funky_arms.rs | 2 +- ...ue_101973.inner.ConstProp.panic-abort.diff | 66 --- ...e_101973.inner.ConstProp.panic-unwind.diff | 66 --- .../issue_101973.inner.GVN.panic-abort.diff | 82 +++ .../issue_101973.inner.GVN.panic-unwind.diff | 82 +++ tests/mir-opt/issue_101973.rs | 4 +- ...ecked_ops.checked_shl.PreCodegen.after.mir | 2 +- .../loops.int_range.PreCodegen.after.mir | 2 +- ...able.main.ConstProp.32bit.panic-abort.diff | 47 -- ...ble.main.ConstProp.32bit.panic-unwind.diff | 47 -- ...able.main.ConstProp.64bit.panic-abort.diff | 47 -- ...ble.main.ConstProp.64bit.panic-unwind.diff | 47 -- ...o_variable.main.GVN.32bit.panic-abort.diff | 62 +++ ..._variable.main.GVN.32bit.panic-unwind.diff | 62 +++ ..._variable.main.GVN.64bit.panic-unwind.diff | 62 +++ ...ain.PreCodegen.after.32bit.panic-abort.mir | 5 +- ...in.PreCodegen.after.32bit.panic-unwind.mir | 5 +- ...ain.PreCodegen.after.64bit.panic-abort.mir | 5 +- ...in.PreCodegen.after.64bit.panic-unwind.mir | 5 +- ...fyLocals-final.after.32bit.panic-abort.mir | 5 +- ...yLocals-final.after.32bit.panic-unwind.mir | 5 +- ...fyLocals-final.after.64bit.panic-abort.mir | 5 +- ...yLocals-final.after.64bit.panic-unwind.mir | 5 +- .../pre-codegen/optimizes_into_variable.rs | 2 +- ...iter_next.PreCodegen.after.panic-abort.mir | 2 +- ...ter_next.PreCodegen.after.panic-unwind.mir | 2 +- ...mple_option_map.ezmap.PreCodegen.after.mir | 2 +- ...ange_loop.PreCodegen.after.panic-abort.mir | 2 +- ...nge_loop.PreCodegen.after.panic-unwind.mir | 2 +- ...ify_match.main.ConstProp.panic-unwind.diff | 28 - ... simplify_match.main.GVN.panic-abort.diff} | 14 +- .../simplify_match.main.GVN.panic-unwind.diff | 30 + tests/mir-opt/simplify_match.rs | 2 +- 199 files changed, 1208 insertions(+), 1785 deletions(-) rename tests/mir-opt/{const_allocation.main.ConstProp.after.32bit.mir => const_allocation.main.GVN.after.32bit.mir} (98%) rename tests/mir-opt/{const_allocation.main.ConstProp.after.64bit.mir => const_allocation.main.GVN.after.64bit.mir} (98%) rename tests/mir-opt/{const_allocation2.main.ConstProp.after.32bit.mir => const_allocation2.main.GVN.after.32bit.mir} (97%) rename tests/mir-opt/{const_allocation2.main.ConstProp.after.64bit.mir => const_allocation2.main.GVN.after.64bit.mir} (98%) rename tests/mir-opt/{const_allocation3.main.ConstProp.after.32bit.mir => const_allocation3.main.GVN.after.32bit.mir} (98%) rename tests/mir-opt/{const_allocation3.main.ConstProp.after.64bit.mir => const_allocation3.main.GVN.after.64bit.mir} (98%) rename tests/mir-opt/const_prop/{address_of_pair.fn0.ConstProp.diff => address_of_pair.fn0.GVN.diff} (67%) rename tests/mir-opt/const_prop/{aggregate.foo.ConstProp.panic-abort.diff => aggregate.foo.GVN.panic-abort.diff} (69%) rename tests/mir-opt/const_prop/{aggregate.foo.ConstProp.panic-unwind.diff => aggregate.foo.GVN.panic-unwind.diff} (69%) rename tests/mir-opt/const_prop/{aggregate.main.ConstProp.panic-abort.diff => aggregate.main.GVN.panic-abort.diff} (85%) rename tests/mir-opt/const_prop/{aggregate.main.ConstProp.panic-unwind.diff => aggregate.main.GVN.panic-unwind.diff} (85%) delete mode 100644 tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-abort.diff rename tests/mir-opt/const_prop/{array_index.main.ConstProp.64bit.panic-abort.diff => array_index.main.GVN.32bit.panic-abort.diff} (88%) rename tests/mir-opt/const_prop/{array_index.main.ConstProp.32bit.panic-unwind.diff => array_index.main.GVN.32bit.panic-unwind.diff} (88%) rename tests/mir-opt/const_prop/{array_index.main.ConstProp.64bit.panic-unwind.diff => array_index.main.GVN.64bit.panic-unwind.diff} (88%) rename tests/mir-opt/const_prop/{bad_op_div_by_zero.main.ConstProp.panic-abort.diff => bad_op_div_by_zero.main.GVN.panic-abort.diff} (91%) rename tests/mir-opt/const_prop/{bad_op_div_by_zero.main.ConstProp.panic-unwind.diff => bad_op_div_by_zero.main.GVN.panic-unwind.diff} (91%) rename tests/mir-opt/const_prop/{bad_op_mod_by_zero.main.ConstProp.panic-abort.diff => bad_op_mod_by_zero.main.GVN.panic-abort.diff} (91%) rename tests/mir-opt/const_prop/{bad_op_mod_by_zero.main.ConstProp.panic-unwind.diff => bad_op_mod_by_zero.main.GVN.panic-unwind.diff} (91%) delete mode 100644 tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-abort.diff rename tests/mir-opt/const_prop/{bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-abort.diff => bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-abort.diff} (91%) rename tests/mir-opt/const_prop/{bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-unwind.diff => bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-unwind.diff} (91%) rename tests/mir-opt/const_prop/{bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-unwind.diff => bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-unwind.diff} (91%) delete mode 100644 tests/mir-opt/const_prop/boolean_identities.test.ConstProp.diff create mode 100644 tests/mir-opt/const_prop/boolean_identities.test.GVN.diff rename tests/mir-opt/const_prop/{boxes.main.ConstProp.panic-abort.diff => boxes.main.GVN.panic-abort.diff} (95%) rename tests/mir-opt/const_prop/{boxes.main.ConstProp.panic-unwind.diff => boxes.main.GVN.panic-unwind.diff} (95%) rename tests/mir-opt/const_prop/{cast.main.ConstProp.diff => cast.main.GVN.diff} (87%) rename tests/mir-opt/const_prop/{checked_add.main.ConstProp.panic-abort.diff => checked_add.main.GVN.panic-abort.diff} (88%) rename tests/mir-opt/const_prop/{checked_add.main.ConstProp.panic-unwind.diff => checked_add.main.GVN.panic-unwind.diff} (88%) rename tests/mir-opt/const_prop/{const_prop_fails_gracefully.main.ConstProp.panic-abort.diff => const_prop_fails_gracefully.main.GVN.panic-abort.diff} (70%) rename tests/mir-opt/const_prop/{const_prop_fails_gracefully.main.ConstProp.panic-unwind.diff => const_prop_fails_gracefully.main.GVN.panic-unwind.diff} (70%) rename tests/mir-opt/const_prop/{control_flow_simplification.hello.ConstProp.panic-abort.diff => control_flow_simplification.hello.GVN.panic-abort.diff} (66%) rename tests/mir-opt/const_prop/{control_flow_simplification.hello.ConstProp.panic-unwind.diff => control_flow_simplification.hello.GVN.panic-unwind.diff} (66%) rename tests/mir-opt/const_prop/{discriminant.main.ConstProp.32bit.diff => discriminant.main.GVN.32bit.diff} (93%) rename tests/mir-opt/const_prop/{discriminant.main.ConstProp.64bit.diff => discriminant.main.GVN.64bit.diff} (93%) rename tests/mir-opt/const_prop/{indirect.main.ConstProp.panic-abort.diff => indirect.main.GVN.panic-abort.diff} (90%) rename tests/mir-opt/const_prop/{indirect.main.ConstProp.panic-unwind.diff => indirect.main.GVN.panic-unwind.diff} (90%) rename tests/mir-opt/const_prop/{inherit_overflow.main.ConstProp.panic-abort.diff => inherit_overflow.main.GVN.panic-abort.diff} (91%) rename tests/mir-opt/const_prop/{inherit_overflow.main.ConstProp.panic-unwind.diff => inherit_overflow.main.GVN.panic-unwind.diff} (91%) rename tests/mir-opt/const_prop/{invalid_constant.main.ConstProp.diff => invalid_constant.main.GVN.diff} (83%) delete mode 100644 tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff delete mode 100644 tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff create mode 100644 tests/mir-opt/const_prop/issue_66971.main.GVN.panic-abort.diff create mode 100644 tests/mir-opt/const_prop/issue_66971.main.GVN.panic-unwind.diff delete mode 100644 tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff delete mode 100644 tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff create mode 100644 tests/mir-opt/const_prop/issue_67019.main.GVN.panic-abort.diff create mode 100644 tests/mir-opt/const_prop/issue_67019.main.GVN.panic-unwind.diff delete mode 100644 tests/mir-opt/const_prop/large_array_index.main.ConstProp.64bit.panic-abort.diff rename tests/mir-opt/const_prop/{large_array_index.main.ConstProp.32bit.panic-abort.diff => large_array_index.main.GVN.32bit.panic-abort.diff} (65%) rename tests/mir-opt/const_prop/{large_array_index.main.ConstProp.64bit.panic-unwind.diff => large_array_index.main.GVN.32bit.panic-unwind.diff} (65%) rename tests/mir-opt/const_prop/{large_array_index.main.ConstProp.32bit.panic-unwind.diff => large_array_index.main.GVN.64bit.panic-unwind.diff} (65%) rename tests/mir-opt/const_prop/{mult_by_zero.test.ConstProp.diff => mult_by_zero.test.GVN.diff} (72%) rename tests/mir-opt/const_prop/{mutable_variable.main.ConstProp.diff => mutable_variable.main.GVN.diff} (78%) rename tests/mir-opt/const_prop/{mutable_variable_aggregate.main.ConstProp.diff => mutable_variable_aggregate.main.GVN.diff} (68%) rename tests/mir-opt/const_prop/{mutable_variable_aggregate_mut_ref.main.ConstProp.diff => mutable_variable_aggregate_mut_ref.main.GVN.diff} (72%) rename tests/mir-opt/const_prop/{mutable_variable_aggregate_partial_read.main.ConstProp.panic-abort.diff => mutable_variable_aggregate_partial_read.main.GVN.panic-abort.diff} (80%) rename tests/mir-opt/const_prop/{mutable_variable_aggregate_partial_read.main.ConstProp.panic-unwind.diff => mutable_variable_aggregate_partial_read.main.GVN.panic-unwind.diff} (80%) rename tests/mir-opt/const_prop/{mutable_variable_no_prop.main.ConstProp.diff => mutable_variable_no_prop.main.GVN.diff} (92%) rename tests/mir-opt/const_prop/{mutable_variable_unprop_assign.main.ConstProp.panic-abort.diff => mutable_variable_unprop_assign.main.GVN.panic-abort.diff} (87%) rename tests/mir-opt/const_prop/{mutable_variable_unprop_assign.main.ConstProp.panic-unwind.diff => mutable_variable_unprop_assign.main.GVN.panic-unwind.diff} (87%) rename tests/mir-opt/const_prop/{offset_of.concrete.ConstProp.panic-abort.diff => offset_of.concrete.GVN.panic-abort.diff} (96%) rename tests/mir-opt/const_prop/{offset_of.concrete.ConstProp.panic-unwind.diff => offset_of.concrete.GVN.panic-unwind.diff} (96%) rename tests/mir-opt/const_prop/{offset_of.generic.ConstProp.panic-abort.diff => offset_of.generic.GVN.panic-abort.diff} (73%) rename tests/mir-opt/const_prop/{offset_of.generic.ConstProp.panic-unwind.diff => offset_of.generic.GVN.panic-unwind.diff} (73%) rename tests/mir-opt/const_prop/{read_immutable_static.main.ConstProp.diff => read_immutable_static.main.GVN.diff} (85%) rename tests/mir-opt/const_prop/{ref_deref.main.ConstProp.diff => ref_deref.main.GVN.diff} (76%) rename tests/mir-opt/const_prop/{ref_deref_project.main.ConstProp.diff => ref_deref_project.main.GVN.diff} (77%) rename tests/mir-opt/const_prop/{reify_fn_ptr.main.ConstProp.diff => reify_fn_ptr.main.GVN.diff} (88%) delete mode 100644 tests/mir-opt/const_prop/repeat.main.ConstProp.32bit.panic-abort.diff rename tests/mir-opt/const_prop/{repeat.main.ConstProp.64bit.panic-abort.diff => repeat.main.GVN.32bit.panic-abort.diff} (64%) rename tests/mir-opt/const_prop/{repeat.main.ConstProp.64bit.panic-unwind.diff => repeat.main.GVN.32bit.panic-unwind.diff} (64%) rename tests/mir-opt/const_prop/{repeat.main.ConstProp.32bit.panic-unwind.diff => repeat.main.GVN.64bit.panic-unwind.diff} (64%) rename tests/mir-opt/const_prop/{return_place.add.ConstProp.panic-abort.diff => return_place.add.GVN.panic-abort.diff} (87%) rename tests/mir-opt/const_prop/{return_place.add.ConstProp.panic-unwind.diff => return_place.add.GVN.panic-unwind.diff} (86%) rename tests/mir-opt/const_prop/{scalar_literal_propagation.main.ConstProp.panic-abort.diff => scalar_literal_propagation.main.GVN.panic-abort.diff} (79%) rename tests/mir-opt/const_prop/{scalar_literal_propagation.main.ConstProp.panic-unwind.diff => scalar_literal_propagation.main.GVN.panic-unwind.diff} (79%) delete mode 100644 tests/mir-opt/const_prop/slice_len.main.ConstProp.32bit.panic-abort.diff rename tests/mir-opt/const_prop/{slice_len.main.ConstProp.64bit.panic-abort.diff => slice_len.main.GVN.32bit.panic-abort.diff} (62%) rename tests/mir-opt/const_prop/{slice_len.main.ConstProp.32bit.panic-unwind.diff => slice_len.main.GVN.32bit.panic-unwind.diff} (62%) rename tests/mir-opt/const_prop/{slice_len.main.ConstProp.64bit.panic-unwind.diff => slice_len.main.GVN.64bit.panic-unwind.diff} (62%) rename tests/mir-opt/const_prop/{switch_int.main.ConstProp.panic-abort.diff => switch_int.main.GVN.panic-abort.diff} (87%) rename tests/mir-opt/const_prop/{switch_int.main.ConstProp.panic-unwind.diff => switch_int.main.GVN.panic-unwind.diff} (87%) rename tests/mir-opt/const_prop/{transmute.from_char.ConstProp.32bit.diff => transmute.from_char.GVN.32bit.diff} (70%) rename tests/mir-opt/const_prop/{transmute.from_char.ConstProp.64bit.diff => transmute.from_char.GVN.64bit.diff} (70%) rename tests/mir-opt/const_prop/{transmute.invalid_bool.ConstProp.64bit.diff => transmute.invalid_bool.GVN.32bit.diff} (71%) rename tests/mir-opt/const_prop/{transmute.invalid_bool.ConstProp.32bit.diff => transmute.invalid_bool.GVN.64bit.diff} (71%) rename tests/mir-opt/const_prop/{transmute.invalid_char.ConstProp.32bit.diff => transmute.invalid_char.GVN.32bit.diff} (71%) rename tests/mir-opt/const_prop/{transmute.invalid_char.ConstProp.64bit.diff => transmute.invalid_char.GVN.64bit.diff} (71%) rename tests/mir-opt/const_prop/{transmute.less_as_i8.ConstProp.32bit.diff => transmute.less_as_i8.GVN.32bit.diff} (79%) rename tests/mir-opt/const_prop/{transmute.less_as_i8.ConstProp.64bit.diff => transmute.less_as_i8.GVN.64bit.diff} (79%) rename tests/mir-opt/const_prop/{transmute.undef_union_as_integer.ConstProp.64bit.diff => transmute.undef_union_as_integer.GVN.32bit.diff} (61%) rename tests/mir-opt/const_prop/{transmute.undef_union_as_integer.ConstProp.32bit.diff => transmute.undef_union_as_integer.GVN.64bit.diff} (61%) rename tests/mir-opt/const_prop/{transmute.unreachable_box.ConstProp.64bit.diff => transmute.unreachable_box.GVN.32bit.diff} (83%) rename tests/mir-opt/const_prop/{transmute.unreachable_box.ConstProp.32bit.diff => transmute.unreachable_box.GVN.64bit.diff} (83%) rename tests/mir-opt/const_prop/{transmute.unreachable_direct.ConstProp.32bit.diff => transmute.unreachable_direct.GVN.32bit.diff} (56%) rename tests/mir-opt/const_prop/{transmute.unreachable_direct.ConstProp.64bit.diff => transmute.unreachable_direct.GVN.64bit.diff} (56%) rename tests/mir-opt/const_prop/{transmute.unreachable_mut.ConstProp.32bit.diff => transmute.unreachable_mut.GVN.32bit.diff} (82%) rename tests/mir-opt/const_prop/{transmute.unreachable_mut.ConstProp.64bit.diff => transmute.unreachable_mut.GVN.64bit.diff} (82%) rename tests/mir-opt/const_prop/{transmute.unreachable_ref.ConstProp.32bit.diff => transmute.unreachable_ref.GVN.32bit.diff} (77%) rename tests/mir-opt/const_prop/{transmute.unreachable_ref.ConstProp.64bit.diff => transmute.unreachable_ref.GVN.64bit.diff} (77%) rename tests/mir-opt/const_prop/{transmute.valid_char.ConstProp.32bit.diff => transmute.valid_char.GVN.32bit.diff} (70%) rename tests/mir-opt/const_prop/{transmute.valid_char.ConstProp.64bit.diff => transmute.valid_char.GVN.64bit.diff} (70%) rename tests/mir-opt/const_prop/{tuple_literal_propagation.main.ConstProp.panic-abort.diff => tuple_literal_propagation.main.GVN.panic-abort.diff} (66%) rename tests/mir-opt/const_prop/{tuple_literal_propagation.main.ConstProp.panic-unwind.diff => tuple_literal_propagation.main.GVN.panic-unwind.diff} (66%) rename tests/mir-opt/const_prop/{while_let_loops.change_loop_body.ConstProp.diff => while_let_loops.change_loop_body.GVN.diff} (68%) rename tests/mir-opt/{const_prop_miscompile.bar.ConstProp.diff => const_prop_miscompile.bar.GVN.diff} (87%) rename tests/mir-opt/{const_prop_miscompile.foo.ConstProp.diff => const_prop_miscompile.foo.GVN.diff} (84%) rename tests/mir-opt/{funky_arms.float_to_exponential_common.ConstProp.panic-abort.diff => funky_arms.float_to_exponential_common.GVN.panic-abort.diff} (68%) rename tests/mir-opt/{funky_arms.float_to_exponential_common.ConstProp.panic-unwind.diff => funky_arms.float_to_exponential_common.GVN.panic-unwind.diff} (68%) delete mode 100644 tests/mir-opt/issue_101973.inner.ConstProp.panic-abort.diff delete mode 100644 tests/mir-opt/issue_101973.inner.ConstProp.panic-unwind.diff create mode 100644 tests/mir-opt/issue_101973.inner.GVN.panic-abort.diff create mode 100644 tests/mir-opt/issue_101973.inner.GVN.panic-unwind.diff delete mode 100644 tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-abort.diff delete mode 100644 tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-unwind.diff delete mode 100644 tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-abort.diff delete mode 100644 tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-unwind.diff create mode 100644 tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-abort.diff create mode 100644 tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-unwind.diff create mode 100644 tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.64bit.panic-unwind.diff delete mode 100644 tests/mir-opt/simplify_match.main.ConstProp.panic-unwind.diff rename tests/mir-opt/{simplify_match.main.ConstProp.panic-abort.diff => simplify_match.main.GVN.panic-abort.diff} (50%) create mode 100644 tests/mir-opt/simplify_match.main.GVN.panic-unwind.diff diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 4fc78b285803d..b051f3b6244aa 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -1,29 +1,21 @@ //! Propagates constants for early reporting of statically known //! assertion failures -use either::Right; - use rustc_const_eval::const_eval::CheckAlignment; -use rustc_const_eval::ReportErrorExt; use rustc_data_structures::fx::FxHashSet; -use rustc_hir::def::DefKind; use rustc_index::bit_set::BitSet; -use rustc_index::{IndexSlice, IndexVec}; -use rustc_middle::mir::visit::{ - MutVisitor, MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor, -}; +use rustc_index::IndexVec; +use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; -use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout}; -use rustc_middle::ty::{self, GenericArgs, Instance, ParamEnv, Ty, TyCtxt, TypeVisitableExt}; -use rustc_span::{def_id::DefId, Span}; -use rustc_target::abi::{self, Align, HasDataLayout, Size, TargetDataLayout}; +use rustc_middle::ty::layout::TyAndLayout; +use rustc_middle::ty::{self, ParamEnv, TyCtxt}; +use rustc_span::def_id::DefId; +use rustc_target::abi::{Align, Size}; use rustc_target::spec::abi::Abi as CallAbi; -use crate::dataflow_const_prop::Patch; -use crate::MirPass; use rustc_const_eval::interpret::{ - self, compile_time_machine, AllocId, ConstAllocation, FnArg, Frame, ImmTy, Immediate, InterpCx, - InterpResult, MemoryKind, OpTy, PlaceTy, Pointer, Scalar, StackPopCleanup, + self, compile_time_machine, AllocId, ConstAllocation, FnArg, Frame, ImmTy, InterpCx, + InterpResult, OpTy, PlaceTy, Pointer, }; /// The maximum number of bytes that we'll allocate space for a local or the return value. @@ -58,63 +50,7 @@ pub(crate) macro throw_machine_stop_str($($tt:tt)*) {{ throw_machine_stop!(Zst) }} -pub struct ConstProp; - -impl<'tcx> MirPass<'tcx> for ConstProp { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() >= 2 - } - - #[instrument(skip(self, tcx), level = "debug")] - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - // will be evaluated by miri and produce its errors there - if body.source.promoted.is_some() { - return; - } - - let def_id = body.source.def_id().expect_local(); - let def_kind = tcx.def_kind(def_id); - let is_fn_like = def_kind.is_fn_like(); - let is_assoc_const = def_kind == DefKind::AssocConst; - - // Only run const prop on functions, methods, closures and associated constants - if !is_fn_like && !is_assoc_const { - // skip anon_const/statics/consts because they'll be evaluated by miri anyway - trace!("ConstProp skipped for {:?}", def_id); - return; - } - - // FIXME(welseywiser) const prop doesn't work on generators because of query cycles - // computing their layout. - let is_generator = def_kind == DefKind::Generator; - if is_generator { - trace!("ConstProp skipped for generator {:?}", def_id); - return; - } - - trace!("ConstProp starting for {:?}", def_id); - - // FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold - // constants, instead of just checking for const-folding succeeding. - // That would require a uniform one-def no-mutation analysis - // and RPO (or recursing when needing the value of a local). - let mut optimization_finder = ConstPropagator::new(body, tcx); - - // Traverse the body in reverse post-order, to ensure that `FullConstProp` locals are - // assigned before being read. - for &bb in body.basic_blocks.reverse_postorder() { - let data = &body.basic_blocks[bb]; - optimization_finder.visit_basic_block_data(bb, data); - } - - let mut patch = optimization_finder.patch; - patch.visit_body_preserves_cfg(body); - - trace!("ConstProp done for {:?}", def_id); - } -} - -pub struct ConstPropMachine<'mir, 'tcx> { +pub(crate) struct ConstPropMachine<'mir, 'tcx> { /// The virtual call stack. stack: Vec>, pub written_only_inside_own_block_locals: FxHashSet, @@ -286,296 +222,6 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx> } } -/// Finds optimization opportunities on the MIR. -struct ConstPropagator<'mir, 'tcx> { - ecx: InterpCx<'mir, 'tcx, ConstPropMachine<'mir, 'tcx>>, - tcx: TyCtxt<'tcx>, - param_env: ParamEnv<'tcx>, - local_decls: &'mir IndexSlice>, - patch: Patch<'tcx>, -} - -impl<'tcx> LayoutOfHelpers<'tcx> for ConstPropagator<'_, 'tcx> { - type LayoutOfResult = Result, LayoutError<'tcx>>; - - #[inline] - fn handle_layout_err(&self, err: LayoutError<'tcx>, _: Span, _: Ty<'tcx>) -> LayoutError<'tcx> { - err - } -} - -impl HasDataLayout for ConstPropagator<'_, '_> { - #[inline] - fn data_layout(&self) -> &TargetDataLayout { - &self.tcx.data_layout - } -} - -impl<'tcx> ty::layout::HasTyCtxt<'tcx> for ConstPropagator<'_, 'tcx> { - #[inline] - fn tcx(&self) -> TyCtxt<'tcx> { - self.tcx - } -} - -impl<'tcx> ty::layout::HasParamEnv<'tcx> for ConstPropagator<'_, 'tcx> { - #[inline] - fn param_env(&self) -> ty::ParamEnv<'tcx> { - self.param_env - } -} - -impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { - fn new(body: &'mir Body<'tcx>, tcx: TyCtxt<'tcx>) -> ConstPropagator<'mir, 'tcx> { - let def_id = body.source.def_id(); - let args = &GenericArgs::identity_for_item(tcx, def_id); - let param_env = tcx.param_env_reveal_all_normalized(def_id); - - let can_const_prop = CanConstProp::check(tcx, param_env, body); - let mut ecx = InterpCx::new( - tcx, - tcx.def_span(def_id), - param_env, - ConstPropMachine::new(can_const_prop), - ); - - let ret_layout = ecx - .layout_of(body.bound_return_ty().instantiate(tcx, args)) - .ok() - // Don't bother allocating memory for large values. - // I don't know how return types can seem to be unsized but this happens in the - // `type/type-unsatisfiable.rs` test. - .filter(|ret_layout| { - ret_layout.is_sized() && ret_layout.size < Size::from_bytes(MAX_ALLOC_LIMIT) - }) - .unwrap_or_else(|| ecx.layout_of(tcx.types.unit).unwrap()); - - let ret = ecx - .allocate(ret_layout, MemoryKind::Stack) - .expect("couldn't perform small allocation") - .into(); - - ecx.push_stack_frame( - Instance::new(def_id, args), - body, - &ret, - StackPopCleanup::Root { cleanup: false }, - ) - .expect("failed to push initial stack frame"); - - for local in body.local_decls.indices() { - // Mark everything initially live. - // This is somewhat dicey since some of them might be unsized and it is incoherent to - // mark those as live... We rely on `local_to_place`/`local_to_op` in the interpreter - // stopping us before those unsized immediates can cause issues deeper in the - // interpreter. - ecx.frame_mut().locals[local].make_live_uninit(); - } - - let patch = Patch::new(tcx); - ConstPropagator { ecx, tcx, param_env, local_decls: &body.local_decls, patch } - } - - fn get_const(&self, place: Place<'tcx>) -> Option> { - let op = match self.ecx.eval_place_to_op(place, None) { - Ok(op) => { - if op - .as_mplace_or_imm() - .right() - .is_some_and(|imm| matches!(*imm, Immediate::Uninit)) - { - // Make sure nobody accidentally uses this value. - return None; - } - op - } - Err(e) => { - trace!("get_const failed: {:?}", e.into_kind().debug()); - return None; - } - }; - - // Try to read the local as an immediate so that if it is representable as a scalar, we can - // handle it as such, but otherwise, just return the value as is. - Some(match self.ecx.read_immediate_raw(&op) { - Ok(Right(imm)) => imm.into(), - _ => op, - }) - } - - /// Remove `local` from the pool of `Locals`. Allows writing to them, - /// but not reading from them anymore. - fn remove_const(ecx: &mut InterpCx<'mir, 'tcx, ConstPropMachine<'mir, 'tcx>>, local: Local) { - ecx.frame_mut().locals[local].make_live_uninit(); - ecx.machine.written_only_inside_own_block_locals.remove(&local); - } - - fn check_rvalue(&mut self, rvalue: &Rvalue<'tcx>) -> Option<()> { - // Perform any special handling for specific Rvalue types. - // Generally, checks here fall into one of two categories: - // 1. Additional checking to provide useful lints to the user - // - In this case, we will do some validation and then fall through to the - // end of the function which evals the assignment. - // 2. Working around bugs in other parts of the compiler - // - In this case, we'll return `None` from this function to stop evaluation. - match rvalue { - // Do not try creating references (#67862) - Rvalue::AddressOf(_, place) | Rvalue::Ref(_, _, place) => { - trace!("skipping AddressOf | Ref for {:?}", place); - - // This may be creating mutable references or immutable references to cells. - // If that happens, the pointed to value could be mutated via that reference. - // Since we aren't tracking references, the const propagator loses track of what - // value the local has right now. - // Thus, all locals that have their reference taken - // must not take part in propagation. - Self::remove_const(&mut self.ecx, place.local); - - return None; - } - Rvalue::ThreadLocalRef(def_id) => { - trace!("skipping ThreadLocalRef({:?})", def_id); - - return None; - } - // There's no other checking to do at this time. - Rvalue::Aggregate(..) - | Rvalue::Use(..) - | Rvalue::CopyForDeref(..) - | Rvalue::Repeat(..) - | Rvalue::Len(..) - | Rvalue::Cast(..) - | Rvalue::ShallowInitBox(..) - | Rvalue::Discriminant(..) - | Rvalue::NullaryOp(..) - | Rvalue::UnaryOp(..) - | Rvalue::BinaryOp(..) - | Rvalue::CheckedBinaryOp(..) => {} - } - - // FIXME we need to revisit this for #67176 - if rvalue.has_param() { - return None; - } - if !rvalue - .ty(&self.ecx.frame().body.local_decls, *self.ecx.tcx) - .is_sized(*self.ecx.tcx, self.param_env) - { - // the interpreter doesn't support unsized locals (only unsized arguments), - // but rustc does (in a kinda broken way), so we have to skip them here - return None; - } - - Some(()) - } - - // Attempt to use algebraic identities to eliminate constant expressions - fn eval_rvalue_with_identities( - &mut self, - rvalue: &Rvalue<'tcx>, - place: Place<'tcx>, - ) -> Option<()> { - match rvalue { - Rvalue::BinaryOp(op, box (left, right)) - | Rvalue::CheckedBinaryOp(op, box (left, right)) => { - let l = self.ecx.eval_operand(left, None).and_then(|x| self.ecx.read_immediate(&x)); - let r = - self.ecx.eval_operand(right, None).and_then(|x| self.ecx.read_immediate(&x)); - - let const_arg = match (l, r) { - (Ok(x), Err(_)) | (Err(_), Ok(x)) => x, // exactly one side is known - (Err(_), Err(_)) => return None, // neither side is known - (Ok(_), Ok(_)) => return self.ecx.eval_rvalue_into_place(rvalue, place).ok(), // both sides are known - }; - - if !matches!(const_arg.layout.abi, abi::Abi::Scalar(..)) { - // We cannot handle Scalar Pair stuff. - // No point in calling `eval_rvalue_into_place`, since only one side is known - return None; - } - - let arg_value = const_arg.to_scalar().to_bits(const_arg.layout.size).ok()?; - let dest = self.ecx.eval_place(place).ok()?; - - match op { - BinOp::BitAnd if arg_value == 0 => { - self.ecx.write_immediate(*const_arg, &dest).ok() - } - BinOp::BitOr - if arg_value == const_arg.layout.size.truncate(u128::MAX) - || (const_arg.layout.ty.is_bool() && arg_value == 1) => - { - self.ecx.write_immediate(*const_arg, &dest).ok() - } - BinOp::Mul if const_arg.layout.ty.is_integral() && arg_value == 0 => { - if let Rvalue::CheckedBinaryOp(_, _) = rvalue { - let val = Immediate::ScalarPair( - const_arg.to_scalar(), - Scalar::from_bool(false), - ); - self.ecx.write_immediate(val, &dest).ok() - } else { - self.ecx.write_immediate(*const_arg, &dest).ok() - } - } - _ => None, - } - } - _ => self.ecx.eval_rvalue_into_place(rvalue, place).ok(), - } - } - - fn replace_with_const(&mut self, place: Place<'tcx>) -> Option> { - // This will return None if the above `const_prop` invocation only "wrote" a - // type whose creation requires no write. E.g. a generator whose initial state - // consists solely of uninitialized memory (so it doesn't capture any locals). - let value = self.get_const(place)?; - if !self.tcx.consider_optimizing(|| format!("ConstantPropagation - {value:?}")) { - return None; - } - trace!("replacing {:?} with {:?}", place, value); - - // FIXME: figure out what to do when read_immediate_raw fails - let imm = self.ecx.read_immediate_raw(&value).ok()?; - - let Right(imm) = imm else { return None }; - match *imm { - Immediate::Scalar(scalar) if scalar.try_to_int().is_ok() => { - Some(Const::from_scalar(self.tcx, scalar, value.layout.ty)) - } - Immediate::ScalarPair(l, r) if l.try_to_int().is_ok() && r.try_to_int().is_ok() => { - let alloc_id = self - .ecx - .intern_with_temp_alloc(value.layout, |ecx, dest| { - ecx.write_immediate(*imm, dest) - }) - .ok()?; - - Some(Const::Val( - ConstValue::Indirect { alloc_id, offset: Size::ZERO }, - value.layout.ty, - )) - } - // Scalars or scalar pairs that contain undef values are assumed to not have - // successfully evaluated and are thus not propagated. - _ => None, - } - } - - fn ensure_not_propagated(&self, local: Local) { - if cfg!(debug_assertions) { - assert!( - self.get_const(local.into()).is_none() - || self - .layout_of(self.local_decls[local].ty) - .map_or(true, |layout| layout.is_zst()), - "failed to remove values for `{local:?}`, value={:?}", - self.get_const(local.into()), - ) - } - } -} - /// The mode that `ConstProp` is allowed to run in for a given `Local`. #[derive(Clone, Copy, Debug, PartialEq)] pub enum ConstPropMode { @@ -695,145 +341,3 @@ impl<'tcx> Visitor<'tcx> for CanConstProp { } } } - -impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> { - fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) { - self.super_operand(operand, location); - if let Some(place) = operand.place() && let Some(value) = self.replace_with_const(place) { - self.patch.before_effect.insert((location, place), value); - } - } - - fn visit_projection_elem( - &mut self, - _: PlaceRef<'tcx>, - elem: PlaceElem<'tcx>, - _: PlaceContext, - location: Location, - ) { - if let PlaceElem::Index(local) = elem - && let Some(value) = self.replace_with_const(local.into()) - { - self.patch.before_effect.insert((location, local.into()), value); - } - } - - fn visit_assign(&mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) { - self.super_assign(place, rvalue, location); - - let Some(()) = self.check_rvalue(rvalue) else { return }; - - match self.ecx.machine.can_const_prop[place.local] { - // Do nothing if the place is indirect. - _ if place.is_indirect() => {} - ConstPropMode::NoPropagation => self.ensure_not_propagated(place.local), - ConstPropMode::OnlyInsideOwnBlock | ConstPropMode::FullConstProp => { - if let Some(()) = self.eval_rvalue_with_identities(rvalue, *place) { - // If this was already an evaluated constant, keep it. - if let Rvalue::Use(Operand::Constant(c)) = rvalue - && let Const::Val(..) = c.const_ - { - trace!("skipping replace of Rvalue::Use({:?} because it is already a const", c); - } else if let Some(operand) = self.replace_with_const(*place) { - self.patch.assignments.insert(location, operand); - } - } else { - // Const prop failed, so erase the destination, ensuring that whatever happens - // from here on, does not know about the previous value. - // This is important in case we have - // ```rust - // let mut x = 42; - // x = SOME_MUTABLE_STATIC; - // // x must now be uninit - // ``` - // FIXME: we overzealously erase the entire local, because that's easier to - // implement. - trace!( - "propagation into {:?} failed. - Nuking the entire site from orbit, it's the only way to be sure", - place, - ); - Self::remove_const(&mut self.ecx, place.local); - } - } - } - } - - fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) { - trace!("visit_statement: {:?}", statement); - - // We want to evaluate operands before any change to the assigned-to value, - // so we recurse first. - self.super_statement(statement, location); - - match statement.kind { - StatementKind::SetDiscriminant { ref place, .. } => { - match self.ecx.machine.can_const_prop[place.local] { - // Do nothing if the place is indirect. - _ if place.is_indirect() => {} - ConstPropMode::NoPropagation => self.ensure_not_propagated(place.local), - ConstPropMode::FullConstProp | ConstPropMode::OnlyInsideOwnBlock => { - if self.ecx.statement(statement).is_ok() { - trace!("propped discriminant into {:?}", place); - } else { - Self::remove_const(&mut self.ecx, place.local); - } - } - } - } - StatementKind::StorageLive(local) => { - Self::remove_const(&mut self.ecx, local); - } - // We do not need to mark dead locals as such. For `FullConstProp` locals, - // this allows to propagate the single assigned value in this case: - // ``` - // let x = SOME_CONST; - // if a { - // f(copy x); - // StorageDead(x); - // } else { - // g(copy x); - // StorageDead(x); - // } - // ``` - // - // This may propagate a constant where the local would be uninit or dead. - // In both cases, this does not matter, as those reads would be UB anyway. - _ => {} - } - } - - fn visit_basic_block_data(&mut self, block: BasicBlock, data: &BasicBlockData<'tcx>) { - self.super_basic_block_data(block, data); - - // We remove all Locals which are restricted in propagation to their containing blocks and - // which were modified in the current block. - // Take it out of the ecx so we can get a mutable reference to the ecx for `remove_const`. - let mut written_only_inside_own_block_locals = - std::mem::take(&mut self.ecx.machine.written_only_inside_own_block_locals); - - // This loop can get very hot for some bodies: it check each local in each bb. - // To avoid this quadratic behaviour, we only clear the locals that were modified inside - // the current block. - for local in written_only_inside_own_block_locals.drain() { - debug_assert_eq!( - self.ecx.machine.can_const_prop[local], - ConstPropMode::OnlyInsideOwnBlock - ); - Self::remove_const(&mut self.ecx, local); - } - self.ecx.machine.written_only_inside_own_block_locals = - written_only_inside_own_block_locals; - - if cfg!(debug_assertions) { - for (local, &mode) in self.ecx.machine.can_const_prop.iter_enumerated() { - match mode { - ConstPropMode::FullConstProp => {} - ConstPropMode::NoPropagation | ConstPropMode::OnlyInsideOwnBlock => { - self.ensure_not_propagated(local); - } - } - } - } - } -} diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 86910a6a1196c..100cd23feefc6 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -553,7 +553,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { &separate_const_switch::SeparateConstSwitch, &gvn::GVN, &simplify::SimplifyLocals::AfterGVN, - &const_prop::ConstProp, &dataflow_const_prop::DataflowConstProp, // // Const-prop runs unconditionally, but doesn't mutate the MIR at mir-opt-level=0. diff --git a/tests/codegen/inherit_overflow.rs b/tests/codegen/inherit_overflow.rs index 39909d7abfd40..fa9ee0ae12a16 100644 --- a/tests/codegen/inherit_overflow.rs +++ b/tests/codegen/inherit_overflow.rs @@ -1,4 +1,4 @@ -// compile-flags: -Zmir-enable-passes=+Inline,+ConstProp --crate-type lib +// compile-flags: -Zmir-enable-passes=+Inline,+GVN --crate-type lib // revisions: ASSERT NOASSERT //[ASSERT] compile-flags: -Coverflow-checks=on //[NOASSERT] compile-flags: -Coverflow-checks=off diff --git a/tests/mir-opt/const_allocation.main.ConstProp.after.32bit.mir b/tests/mir-opt/const_allocation.main.GVN.after.32bit.mir similarity index 98% rename from tests/mir-opt/const_allocation.main.ConstProp.after.32bit.mir rename to tests/mir-opt/const_allocation.main.GVN.after.32bit.mir index 8c8e69595950d..629fe1dea9a3f 100644 --- a/tests/mir-opt/const_allocation.main.ConstProp.after.32bit.mir +++ b/tests/mir-opt/const_allocation.main.GVN.after.32bit.mir @@ -1,4 +1,4 @@ -// MIR for `main` after ConstProp +// MIR for `main` after GVN fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_allocation.main.ConstProp.after.64bit.mir b/tests/mir-opt/const_allocation.main.GVN.after.64bit.mir similarity index 98% rename from tests/mir-opt/const_allocation.main.ConstProp.after.64bit.mir rename to tests/mir-opt/const_allocation.main.GVN.after.64bit.mir index e22547032967f..8c58cd353b785 100644 --- a/tests/mir-opt/const_allocation.main.ConstProp.after.64bit.mir +++ b/tests/mir-opt/const_allocation.main.GVN.after.64bit.mir @@ -1,4 +1,4 @@ -// MIR for `main` after ConstProp +// MIR for `main` after GVN fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_allocation.rs b/tests/mir-opt/const_allocation.rs index 91a2455eb836a..05888d1d0c935 100644 --- a/tests/mir-opt/const_allocation.rs +++ b/tests/mir-opt/const_allocation.rs @@ -1,10 +1,10 @@ -// unit-test: ConstProp +// unit-test: GVN // ignore-endian-big // EMIT_MIR_FOR_EACH_BIT_WIDTH static FOO: &[(Option, &[&str])] = &[(None, &[]), (None, &["foo", "bar"]), (Some(42), &["meh", "mop", "möp"])]; -// EMIT_MIR const_allocation.main.ConstProp.after.mir +// EMIT_MIR const_allocation.main.GVN.after.mir fn main() { FOO; } diff --git a/tests/mir-opt/const_allocation2.main.ConstProp.after.32bit.mir b/tests/mir-opt/const_allocation2.main.GVN.after.32bit.mir similarity index 97% rename from tests/mir-opt/const_allocation2.main.ConstProp.after.32bit.mir rename to tests/mir-opt/const_allocation2.main.GVN.after.32bit.mir index c5f6902b4b48a..7118e911d4a24 100644 --- a/tests/mir-opt/const_allocation2.main.ConstProp.after.32bit.mir +++ b/tests/mir-opt/const_allocation2.main.GVN.after.32bit.mir @@ -1,4 +1,4 @@ -// MIR for `main` after ConstProp +// MIR for `main` after GVN fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_allocation2.main.ConstProp.after.64bit.mir b/tests/mir-opt/const_allocation2.main.GVN.after.64bit.mir similarity index 98% rename from tests/mir-opt/const_allocation2.main.ConstProp.after.64bit.mir rename to tests/mir-opt/const_allocation2.main.GVN.after.64bit.mir index b95b8c7874878..4f9bdbf492ad6 100644 --- a/tests/mir-opt/const_allocation2.main.ConstProp.after.64bit.mir +++ b/tests/mir-opt/const_allocation2.main.GVN.after.64bit.mir @@ -1,4 +1,4 @@ -// MIR for `main` after ConstProp +// MIR for `main` after GVN fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_allocation2.rs b/tests/mir-opt/const_allocation2.rs index f2870aa47c563..dd722a8173052 100644 --- a/tests/mir-opt/const_allocation2.rs +++ b/tests/mir-opt/const_allocation2.rs @@ -1,7 +1,7 @@ -// unit-test: ConstProp +// unit-test: GVN // ignore-endian-big // EMIT_MIR_FOR_EACH_BIT_WIDTH -// EMIT_MIR const_allocation2.main.ConstProp.after.mir +// EMIT_MIR const_allocation2.main.GVN.after.mir fn main() { FOO; } diff --git a/tests/mir-opt/const_allocation3.main.ConstProp.after.32bit.mir b/tests/mir-opt/const_allocation3.main.GVN.after.32bit.mir similarity index 98% rename from tests/mir-opt/const_allocation3.main.ConstProp.after.32bit.mir rename to tests/mir-opt/const_allocation3.main.GVN.after.32bit.mir index e172c7540014d..21f04c27ce498 100644 --- a/tests/mir-opt/const_allocation3.main.ConstProp.after.32bit.mir +++ b/tests/mir-opt/const_allocation3.main.GVN.after.32bit.mir @@ -1,4 +1,4 @@ -// MIR for `main` after ConstProp +// MIR for `main` after GVN fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_allocation3.main.ConstProp.after.64bit.mir b/tests/mir-opt/const_allocation3.main.GVN.after.64bit.mir similarity index 98% rename from tests/mir-opt/const_allocation3.main.ConstProp.after.64bit.mir rename to tests/mir-opt/const_allocation3.main.GVN.after.64bit.mir index d5feea723e7cd..c568e1077a4b5 100644 --- a/tests/mir-opt/const_allocation3.main.ConstProp.after.64bit.mir +++ b/tests/mir-opt/const_allocation3.main.GVN.after.64bit.mir @@ -1,4 +1,4 @@ -// MIR for `main` after ConstProp +// MIR for `main` after GVN fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_allocation3.rs b/tests/mir-opt/const_allocation3.rs index da3fd089b026b..264d865b83483 100644 --- a/tests/mir-opt/const_allocation3.rs +++ b/tests/mir-opt/const_allocation3.rs @@ -1,7 +1,7 @@ -// unit-test: ConstProp +// unit-test: GVN // ignore-endian-big // EMIT_MIR_FOR_EACH_BIT_WIDTH -// EMIT_MIR const_allocation3.main.ConstProp.after.mir +// EMIT_MIR const_allocation3.main.GVN.after.mir fn main() { FOO; } diff --git a/tests/mir-opt/const_prop/address_of_pair.fn0.ConstProp.diff b/tests/mir-opt/const_prop/address_of_pair.fn0.GVN.diff similarity index 67% rename from tests/mir-opt/const_prop/address_of_pair.fn0.ConstProp.diff rename to tests/mir-opt/const_prop/address_of_pair.fn0.GVN.diff index 6b96c24d46063..7092b25a76807 100644 --- a/tests/mir-opt/const_prop/address_of_pair.fn0.ConstProp.diff +++ b/tests/mir-opt/const_prop/address_of_pair.fn0.GVN.diff @@ -1,5 +1,5 @@ -- // MIR for `fn0` before ConstProp -+ // MIR for `fn0` after ConstProp +- // MIR for `fn0` before GVN ++ // MIR for `fn0` after GVN fn fn0() -> bool { let mut _0: bool; @@ -23,24 +23,32 @@ bb0: { StorageLive(_2); - _2 = (const 1_i32, const false); +- _2 = (const 1_i32, const false); ++ _2 = const (1_i32, false); StorageLive(_3); _3 = &raw mut (_2.1: bool); - _2 = (const 1_i32, const false); +- _2 = (const 1_i32, const false); ++ _2 = const (1_i32, false); StorageLive(_4); (*_3) = const true; _4 = const (); StorageDead(_4); - StorageLive(_5); +- StorageLive(_5); ++ nop; StorageLive(_6); _6 = (_2.1: bool); _5 = Not(move _6); StorageDead(_6); _0 = _5; - StorageDead(_5); +- StorageDead(_5); ++ nop; StorageDead(_3); StorageDead(_2); return; } ++ } ++ ++ alloc7 (size: 8, align: 4) { ++ 01 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/const_prop/address_of_pair.rs b/tests/mir-opt/const_prop/address_of_pair.rs index 43dc9bae62534..aa951fab18677 100644 --- a/tests/mir-opt/const_prop/address_of_pair.rs +++ b/tests/mir-opt/const_prop/address_of_pair.rs @@ -1,6 +1,6 @@ -// unit-test: ConstProp +// unit-test: GVN -// EMIT_MIR address_of_pair.fn0.ConstProp.diff +// EMIT_MIR address_of_pair.fn0.GVN.diff pub fn fn0() -> bool { let mut pair = (1, false); let ptr = core::ptr::addr_of_mut!(pair.1); diff --git a/tests/mir-opt/const_prop/aggregate.foo.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/aggregate.foo.GVN.panic-abort.diff similarity index 69% rename from tests/mir-opt/const_prop/aggregate.foo.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/aggregate.foo.GVN.panic-abort.diff index 5e2db148de83b..cd70ecc9a275c 100644 --- a/tests/mir-opt/const_prop/aggregate.foo.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/aggregate.foo.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `foo` before ConstProp -+ // MIR for `foo` after ConstProp +- // MIR for `foo` before GVN ++ // MIR for `foo` after GVN fn foo(_1: u8) -> () { debug x => _1; @@ -25,12 +25,11 @@ StorageLive(_4); StorageLive(_5); _5 = _1; - _4 = (const 0_i32, move _5); +- _4 = (const 0_i32, move _5); ++ _4 = (const 0_i32, _1); StorageDead(_5); -- _3 = (_4.0: i32); -- _2 = Add(move _3, const 1_i32); -+ _3 = const 0_i32; -+ _2 = const 1_i32; + _3 = (_4.0: i32); + _2 = Add(move _3, const 1_i32); StorageDead(_3); StorageDead(_4); StorageLive(_6); @@ -38,12 +37,11 @@ StorageLive(_8); StorageLive(_9); _9 = _1; - _8 = (move _9, const 1_i32); +- _8 = (move _9, const 1_i32); ++ _8 = (_1, const 1_i32); StorageDead(_9); -- _7 = (_8.1: i32); -- _6 = Add(move _7, const 2_i32); -+ _7 = const 1_i32; -+ _6 = const 3_i32; + _7 = (_8.1: i32); + _6 = Add(move _7, const 2_i32); StorageDead(_7); StorageDead(_8); _0 = const (); diff --git a/tests/mir-opt/const_prop/aggregate.foo.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/aggregate.foo.GVN.panic-unwind.diff similarity index 69% rename from tests/mir-opt/const_prop/aggregate.foo.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/aggregate.foo.GVN.panic-unwind.diff index 5e2db148de83b..cd70ecc9a275c 100644 --- a/tests/mir-opt/const_prop/aggregate.foo.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/aggregate.foo.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `foo` before ConstProp -+ // MIR for `foo` after ConstProp +- // MIR for `foo` before GVN ++ // MIR for `foo` after GVN fn foo(_1: u8) -> () { debug x => _1; @@ -25,12 +25,11 @@ StorageLive(_4); StorageLive(_5); _5 = _1; - _4 = (const 0_i32, move _5); +- _4 = (const 0_i32, move _5); ++ _4 = (const 0_i32, _1); StorageDead(_5); -- _3 = (_4.0: i32); -- _2 = Add(move _3, const 1_i32); -+ _3 = const 0_i32; -+ _2 = const 1_i32; + _3 = (_4.0: i32); + _2 = Add(move _3, const 1_i32); StorageDead(_3); StorageDead(_4); StorageLive(_6); @@ -38,12 +37,11 @@ StorageLive(_8); StorageLive(_9); _9 = _1; - _8 = (move _9, const 1_i32); +- _8 = (move _9, const 1_i32); ++ _8 = (_1, const 1_i32); StorageDead(_9); -- _7 = (_8.1: i32); -- _6 = Add(move _7, const 2_i32); -+ _7 = const 1_i32; -+ _6 = const 3_i32; + _7 = (_8.1: i32); + _6 = Add(move _7, const 2_i32); StorageDead(_7); StorageDead(_8); _0 = const (); diff --git a/tests/mir-opt/const_prop/aggregate.foo.PreCodegen.after.panic-abort.mir b/tests/mir-opt/const_prop/aggregate.foo.PreCodegen.after.panic-abort.mir index b9c5859cade4f..e1f4d781c459e 100644 --- a/tests/mir-opt/const_prop/aggregate.foo.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/const_prop/aggregate.foo.PreCodegen.after.panic-abort.mir @@ -24,10 +24,10 @@ fn foo(_1: u8) -> () { StorageLive(_4); StorageLive(_5); _5 = _1; - _4 = (const 0_i32, move _5); + _4 = (const 0_i32, _1); StorageDead(_5); - _3 = const 0_i32; - _2 = const 1_i32; + _3 = (_4.0: i32); + _2 = Add(move _3, const 1_i32); StorageDead(_3); StorageDead(_4); StorageLive(_6); @@ -35,10 +35,10 @@ fn foo(_1: u8) -> () { StorageLive(_8); StorageLive(_9); _9 = _1; - _8 = (move _9, const 1_i32); + _8 = (_1, const 1_i32); StorageDead(_9); - _7 = const 1_i32; - _6 = const 3_i32; + _7 = (_8.1: i32); + _6 = Add(move _7, const 2_i32); StorageDead(_7); StorageDead(_8); _0 = const (); diff --git a/tests/mir-opt/const_prop/aggregate.foo.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/const_prop/aggregate.foo.PreCodegen.after.panic-unwind.mir index b9c5859cade4f..e1f4d781c459e 100644 --- a/tests/mir-opt/const_prop/aggregate.foo.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/const_prop/aggregate.foo.PreCodegen.after.panic-unwind.mir @@ -24,10 +24,10 @@ fn foo(_1: u8) -> () { StorageLive(_4); StorageLive(_5); _5 = _1; - _4 = (const 0_i32, move _5); + _4 = (const 0_i32, _1); StorageDead(_5); - _3 = const 0_i32; - _2 = const 1_i32; + _3 = (_4.0: i32); + _2 = Add(move _3, const 1_i32); StorageDead(_3); StorageDead(_4); StorageLive(_6); @@ -35,10 +35,10 @@ fn foo(_1: u8) -> () { StorageLive(_8); StorageLive(_9); _9 = _1; - _8 = (move _9, const 1_i32); + _8 = (_1, const 1_i32); StorageDead(_9); - _7 = const 1_i32; - _6 = const 3_i32; + _7 = (_8.1: i32); + _6 = Add(move _7, const 2_i32); StorageDead(_7); StorageDead(_8); _0 = const (); diff --git a/tests/mir-opt/const_prop/aggregate.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/aggregate.main.GVN.panic-abort.diff similarity index 85% rename from tests/mir-opt/const_prop/aggregate.main.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/aggregate.main.GVN.panic-abort.diff index a4911a6d48ade..854e27445afb9 100644 --- a/tests/mir-opt/const_prop/aggregate.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/aggregate.main.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -13,7 +13,8 @@ } bb0: { - StorageLive(_1); +- StorageLive(_1); ++ nop; StorageLive(_2); StorageLive(_3); _3 = (const 0_i32, const 1_u8, const 2_i32); @@ -35,7 +36,8 @@ StorageDead(_5); StorageDead(_4); _0 = const (); - StorageDead(_1); +- StorageDead(_1); ++ nop; return; } } diff --git a/tests/mir-opt/const_prop/aggregate.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/aggregate.main.GVN.panic-unwind.diff similarity index 85% rename from tests/mir-opt/const_prop/aggregate.main.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/aggregate.main.GVN.panic-unwind.diff index b8b9fa5cc1c5c..f6c4b2c924097 100644 --- a/tests/mir-opt/const_prop/aggregate.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/aggregate.main.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -13,7 +13,8 @@ } bb0: { - StorageLive(_1); +- StorageLive(_1); ++ nop; StorageLive(_2); StorageLive(_3); _3 = (const 0_i32, const 1_u8, const 2_i32); @@ -35,7 +36,8 @@ StorageDead(_5); StorageDead(_4); _0 = const (); - StorageDead(_1); +- StorageDead(_1); ++ nop; return; } } diff --git a/tests/mir-opt/const_prop/aggregate.main.PreCodegen.after.panic-abort.mir b/tests/mir-opt/const_prop/aggregate.main.PreCodegen.after.panic-abort.mir index 44a85a5636b9c..687867737c8b3 100644 --- a/tests/mir-opt/const_prop/aggregate.main.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/const_prop/aggregate.main.PreCodegen.after.panic-abort.mir @@ -12,7 +12,7 @@ fn main() -> () { } bb0: { - StorageLive(_1); + nop; StorageLive(_2); StorageLive(_3); _3 = (const 0_i32, const 1_u8, const 2_i32); @@ -30,7 +30,7 @@ fn main() -> () { StorageDead(_5); StorageDead(_4); _0 = const (); - StorageDead(_1); + nop; return; } } diff --git a/tests/mir-opt/const_prop/aggregate.main.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/const_prop/aggregate.main.PreCodegen.after.panic-unwind.mir index 2c7bdbb5055bd..ce502379aa4b3 100644 --- a/tests/mir-opt/const_prop/aggregate.main.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/const_prop/aggregate.main.PreCodegen.after.panic-unwind.mir @@ -12,7 +12,7 @@ fn main() -> () { } bb0: { - StorageLive(_1); + nop; StorageLive(_2); StorageLive(_3); _3 = (const 0_i32, const 1_u8, const 2_i32); @@ -30,7 +30,7 @@ fn main() -> () { StorageDead(_5); StorageDead(_4); _0 = const (); - StorageDead(_1); + nop; return; } } diff --git a/tests/mir-opt/const_prop/aggregate.rs b/tests/mir-opt/const_prop/aggregate.rs index 62cd3dd688982..8ee16552cc244 100644 --- a/tests/mir-opt/const_prop/aggregate.rs +++ b/tests/mir-opt/const_prop/aggregate.rs @@ -1,15 +1,15 @@ // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// unit-test: ConstProp +// unit-test: GVN // compile-flags: -O -// EMIT_MIR aggregate.main.ConstProp.diff +// EMIT_MIR aggregate.main.GVN.diff // EMIT_MIR aggregate.main.PreCodegen.after.mir fn main() { let x = (0, 1, 2).1 + 0; foo(x); } -// EMIT_MIR aggregate.foo.ConstProp.diff +// EMIT_MIR aggregate.foo.GVN.diff // EMIT_MIR aggregate.foo.PreCodegen.after.mir fn foo(x: u8) { // Verify that we still propagate if part of the aggregate is not known. diff --git a/tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-abort.diff b/tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-abort.diff deleted file mode 100644 index b2f58f8f771d7..0000000000000 --- a/tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-abort.diff +++ /dev/null @@ -1,39 +0,0 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp - - fn main() -> () { - let mut _0: (); - let _1: u32; - let mut _2: [u32; 4]; - let _3: usize; - let mut _4: usize; - let mut _5: bool; - scope 1 { - debug x => _1; - } - - bb0: { - StorageLive(_1); - StorageLive(_2); - _2 = [const 0_u32, const 1_u32, const 2_u32, const 3_u32]; - StorageLive(_3); - _3 = const 2_usize; -- _4 = Len(_2); -- _5 = Lt(_3, _4); -- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind unreachable]; -+ _4 = const 4_usize; -+ _5 = const true; -+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 4_usize, const 2_usize) -> [success: bb1, unwind unreachable]; - } - - bb1: { -- _1 = _2[_3]; -+ _1 = const 2_u32; - StorageDead(_3); - StorageDead(_2); - _0 = const (); - StorageDead(_1); - return; - } - } - diff --git a/tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-abort.diff b/tests/mir-opt/const_prop/array_index.main.GVN.32bit.panic-abort.diff similarity index 88% rename from tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-abort.diff rename to tests/mir-opt/const_prop/array_index.main.GVN.32bit.panic-abort.diff index b2f58f8f771d7..7cd975711f22b 100644 --- a/tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/array_index.main.GVN.32bit.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -27,8 +27,7 @@ } bb1: { -- _1 = _2[_3]; -+ _1 = const 2_u32; + _1 = _2[_3]; StorageDead(_3); StorageDead(_2); _0 = const (); diff --git a/tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-unwind.diff b/tests/mir-opt/const_prop/array_index.main.GVN.32bit.panic-unwind.diff similarity index 88% rename from tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-unwind.diff rename to tests/mir-opt/const_prop/array_index.main.GVN.32bit.panic-unwind.diff index f9e3f8f171ad4..ec509b15c8b07 100644 --- a/tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/array_index.main.GVN.32bit.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -27,8 +27,7 @@ } bb1: { -- _1 = _2[_3]; -+ _1 = const 2_u32; + _1 = _2[_3]; StorageDead(_3); StorageDead(_2); _0 = const (); diff --git a/tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-unwind.diff b/tests/mir-opt/const_prop/array_index.main.GVN.64bit.panic-unwind.diff similarity index 88% rename from tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-unwind.diff rename to tests/mir-opt/const_prop/array_index.main.GVN.64bit.panic-unwind.diff index f9e3f8f171ad4..ec509b15c8b07 100644 --- a/tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/array_index.main.GVN.64bit.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -27,8 +27,7 @@ } bb1: { -- _1 = _2[_3]; -+ _1 = const 2_u32; + _1 = _2[_3]; StorageDead(_3); StorageDead(_2); _0 = const (); diff --git a/tests/mir-opt/const_prop/array_index.rs b/tests/mir-opt/const_prop/array_index.rs index f85d23b9789eb..9b0f17f72c6fb 100644 --- a/tests/mir-opt/const_prop/array_index.rs +++ b/tests/mir-opt/const_prop/array_index.rs @@ -1,8 +1,8 @@ // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// unit-test: ConstProp +// unit-test: GVN // EMIT_MIR_FOR_EACH_BIT_WIDTH -// EMIT_MIR array_index.main.ConstProp.diff +// EMIT_MIR array_index.main.GVN.diff fn main() { let x: u32 = [0, 1, 2, 3][2]; } diff --git a/tests/mir-opt/const_prop/bad_op_div_by_zero.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/bad_op_div_by_zero.main.GVN.panic-abort.diff similarity index 91% rename from tests/mir-opt/const_prop/bad_op_div_by_zero.main.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/bad_op_div_by_zero.main.GVN.panic-abort.diff index cead70110dcb8..4838efba6f9d1 100644 --- a/tests/mir-opt/const_prop/bad_op_div_by_zero.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/bad_op_div_by_zero.main.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -18,7 +18,8 @@ } bb0: { - StorageLive(_1); +- StorageLive(_1); ++ nop; _1 = const 0_i32; StorageLive(_2); StorageLive(_3); @@ -47,7 +48,8 @@ StorageDead(_3); _0 = const (); StorageDead(_2); - StorageDead(_1); +- StorageDead(_1); ++ nop; return; } } diff --git a/tests/mir-opt/const_prop/bad_op_div_by_zero.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/bad_op_div_by_zero.main.GVN.panic-unwind.diff similarity index 91% rename from tests/mir-opt/const_prop/bad_op_div_by_zero.main.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/bad_op_div_by_zero.main.GVN.panic-unwind.diff index c9c4ba8548c67..7f403d6efc103 100644 --- a/tests/mir-opt/const_prop/bad_op_div_by_zero.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/bad_op_div_by_zero.main.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -18,7 +18,8 @@ } bb0: { - StorageLive(_1); +- StorageLive(_1); ++ nop; _1 = const 0_i32; StorageLive(_2); StorageLive(_3); @@ -47,7 +48,8 @@ StorageDead(_3); _0 = const (); StorageDead(_2); - StorageDead(_1); +- StorageDead(_1); ++ nop; return; } } diff --git a/tests/mir-opt/const_prop/bad_op_div_by_zero.rs b/tests/mir-opt/const_prop/bad_op_div_by_zero.rs index 963084bf7e5bf..8ec59f83d1989 100644 --- a/tests/mir-opt/const_prop/bad_op_div_by_zero.rs +++ b/tests/mir-opt/const_prop/bad_op_div_by_zero.rs @@ -1,6 +1,6 @@ // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// unit-test: ConstProp -// EMIT_MIR bad_op_div_by_zero.main.ConstProp.diff +// unit-test: GVN +// EMIT_MIR bad_op_div_by_zero.main.GVN.diff #[allow(unconditional_panic)] fn main() { let y = 0; diff --git a/tests/mir-opt/const_prop/bad_op_mod_by_zero.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/bad_op_mod_by_zero.main.GVN.panic-abort.diff similarity index 91% rename from tests/mir-opt/const_prop/bad_op_mod_by_zero.main.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/bad_op_mod_by_zero.main.GVN.panic-abort.diff index 2666fd9eb91f6..59f2eb86f5095 100644 --- a/tests/mir-opt/const_prop/bad_op_mod_by_zero.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/bad_op_mod_by_zero.main.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -18,7 +18,8 @@ } bb0: { - StorageLive(_1); +- StorageLive(_1); ++ nop; _1 = const 0_i32; StorageLive(_2); StorageLive(_3); @@ -47,7 +48,8 @@ StorageDead(_3); _0 = const (); StorageDead(_2); - StorageDead(_1); +- StorageDead(_1); ++ nop; return; } } diff --git a/tests/mir-opt/const_prop/bad_op_mod_by_zero.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/bad_op_mod_by_zero.main.GVN.panic-unwind.diff similarity index 91% rename from tests/mir-opt/const_prop/bad_op_mod_by_zero.main.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/bad_op_mod_by_zero.main.GVN.panic-unwind.diff index 679df90f16fea..9b866082788cd 100644 --- a/tests/mir-opt/const_prop/bad_op_mod_by_zero.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/bad_op_mod_by_zero.main.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -18,7 +18,8 @@ } bb0: { - StorageLive(_1); +- StorageLive(_1); ++ nop; _1 = const 0_i32; StorageLive(_2); StorageLive(_3); @@ -47,7 +48,8 @@ StorageDead(_3); _0 = const (); StorageDead(_2); - StorageDead(_1); +- StorageDead(_1); ++ nop; return; } } diff --git a/tests/mir-opt/const_prop/bad_op_mod_by_zero.rs b/tests/mir-opt/const_prop/bad_op_mod_by_zero.rs index 9d7d2aa10443e..82ef8f9061c36 100644 --- a/tests/mir-opt/const_prop/bad_op_mod_by_zero.rs +++ b/tests/mir-opt/const_prop/bad_op_mod_by_zero.rs @@ -1,6 +1,6 @@ -// unit-test: ConstProp +// unit-test: GVN // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// EMIT_MIR bad_op_mod_by_zero.main.ConstProp.diff +// EMIT_MIR bad_op_mod_by_zero.main.GVN.diff #[allow(unconditional_panic)] fn main() { let y = 0; diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-abort.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-abort.diff deleted file mode 100644 index e443c8991f9a6..0000000000000 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-abort.diff +++ /dev/null @@ -1,54 +0,0 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp - - fn main() -> () { - let mut _0: (); - let _1: *const [i32]; - let mut _2: *const [i32; 3]; - let _3: &[i32; 3]; - let _4: [i32; 3]; - let _6: usize; - let mut _7: usize; - let mut _8: bool; - let mut _9: &[i32; 3]; - scope 1 { - debug a => _1; - scope 2 { - let _5: i32; - scope 3 { - debug _b => _5; - } - } - } - - bb0: { - StorageLive(_1); - StorageLive(_2); - StorageLive(_3); - _9 = const _; - _3 = &(*_9); - _2 = &raw const (*_3); - _1 = move _2 as *const [i32] (PointerCoercion(Unsize)); - StorageDead(_2); - StorageDead(_3); - StorageLive(_5); - StorageLive(_6); - _6 = const 3_usize; - _7 = Len((*_1)); -- _8 = Lt(_6, _7); -- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind unreachable]; -+ _8 = Lt(const 3_usize, _7); -+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 3_usize) -> [success: bb1, unwind unreachable]; - } - - bb1: { -- _5 = (*_1)[_6]; -+ _5 = (*_1)[3 of 4]; - StorageDead(_6); - _0 = const (); - StorageDead(_5); - StorageDead(_1); - return; - } - } - diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-abort.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-abort.diff similarity index 91% rename from tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-abort.diff rename to tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-abort.diff index e443c8991f9a6..7454ab25e3f13 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -42,8 +42,7 @@ } bb1: { -- _5 = (*_1)[_6]; -+ _5 = (*_1)[3 of 4]; + _5 = (*_1)[_6]; StorageDead(_6); _0 = const (); StorageDead(_5); diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-unwind.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-unwind.diff similarity index 91% rename from tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-unwind.diff rename to tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-unwind.diff index 592f43f473979..6ddaf91dcf1ce 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -42,8 +42,7 @@ } bb1: { -- _5 = (*_1)[_6]; -+ _5 = (*_1)[3 of 4]; + _5 = (*_1)[_6]; StorageDead(_6); _0 = const (); StorageDead(_5); diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-unwind.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-unwind.diff similarity index 91% rename from tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-unwind.diff rename to tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-unwind.diff index 592f43f473979..6ddaf91dcf1ce 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -42,8 +42,7 @@ } bb1: { -- _5 = (*_1)[_6]; -+ _5 = (*_1)[3 of 4]; + _5 = (*_1)[_6]; StorageDead(_6); _0 = const (); StorageDead(_5); diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.rs b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.rs index d6b1a93f30499..fe224c95cb905 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.rs +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.rs @@ -1,8 +1,8 @@ -// unit-test: ConstProp +// unit-test: GVN // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // EMIT_MIR_FOR_EACH_BIT_WIDTH -// EMIT_MIR bad_op_unsafe_oob_for_slices.main.ConstProp.diff +// EMIT_MIR bad_op_unsafe_oob_for_slices.main.GVN.diff #[allow(unconditional_panic)] fn main() { let a: *const [_] = &[1, 2, 3]; diff --git a/tests/mir-opt/const_prop/boolean_identities.rs b/tests/mir-opt/const_prop/boolean_identities.rs index c7b609949cd15..d50d6acb60725 100644 --- a/tests/mir-opt/const_prop/boolean_identities.rs +++ b/tests/mir-opt/const_prop/boolean_identities.rs @@ -1,7 +1,7 @@ -// unit-test: ConstProp +// unit-test: GVN // compile-flags: -O -Zmir-opt-level=4 -// EMIT_MIR boolean_identities.test.ConstProp.diff +// EMIT_MIR boolean_identities.test.GVN.diff pub fn test(x: bool, y: bool) -> bool { (y | true) & (x & false) } diff --git a/tests/mir-opt/const_prop/boolean_identities.test.ConstProp.diff b/tests/mir-opt/const_prop/boolean_identities.test.ConstProp.diff deleted file mode 100644 index 56f3e09e6b8dd..0000000000000 --- a/tests/mir-opt/const_prop/boolean_identities.test.ConstProp.diff +++ /dev/null @@ -1,25 +0,0 @@ -- // MIR for `test` before ConstProp -+ // MIR for `test` after ConstProp - - fn test(_1: bool, _2: bool) -> bool { - debug x => _1; - debug y => _2; - let mut _0: bool; - let mut _3: bool; - let mut _4: bool; - - bb0: { - StorageLive(_3); -- _3 = BitOr(_2, const true); -+ _3 = const true; - StorageLive(_4); -- _4 = BitAnd(_1, const false); -- _0 = BitAnd(move _3, move _4); -+ _4 = const false; -+ _0 = const false; - StorageDead(_4); - StorageDead(_3); - return; - } - } - diff --git a/tests/mir-opt/const_prop/boolean_identities.test.GVN.diff b/tests/mir-opt/const_prop/boolean_identities.test.GVN.diff new file mode 100644 index 0000000000000..750d76abfc517 --- /dev/null +++ b/tests/mir-opt/const_prop/boolean_identities.test.GVN.diff @@ -0,0 +1,24 @@ +- // MIR for `test` before GVN ++ // MIR for `test` after GVN + + fn test(_1: bool, _2: bool) -> bool { + debug x => _1; + debug y => _2; + let mut _0: bool; + let mut _3: bool; + let mut _4: bool; + let mut _5: bool; + let mut _6: bool; + + bb0: { + StorageLive(_3); + _3 = BitOr(_2, const true); + StorageLive(_5); + _5 = BitAnd(_1, const false); + _0 = BitAnd(move _3, move _5); + StorageDead(_5); + StorageDead(_3); + return; + } + } + diff --git a/tests/mir-opt/const_prop/boxes.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff similarity index 95% rename from tests/mir-opt/const_prop/boxes.main.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff index c9670a5ee4366..b3fdaa5ee8257 100644 --- a/tests/mir-opt/const_prop/boxes.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_prop/boxes.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/boxes.main.GVN.panic-unwind.diff similarity index 95% rename from tests/mir-opt/const_prop/boxes.main.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/boxes.main.GVN.panic-unwind.diff index 64fe72be5c89d..d0350c97253a2 100644 --- a/tests/mir-opt/const_prop/boxes.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/boxes.main.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_prop/boxes.rs b/tests/mir-opt/const_prop/boxes.rs index 78599174b423b..d9fdea2c8c141 100644 --- a/tests/mir-opt/const_prop/boxes.rs +++ b/tests/mir-opt/const_prop/boxes.rs @@ -1,4 +1,4 @@ -// unit-test: ConstProp +// unit-test: GVN // compile-flags: -O // EMIT_MIR_FOR_EACH_PANIC_STRATEGY @@ -6,7 +6,7 @@ // Note: this test verifies that we, in fact, do not const prop `#[rustc_box]` -// EMIT_MIR boxes.main.ConstProp.diff +// EMIT_MIR boxes.main.GVN.diff fn main() { let x = *(#[rustc_box] Box::new(42)) diff --git a/tests/mir-opt/const_prop/cast.main.ConstProp.diff b/tests/mir-opt/const_prop/cast.main.GVN.diff similarity index 87% rename from tests/mir-opt/const_prop/cast.main.ConstProp.diff rename to tests/mir-opt/const_prop/cast.main.GVN.diff index c63adcf1191e0..bc442c4e4468b 100644 --- a/tests/mir-opt/const_prop/cast.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/cast.main.GVN.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_prop/cast.rs b/tests/mir-opt/const_prop/cast.rs index 984086eda48b0..befb6a4faaf85 100644 --- a/tests/mir-opt/const_prop/cast.rs +++ b/tests/mir-opt/const_prop/cast.rs @@ -1,5 +1,5 @@ -// unit-test: ConstProp -// EMIT_MIR cast.main.ConstProp.diff +// unit-test: GVN +// EMIT_MIR cast.main.GVN.diff fn main() { let x = 42u8 as u32; diff --git a/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/checked_add.main.GVN.panic-abort.diff similarity index 88% rename from tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/checked_add.main.GVN.panic-abort.diff index c2fd7f65f5eea..1ab7e2c7d463a 100644 --- a/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/checked_add.main.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -26,7 +26,7 @@ } + } + -+ alloc3 (size: 8, align: 4) { ++ alloc2 (size: 8, align: 4) { + 02 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/checked_add.main.GVN.panic-unwind.diff similarity index 88% rename from tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/checked_add.main.GVN.panic-unwind.diff index 21a31f9aba31e..9bbb614e63d9e 100644 --- a/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/checked_add.main.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -26,7 +26,7 @@ } + } + -+ alloc3 (size: 8, align: 4) { ++ alloc2 (size: 8, align: 4) { + 02 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/const_prop/checked_add.rs b/tests/mir-opt/const_prop/checked_add.rs index fd40876cbc221..e04e8e2fb188e 100644 --- a/tests/mir-opt/const_prop/checked_add.rs +++ b/tests/mir-opt/const_prop/checked_add.rs @@ -1,8 +1,8 @@ // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// unit-test: ConstProp +// unit-test: GVN // compile-flags: -C overflow-checks=on -// EMIT_MIR checked_add.main.ConstProp.diff +// EMIT_MIR checked_add.main.GVN.diff fn main() { let x: u32 = 1 + 1; } diff --git a/tests/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/const_prop_fails_gracefully.main.GVN.panic-abort.diff similarity index 70% rename from tests/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/const_prop_fails_gracefully.main.GVN.panic-abort.diff index bd1de7476a2cc..4e79b3ad59921 100644 --- a/tests/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/const_prop_fails_gracefully.main.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -13,7 +13,8 @@ } bb0: { - StorageLive(_1); +- StorageLive(_1); ++ nop; StorageLive(_2); StorageLive(_3); _3 = const _; @@ -24,14 +25,16 @@ StorageLive(_4); StorageLive(_5); _5 = _1; - _4 = read(move _5) -> [return: bb1, unwind unreachable]; +- _4 = read(move _5) -> [return: bb1, unwind unreachable]; ++ _4 = read(_1) -> [return: bb1, unwind unreachable]; } bb1: { StorageDead(_5); StorageDead(_4); _0 = const (); - StorageDead(_1); +- StorageDead(_1); ++ nop; return; } } diff --git a/tests/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/const_prop_fails_gracefully.main.GVN.panic-unwind.diff similarity index 70% rename from tests/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/const_prop_fails_gracefully.main.GVN.panic-unwind.diff index 850b743feb1ca..fdc459b457ce0 100644 --- a/tests/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/const_prop_fails_gracefully.main.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -13,7 +13,8 @@ } bb0: { - StorageLive(_1); +- StorageLive(_1); ++ nop; StorageLive(_2); StorageLive(_3); _3 = const _; @@ -24,14 +25,16 @@ StorageLive(_4); StorageLive(_5); _5 = _1; - _4 = read(move _5) -> [return: bb1, unwind continue]; +- _4 = read(move _5) -> [return: bb1, unwind continue]; ++ _4 = read(_1) -> [return: bb1, unwind continue]; } bb1: { StorageDead(_5); StorageDead(_4); _0 = const (); - StorageDead(_1); +- StorageDead(_1); ++ nop; return; } } diff --git a/tests/mir-opt/const_prop/const_prop_fails_gracefully.rs b/tests/mir-opt/const_prop/const_prop_fails_gracefully.rs index c92831f926d3c..7190772e72b57 100644 --- a/tests/mir-opt/const_prop/const_prop_fails_gracefully.rs +++ b/tests/mir-opt/const_prop/const_prop_fails_gracefully.rs @@ -1,9 +1,9 @@ // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// unit-test: ConstProp +// unit-test: GVN #[inline(never)] fn read(_: usize) { } -// EMIT_MIR const_prop_fails_gracefully.main.ConstProp.diff +// EMIT_MIR const_prop_fails_gracefully.main.GVN.diff fn main() { const FOO: &i32 = &1; let x = FOO as *const i32 as usize; diff --git a/tests/mir-opt/const_prop/control_flow_simplification.hello.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/control_flow_simplification.hello.GVN.panic-abort.diff similarity index 66% rename from tests/mir-opt/const_prop/control_flow_simplification.hello.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/control_flow_simplification.hello.GVN.panic-abort.diff index ba2e89f0a7445..e9300f3a26c80 100644 --- a/tests/mir-opt/const_prop/control_flow_simplification.hello.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/control_flow_simplification.hello.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `hello` before ConstProp -+ // MIR for `hello` after ConstProp +- // MIR for `hello` before GVN ++ // MIR for `hello` after GVN fn hello() -> () { let mut _0: (); @@ -8,10 +8,9 @@ bb0: { StorageLive(_1); -- _1 = const _; + _1 = const _; - switchInt(move _1) -> [0: bb2, otherwise: bb1]; -+ _1 = const false; -+ switchInt(const false) -> [0: bb2, otherwise: bb1]; ++ switchInt(const _) -> [0: bb2, otherwise: bb1]; } bb1: { diff --git a/tests/mir-opt/const_prop/control_flow_simplification.hello.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/control_flow_simplification.hello.GVN.panic-unwind.diff similarity index 66% rename from tests/mir-opt/const_prop/control_flow_simplification.hello.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/control_flow_simplification.hello.GVN.panic-unwind.diff index e0a610f60a795..04866dd89fa82 100644 --- a/tests/mir-opt/const_prop/control_flow_simplification.hello.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/control_flow_simplification.hello.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `hello` before ConstProp -+ // MIR for `hello` after ConstProp +- // MIR for `hello` before GVN ++ // MIR for `hello` after GVN fn hello() -> () { let mut _0: (); @@ -8,10 +8,9 @@ bb0: { StorageLive(_1); -- _1 = const _; + _1 = const _; - switchInt(move _1) -> [0: bb2, otherwise: bb1]; -+ _1 = const false; -+ switchInt(const false) -> [0: bb2, otherwise: bb1]; ++ switchInt(const _) -> [0: bb2, otherwise: bb1]; } bb1: { diff --git a/tests/mir-opt/const_prop/control_flow_simplification.rs b/tests/mir-opt/const_prop/control_flow_simplification.rs index 21d727b3e50d9..2a3374ea03574 100644 --- a/tests/mir-opt/const_prop/control_flow_simplification.rs +++ b/tests/mir-opt/const_prop/control_flow_simplification.rs @@ -1,5 +1,5 @@ // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// unit-test: ConstProp +// unit-test: GVN // compile-flags: -Zmir-opt-level=1 trait NeedsDrop: Sized { @@ -8,7 +8,7 @@ trait NeedsDrop: Sized { impl NeedsDrop for This {} -// EMIT_MIR control_flow_simplification.hello.ConstProp.diff +// EMIT_MIR control_flow_simplification.hello.GVN.diff // EMIT_MIR control_flow_simplification.hello.PreCodegen.before.mir fn hello(){ if ::NEEDS { diff --git a/tests/mir-opt/const_prop/discriminant.main.ConstProp.32bit.diff b/tests/mir-opt/const_prop/discriminant.main.GVN.32bit.diff similarity index 93% rename from tests/mir-opt/const_prop/discriminant.main.ConstProp.32bit.diff rename to tests/mir-opt/const_prop/discriminant.main.GVN.32bit.diff index e02e7f320b865..70c3c3fe7e495 100644 --- a/tests/mir-opt/const_prop/discriminant.main.ConstProp.32bit.diff +++ b/tests/mir-opt/const_prop/discriminant.main.GVN.32bit.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff b/tests/mir-opt/const_prop/discriminant.main.GVN.64bit.diff similarity index 93% rename from tests/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff rename to tests/mir-opt/const_prop/discriminant.main.GVN.64bit.diff index e02e7f320b865..70c3c3fe7e495 100644 --- a/tests/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff +++ b/tests/mir-opt/const_prop/discriminant.main.GVN.64bit.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_prop/discriminant.rs b/tests/mir-opt/const_prop/discriminant.rs index fdd67ca8ac44f..d65ab358b72fb 100644 --- a/tests/mir-opt/const_prop/discriminant.rs +++ b/tests/mir-opt/const_prop/discriminant.rs @@ -1,4 +1,4 @@ -// unit-test: ConstProp +// unit-test: GVN // compile-flags: -O // FIXME(wesleywiser): Ideally, we could const-prop away all of this and just be left with @@ -7,7 +7,7 @@ // Fixing either of those will allow us to const-prop this away. // EMIT_MIR_FOR_EACH_BIT_WIDTH -// EMIT_MIR discriminant.main.ConstProp.diff +// EMIT_MIR discriminant.main.GVN.diff fn main() { let x = (if let Some(true) = Some(true) { 42 } else { 10 }) + 0; } diff --git a/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/indirect.main.GVN.panic-abort.diff similarity index 90% rename from tests/mir-opt/const_prop/indirect.main.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/indirect.main.GVN.panic-abort.diff index c0efc87302925..c1c035e4e87cf 100644 --- a/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/indirect.main.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -31,7 +31,7 @@ } + } + -+ alloc3 (size: 2, align: 1) { ++ alloc2 (size: 2, align: 1) { + 03 00 │ .. } diff --git a/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/indirect.main.GVN.panic-unwind.diff similarity index 90% rename from tests/mir-opt/const_prop/indirect.main.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/indirect.main.GVN.panic-unwind.diff index 2aee6f164aebb..39c86db10fae9 100644 --- a/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/indirect.main.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -31,7 +31,7 @@ } + } + -+ alloc3 (size: 2, align: 1) { ++ alloc2 (size: 2, align: 1) { + 03 00 │ .. } diff --git a/tests/mir-opt/const_prop/indirect.rs b/tests/mir-opt/const_prop/indirect.rs index 72af6cd95b8db..f85effcf06a6c 100644 --- a/tests/mir-opt/const_prop/indirect.rs +++ b/tests/mir-opt/const_prop/indirect.rs @@ -1,8 +1,8 @@ // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// unit-test: ConstProp +// unit-test: GVN // compile-flags: -C overflow-checks=on -// EMIT_MIR indirect.main.ConstProp.diff +// EMIT_MIR indirect.main.GVN.diff fn main() { let x = (2u32 as u8) + 1; } diff --git a/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/inherit_overflow.main.GVN.panic-abort.diff similarity index 91% rename from tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/inherit_overflow.main.GVN.panic-abort.diff index 7ba51ccdbf6d4..fb9d76dd896ba 100644 --- a/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/inherit_overflow.main.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -37,7 +37,7 @@ } + } + -+ alloc3 (size: 2, align: 1) { ++ alloc2 (size: 2, align: 1) { + 00 01 │ .. } diff --git a/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/inherit_overflow.main.GVN.panic-unwind.diff similarity index 91% rename from tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/inherit_overflow.main.GVN.panic-unwind.diff index 545b7f22f6e0c..348ce16d845a0 100644 --- a/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/inherit_overflow.main.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -37,7 +37,7 @@ } + } + -+ alloc3 (size: 2, align: 1) { ++ alloc2 (size: 2, align: 1) { + 00 01 │ .. } diff --git a/tests/mir-opt/const_prop/inherit_overflow.rs b/tests/mir-opt/const_prop/inherit_overflow.rs index 6ebd364121ab7..f26f9409e986a 100644 --- a/tests/mir-opt/const_prop/inherit_overflow.rs +++ b/tests/mir-opt/const_prop/inherit_overflow.rs @@ -1,8 +1,8 @@ // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// unit-test: ConstProp +// unit-test: GVN // compile-flags: -Zmir-enable-passes=+Inline -// EMIT_MIR inherit_overflow.main.ConstProp.diff +// EMIT_MIR inherit_overflow.main.GVN.diff fn main() { // After inlining, this will contain a `CheckedBinaryOp`. // Propagating the overflow is ok as codegen will just skip emitting the panic. diff --git a/tests/mir-opt/const_prop/invalid_constant.main.ConstProp.diff b/tests/mir-opt/const_prop/invalid_constant.main.GVN.diff similarity index 83% rename from tests/mir-opt/const_prop/invalid_constant.main.ConstProp.diff rename to tests/mir-opt/const_prop/invalid_constant.main.GVN.diff index 10e978a683acc..da5bf1cf42ca9 100644 --- a/tests/mir-opt/const_prop/invalid_constant.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/invalid_constant.main.GVN.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -35,17 +35,14 @@ StorageLive(_1); StorageLive(_2); _2 = InvalidChar { int: const 1114113_u32 }; -- _1 = (_2.1: char); -+ _1 = const {transmute(0x00110001): char}; + _1 = (_2.1: char); StorageDead(_2); StorageLive(_3); StorageLive(_4); StorageLive(_5); _5 = InvalidTag { int: const 4_u32 }; -- _4 = (_5.1: E); -- _3 = [move _4]; -+ _4 = const Scalar(0x00000004): E; -+ _3 = [const Scalar(0x00000004): E]; + _4 = (_5.1: E); + _3 = [move _4]; StorageDead(_4); StorageDead(_5); nop; diff --git a/tests/mir-opt/const_prop/invalid_constant.rs b/tests/mir-opt/const_prop/invalid_constant.rs index bdbc5a1990ea9..81d205fb8b9c2 100644 --- a/tests/mir-opt/const_prop/invalid_constant.rs +++ b/tests/mir-opt/const_prop/invalid_constant.rs @@ -1,4 +1,4 @@ -// unit-test: ConstProp +// unit-test: GVN // compile-flags: -Zmir-enable-passes=+RemoveZsts // Verify that we can pretty print invalid constants. @@ -14,7 +14,7 @@ enum E { A, B, C } enum Empty {} // EMIT_MIR invalid_constant.main.RemoveZsts.diff -// EMIT_MIR invalid_constant.main.ConstProp.diff +// EMIT_MIR invalid_constant.main.GVN.diff fn main() { // An invalid char. union InvalidChar { diff --git a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff deleted file mode 100644 index 9e17d72df29cd..0000000000000 --- a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff +++ /dev/null @@ -1,20 +0,0 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp - - fn main() -> () { - let mut _0: (); - let _1: (); - - bb0: { - _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind unreachable]; - } - - bb1: { - return; - } - } - - alloc5 (size: 2, align: 1) { - 00 00 │ .. - } - diff --git a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff deleted file mode 100644 index 2b507ec449dc3..0000000000000 --- a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff +++ /dev/null @@ -1,20 +0,0 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp - - fn main() -> () { - let mut _0: (); - let _1: (); - - bb0: { - _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind continue]; - } - - bb1: { - return; - } - } - - alloc5 (size: 2, align: 1) { - 00 00 │ .. - } - diff --git a/tests/mir-opt/const_prop/issue_66971.main.GVN.panic-abort.diff b/tests/mir-opt/const_prop/issue_66971.main.GVN.panic-abort.diff new file mode 100644 index 0000000000000..f19f88d1683ca --- /dev/null +++ b/tests/mir-opt/const_prop/issue_66971.main.GVN.panic-abort.diff @@ -0,0 +1,26 @@ +- // MIR for `main` before GVN ++ // MIR for `main` after GVN + + fn main() -> () { + let mut _0: (); + let _1: (); + let mut _2: ((), u8, u8); + + bb0: { + StorageLive(_2); +- _2 = (const (), const 0_u8, const 0_u8); +- _1 = encode(move _2) -> [return: bb1, unwind unreachable]; ++ _2 = const ((), 0_u8, 0_u8); ++ _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind unreachable]; + } + + bb1: { + StorageDead(_2); + return; + } ++ } ++ ++ alloc5 (size: 2, align: 1) { ++ 00 00 │ .. + } + diff --git a/tests/mir-opt/const_prop/issue_66971.main.GVN.panic-unwind.diff b/tests/mir-opt/const_prop/issue_66971.main.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..5fc12a82635e5 --- /dev/null +++ b/tests/mir-opt/const_prop/issue_66971.main.GVN.panic-unwind.diff @@ -0,0 +1,26 @@ +- // MIR for `main` before GVN ++ // MIR for `main` after GVN + + fn main() -> () { + let mut _0: (); + let _1: (); + let mut _2: ((), u8, u8); + + bb0: { + StorageLive(_2); +- _2 = (const (), const 0_u8, const 0_u8); +- _1 = encode(move _2) -> [return: bb1, unwind continue]; ++ _2 = const ((), 0_u8, 0_u8); ++ _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageDead(_2); + return; + } ++ } ++ ++ alloc5 (size: 2, align: 1) { ++ 00 00 │ .. + } + diff --git a/tests/mir-opt/const_prop/issue_66971.rs b/tests/mir-opt/const_prop/issue_66971.rs index a0242ec633f9e..030a0d09e0220 100644 --- a/tests/mir-opt/const_prop/issue_66971.rs +++ b/tests/mir-opt/const_prop/issue_66971.rs @@ -1,9 +1,9 @@ // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// unit-test: ConstProp +// unit-test: GVN // compile-flags: -Z mir-opt-level=3 // Due to a bug in propagating scalar pairs the assertion below used to fail. In the expected -// outputs below, after ConstProp this is how _2 would look like with the bug: +// outputs below, after GVN this is how _2 would look like with the bug: // // _2 = (const Scalar(0x00) : (), const 0u8); // @@ -13,7 +13,7 @@ fn encode(this: ((), u8, u8)) { assert!(this.2 == 0); } -// EMIT_MIR issue_66971.main.ConstProp.diff +// EMIT_MIR issue_66971.main.GVN.diff fn main() { encode(((), 0, 0)); } diff --git a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff deleted file mode 100644 index 90d431069bdb0..0000000000000 --- a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff +++ /dev/null @@ -1,20 +0,0 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp - - fn main() -> () { - let mut _0: (); - let _1: (); - - bb0: { - _1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind unreachable]; - } - - bb1: { - return; - } - } - - alloc7 (size: 2, align: 1) { - 01 02 │ .. - } - diff --git a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff deleted file mode 100644 index 5978061d96dc2..0000000000000 --- a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff +++ /dev/null @@ -1,20 +0,0 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp - - fn main() -> () { - let mut _0: (); - let _1: (); - - bb0: { - _1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind continue]; - } - - bb1: { - return; - } - } - - alloc7 (size: 2, align: 1) { - 01 02 │ .. - } - diff --git a/tests/mir-opt/const_prop/issue_67019.main.GVN.panic-abort.diff b/tests/mir-opt/const_prop/issue_67019.main.GVN.panic-abort.diff new file mode 100644 index 0000000000000..81ade771ac3b9 --- /dev/null +++ b/tests/mir-opt/const_prop/issue_67019.main.GVN.panic-abort.diff @@ -0,0 +1,39 @@ +- // MIR for `main` before GVN ++ // MIR for `main` after GVN + + fn main() -> () { + let mut _0: (); + let _1: (); + let mut _2: ((u8, u8),); + let mut _3: (u8, u8); + + bb0: { + StorageLive(_2); + StorageLive(_3); +- _3 = (const 1_u8, const 2_u8); +- _2 = (move _3,); ++ _3 = const (1_u8, 2_u8); ++ _2 = const ((1_u8, 2_u8),); + StorageDead(_3); +- _1 = test(move _2) -> [return: bb1, unwind unreachable]; ++ _1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind unreachable]; + } + + bb1: { + StorageDead(_2); + return; + } ++ } ++ ++ alloc8 (size: 2, align: 1) { ++ 01 02 │ .. ++ } ++ ++ alloc7 (size: 2, align: 1) { ++ 01 02 │ .. ++ } ++ ++ alloc6 (size: 2, align: 1) { ++ 01 02 │ .. + } + diff --git a/tests/mir-opt/const_prop/issue_67019.main.GVN.panic-unwind.diff b/tests/mir-opt/const_prop/issue_67019.main.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..1ac5f8dd34e4e --- /dev/null +++ b/tests/mir-opt/const_prop/issue_67019.main.GVN.panic-unwind.diff @@ -0,0 +1,39 @@ +- // MIR for `main` before GVN ++ // MIR for `main` after GVN + + fn main() -> () { + let mut _0: (); + let _1: (); + let mut _2: ((u8, u8),); + let mut _3: (u8, u8); + + bb0: { + StorageLive(_2); + StorageLive(_3); +- _3 = (const 1_u8, const 2_u8); +- _2 = (move _3,); ++ _3 = const (1_u8, 2_u8); ++ _2 = const ((1_u8, 2_u8),); + StorageDead(_3); +- _1 = test(move _2) -> [return: bb1, unwind continue]; ++ _1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageDead(_2); + return; + } ++ } ++ ++ alloc8 (size: 2, align: 1) { ++ 01 02 │ .. ++ } ++ ++ alloc7 (size: 2, align: 1) { ++ 01 02 │ .. ++ } ++ ++ alloc6 (size: 2, align: 1) { ++ 01 02 │ .. + } + diff --git a/tests/mir-opt/const_prop/issue_67019.rs b/tests/mir-opt/const_prop/issue_67019.rs index 66b577f5b5f80..a8ef6dfb0fff0 100644 --- a/tests/mir-opt/const_prop/issue_67019.rs +++ b/tests/mir-opt/const_prop/issue_67019.rs @@ -1,5 +1,5 @@ // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// unit-test: ConstProp +// unit-test: GVN // compile-flags: -Z mir-opt-level=3 // This used to ICE in const-prop @@ -8,7 +8,7 @@ fn test(this: ((u8, u8),)) { assert!((this.0).0 == 1); } -// EMIT_MIR issue_67019.main.ConstProp.diff +// EMIT_MIR issue_67019.main.GVN.diff fn main() { test(((1, 2),)); } diff --git a/tests/mir-opt/const_prop/large_array_index.main.ConstProp.64bit.panic-abort.diff b/tests/mir-opt/const_prop/large_array_index.main.ConstProp.64bit.panic-abort.diff deleted file mode 100644 index 20e2ee326986b..0000000000000 --- a/tests/mir-opt/const_prop/large_array_index.main.ConstProp.64bit.panic-abort.diff +++ /dev/null @@ -1,39 +0,0 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp - - fn main() -> () { - let mut _0: (); - let _1: u8; - let mut _2: [u8; 5000]; - let _3: usize; - let mut _4: usize; - let mut _5: bool; - scope 1 { - debug x => _1; - } - - bb0: { - StorageLive(_1); - StorageLive(_2); - _2 = [const 0_u8; 5000]; - StorageLive(_3); - _3 = const 2_usize; -- _4 = Len(_2); -- _5 = Lt(_3, _4); -- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind unreachable]; -+ _4 = const 5000_usize; -+ _5 = const true; -+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 5000_usize, const 2_usize) -> [success: bb1, unwind unreachable]; - } - - bb1: { -- _1 = _2[_3]; -+ _1 = _2[2 of 3]; - StorageDead(_3); - StorageDead(_2); - _0 = const (); - StorageDead(_1); - return; - } - } - diff --git a/tests/mir-opt/const_prop/large_array_index.main.ConstProp.32bit.panic-abort.diff b/tests/mir-opt/const_prop/large_array_index.main.GVN.32bit.panic-abort.diff similarity index 65% rename from tests/mir-opt/const_prop/large_array_index.main.ConstProp.32bit.panic-abort.diff rename to tests/mir-opt/const_prop/large_array_index.main.GVN.32bit.panic-abort.diff index 20e2ee326986b..056c6004075ae 100644 --- a/tests/mir-opt/const_prop/large_array_index.main.ConstProp.32bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/large_array_index.main.GVN.32bit.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -18,17 +18,15 @@ _2 = [const 0_u8; 5000]; StorageLive(_3); _3 = const 2_usize; -- _4 = Len(_2); + _4 = Len(_2); - _5 = Lt(_3, _4); - assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind unreachable]; -+ _4 = const 5000_usize; -+ _5 = const true; -+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 5000_usize, const 2_usize) -> [success: bb1, unwind unreachable]; ++ _5 = Lt(const 2_usize, _4); ++ assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, const 2_usize) -> [success: bb1, unwind unreachable]; } bb1: { -- _1 = _2[_3]; -+ _1 = _2[2 of 3]; + _1 = _2[_3]; StorageDead(_3); StorageDead(_2); _0 = const (); diff --git a/tests/mir-opt/const_prop/large_array_index.main.ConstProp.64bit.panic-unwind.diff b/tests/mir-opt/const_prop/large_array_index.main.GVN.32bit.panic-unwind.diff similarity index 65% rename from tests/mir-opt/const_prop/large_array_index.main.ConstProp.64bit.panic-unwind.diff rename to tests/mir-opt/const_prop/large_array_index.main.GVN.32bit.panic-unwind.diff index 1bdbbbf7863f9..a7a412ff042c6 100644 --- a/tests/mir-opt/const_prop/large_array_index.main.ConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/large_array_index.main.GVN.32bit.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -18,17 +18,15 @@ _2 = [const 0_u8; 5000]; StorageLive(_3); _3 = const 2_usize; -- _4 = Len(_2); + _4 = Len(_2); - _5 = Lt(_3, _4); - assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind continue]; -+ _4 = const 5000_usize; -+ _5 = const true; -+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 5000_usize, const 2_usize) -> [success: bb1, unwind continue]; ++ _5 = Lt(const 2_usize, _4); ++ assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, const 2_usize) -> [success: bb1, unwind continue]; } bb1: { -- _1 = _2[_3]; -+ _1 = _2[2 of 3]; + _1 = _2[_3]; StorageDead(_3); StorageDead(_2); _0 = const (); diff --git a/tests/mir-opt/const_prop/large_array_index.main.ConstProp.32bit.panic-unwind.diff b/tests/mir-opt/const_prop/large_array_index.main.GVN.64bit.panic-unwind.diff similarity index 65% rename from tests/mir-opt/const_prop/large_array_index.main.ConstProp.32bit.panic-unwind.diff rename to tests/mir-opt/const_prop/large_array_index.main.GVN.64bit.panic-unwind.diff index 1bdbbbf7863f9..a7a412ff042c6 100644 --- a/tests/mir-opt/const_prop/large_array_index.main.ConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/large_array_index.main.GVN.64bit.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -18,17 +18,15 @@ _2 = [const 0_u8; 5000]; StorageLive(_3); _3 = const 2_usize; -- _4 = Len(_2); + _4 = Len(_2); - _5 = Lt(_3, _4); - assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind continue]; -+ _4 = const 5000_usize; -+ _5 = const true; -+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 5000_usize, const 2_usize) -> [success: bb1, unwind continue]; ++ _5 = Lt(const 2_usize, _4); ++ assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, const 2_usize) -> [success: bb1, unwind continue]; } bb1: { -- _1 = _2[_3]; -+ _1 = _2[2 of 3]; + _1 = _2[_3]; StorageDead(_3); StorageDead(_2); _0 = const (); diff --git a/tests/mir-opt/const_prop/large_array_index.rs b/tests/mir-opt/const_prop/large_array_index.rs index d226bd5467165..ce6861e170208 100644 --- a/tests/mir-opt/const_prop/large_array_index.rs +++ b/tests/mir-opt/const_prop/large_array_index.rs @@ -1,8 +1,8 @@ -// unit-test: ConstProp +// unit-test: GVN // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // EMIT_MIR_FOR_EACH_BIT_WIDTH -// EMIT_MIR large_array_index.main.ConstProp.diff +// EMIT_MIR large_array_index.main.GVN.diff fn main() { // check that we don't propagate this, because it's too large let x: u8 = [0_u8; 5000][2]; diff --git a/tests/mir-opt/const_prop/mult_by_zero.rs b/tests/mir-opt/const_prop/mult_by_zero.rs index 7bd30975a738c..cf0bc1dae2840 100644 --- a/tests/mir-opt/const_prop/mult_by_zero.rs +++ b/tests/mir-opt/const_prop/mult_by_zero.rs @@ -1,6 +1,6 @@ -// unit-test: ConstProp +// unit-test: GVN -// EMIT_MIR mult_by_zero.test.ConstProp.diff +// EMIT_MIR mult_by_zero.test.GVN.diff fn test(x : i32) -> i32 { x * 0 } diff --git a/tests/mir-opt/const_prop/mult_by_zero.test.ConstProp.diff b/tests/mir-opt/const_prop/mult_by_zero.test.GVN.diff similarity index 72% rename from tests/mir-opt/const_prop/mult_by_zero.test.ConstProp.diff rename to tests/mir-opt/const_prop/mult_by_zero.test.GVN.diff index 73b1da064237a..e9fb34749c104 100644 --- a/tests/mir-opt/const_prop/mult_by_zero.test.ConstProp.diff +++ b/tests/mir-opt/const_prop/mult_by_zero.test.GVN.diff @@ -1,5 +1,5 @@ -- // MIR for `test` before ConstProp -+ // MIR for `test` after ConstProp +- // MIR for `test` before GVN ++ // MIR for `test` after GVN fn test(_1: i32) -> i32 { debug x => _1; @@ -10,7 +10,7 @@ StorageLive(_2); _2 = _1; - _0 = Mul(move _2, const 0_i32); -+ _0 = const 0_i32; ++ _0 = Mul(_1, const 0_i32); StorageDead(_2); return; } diff --git a/tests/mir-opt/const_prop/mutable_variable.main.ConstProp.diff b/tests/mir-opt/const_prop/mutable_variable.main.GVN.diff similarity index 78% rename from tests/mir-opt/const_prop/mutable_variable.main.ConstProp.diff rename to tests/mir-opt/const_prop/mutable_variable.main.GVN.diff index ad8d9ddb0743f..11464e3240028 100644 --- a/tests/mir-opt/const_prop/mutable_variable.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/mutable_variable.main.GVN.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -17,8 +17,7 @@ _1 = const 42_i32; _1 = const 99_i32; StorageLive(_2); -- _2 = _1; -+ _2 = const 99_i32; + _2 = _1; _0 = const (); StorageDead(_2); StorageDead(_1); diff --git a/tests/mir-opt/const_prop/mutable_variable.rs b/tests/mir-opt/const_prop/mutable_variable.rs index 95987ef7fa9fa..22f2725085935 100644 --- a/tests/mir-opt/const_prop/mutable_variable.rs +++ b/tests/mir-opt/const_prop/mutable_variable.rs @@ -1,6 +1,6 @@ -// unit-test: ConstProp +// unit-test: GVN -// EMIT_MIR mutable_variable.main.ConstProp.diff +// EMIT_MIR mutable_variable.main.GVN.diff fn main() { let mut x = 42; x = 99; diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate.main.ConstProp.diff b/tests/mir-opt/const_prop/mutable_variable_aggregate.main.GVN.diff similarity index 68% rename from tests/mir-opt/const_prop/mutable_variable_aggregate.main.ConstProp.diff rename to tests/mir-opt/const_prop/mutable_variable_aggregate.main.GVN.diff index 56a127ae31ebe..2f6c301810122 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate.main.GVN.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -18,8 +18,7 @@ + _1 = const (42_i32, 43_i32); (_1.1: i32) = const 99_i32; StorageLive(_2); -- _2 = _1; -+ _2 = const (42_i32, 99_i32); + _2 = _1; _0 = const (); StorageDead(_2); StorageDead(_1); @@ -27,11 +26,7 @@ } + } + -+ alloc7 (size: 8, align: 4) { -+ 2a 00 00 00 63 00 00 00 │ *...c... -+ } -+ -+ alloc5 (size: 8, align: 4) { ++ alloc3 (size: 8, align: 4) { + 2a 00 00 00 2b 00 00 00 │ *...+... } diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate.rs b/tests/mir-opt/const_prop/mutable_variable_aggregate.rs index a145c0354380c..69d16983909d9 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate.rs +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate.rs @@ -1,6 +1,6 @@ -// unit-test: ConstProp +// unit-test: GVN -// EMIT_MIR mutable_variable_aggregate.main.ConstProp.diff +// EMIT_MIR mutable_variable_aggregate.main.GVN.diff fn main() { let mut x = (42, 43); x.1 = 99; diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.main.ConstProp.diff b/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.main.GVN.diff similarity index 72% rename from tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.main.ConstProp.diff rename to tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.main.GVN.diff index 106e27f8f2768..b20d0b5b3c968 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.main.GVN.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -18,7 +18,8 @@ bb0: { StorageLive(_1); - _1 = (const 42_i32, const 43_i32); +- _1 = (const 42_i32, const 43_i32); ++ _1 = const (42_i32, 43_i32); StorageLive(_2); _2 = &mut _1; ((*_2).1: i32) = const 99_i32; @@ -30,5 +31,9 @@ StorageDead(_1); return; } ++ } ++ ++ alloc2 (size: 8, align: 4) { ++ 2a 00 00 00 2b 00 00 00 │ *...+... } diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.rs b/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.rs index 3099e659f3fbb..cef82dcc028f0 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.rs +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.rs @@ -1,6 +1,6 @@ -// unit-test: ConstProp +// unit-test: GVN -// EMIT_MIR mutable_variable_aggregate_mut_ref.main.ConstProp.diff +// EMIT_MIR mutable_variable_aggregate_mut_ref.main.GVN.diff fn main() { let mut x = (42, 43); let z = &mut x; diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.GVN.panic-abort.diff similarity index 80% rename from tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.GVN.panic-abort.diff index 34288c62fee12..6480e480f8c58 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -21,8 +21,7 @@ (_1.1: i32) = const 99_i32; (_1.0: i32) = const 42_i32; StorageLive(_2); -- _2 = (_1.1: i32); -+ _2 = const 99_i32; + _2 = (_1.1: i32); _0 = const (); StorageDead(_2); StorageDead(_1); diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.GVN.panic-unwind.diff similarity index 80% rename from tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.GVN.panic-unwind.diff index 7ba2b483dc3fb..fb757801082ee 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -21,8 +21,7 @@ (_1.1: i32) = const 99_i32; (_1.0: i32) = const 42_i32; StorageLive(_2); -- _2 = (_1.1: i32); -+ _2 = const 99_i32; + _2 = (_1.1: i32); _0 = const (); StorageDead(_2); StorageDead(_1); diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.rs b/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.rs index 30ea5714ae49a..7043d61c0c834 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.rs +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.rs @@ -1,7 +1,7 @@ // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// unit-test: ConstProp +// unit-test: GVN -// EMIT_MIR mutable_variable_aggregate_partial_read.main.ConstProp.diff +// EMIT_MIR mutable_variable_aggregate_partial_read.main.GVN.diff fn main() { let mut x: (i32, i32) = foo(); x.1 = 99; diff --git a/tests/mir-opt/const_prop/mutable_variable_no_prop.main.ConstProp.diff b/tests/mir-opt/const_prop/mutable_variable_no_prop.main.GVN.diff similarity index 92% rename from tests/mir-opt/const_prop/mutable_variable_no_prop.main.ConstProp.diff rename to tests/mir-opt/const_prop/mutable_variable_no_prop.main.GVN.diff index ac26f8ef4aeff..32331744c9c17 100644 --- a/tests/mir-opt/const_prop/mutable_variable_no_prop.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/mutable_variable_no_prop.main.GVN.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_prop/mutable_variable_no_prop.rs b/tests/mir-opt/const_prop/mutable_variable_no_prop.rs index e51c6223555d5..73ba2c649f88b 100644 --- a/tests/mir-opt/const_prop/mutable_variable_no_prop.rs +++ b/tests/mir-opt/const_prop/mutable_variable_no_prop.rs @@ -1,8 +1,8 @@ -// unit-test: ConstProp +// unit-test: GVN static mut STATIC: u32 = 0x42424242; -// EMIT_MIR mutable_variable_no_prop.main.ConstProp.diff +// EMIT_MIR mutable_variable_no_prop.main.GVN.diff fn main() { let mut x = 42; unsafe { diff --git a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-abort.diff similarity index 87% rename from tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-abort.diff index a1b433716c846..79f1b11ddd2c4 100644 --- a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -37,8 +37,7 @@ StorageLive(_4); _4 = (_2.1: i32); StorageLive(_5); -- _5 = (_2.0: i32); -+ _5 = const 1_i32; + _5 = (_2.0: i32); _0 = const (); StorageDead(_5); StorageDead(_4); @@ -48,7 +47,7 @@ } + } + -+ alloc7 (size: 8, align: 4) { ++ alloc5 (size: 8, align: 4) { + 01 00 00 00 02 00 00 00 │ ........ } diff --git a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-unwind.diff similarity index 87% rename from tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-unwind.diff index 2dc514194bc11..3a14c4597f3e0 100644 --- a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -37,8 +37,7 @@ StorageLive(_4); _4 = (_2.1: i32); StorageLive(_5); -- _5 = (_2.0: i32); -+ _5 = const 1_i32; + _5 = (_2.0: i32); _0 = const (); StorageDead(_5); StorageDead(_4); @@ -48,7 +47,7 @@ } + } + -+ alloc7 (size: 8, align: 4) { ++ alloc5 (size: 8, align: 4) { + 01 00 00 00 02 00 00 00 │ ........ } diff --git a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs index 4e7c0597a29f3..396e149fc524d 100644 --- a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs +++ b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs @@ -1,7 +1,7 @@ // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// unit-test: ConstProp +// unit-test: GVN -// EMIT_MIR mutable_variable_unprop_assign.main.ConstProp.diff +// EMIT_MIR mutable_variable_unprop_assign.main.GVN.diff fn main() { let a = foo(); let mut x: (i32, i32) = (1, 2); diff --git a/tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/offset_of.concrete.GVN.panic-abort.diff similarity index 96% rename from tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/offset_of.concrete.GVN.panic-abort.diff index c73d217aeec4e..1612f4f5e795f 100644 --- a/tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/offset_of.concrete.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `concrete` before ConstProp -+ // MIR for `concrete` after ConstProp +- // MIR for `concrete` before GVN ++ // MIR for `concrete` after GVN fn concrete() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/offset_of.concrete.GVN.panic-unwind.diff similarity index 96% rename from tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/offset_of.concrete.GVN.panic-unwind.diff index 913ffca4ae904..41e4fb649c62e 100644 --- a/tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/offset_of.concrete.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `concrete` before ConstProp -+ // MIR for `concrete` after ConstProp +- // MIR for `concrete` before GVN ++ // MIR for `concrete` after GVN fn concrete() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/offset_of.generic.GVN.panic-abort.diff similarity index 73% rename from tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/offset_of.generic.GVN.panic-abort.diff index 7519331f6d7d4..2f96f9a176a57 100644 --- a/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/offset_of.generic.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `generic` before ConstProp -+ // MIR for `generic` after ConstProp +- // MIR for `generic` before GVN ++ // MIR for `generic` after GVN fn generic() -> () { let mut _0: (); @@ -43,16 +43,20 @@ StorageDead(_4); StorageLive(_5); StorageLive(_6); - _6 = OffsetOf(Delta, [1]); - _5 = must_use::(move _6) -> [return: bb3, unwind unreachable]; +- _6 = OffsetOf(Delta, [1]); +- _5 = must_use::(move _6) -> [return: bb3, unwind unreachable]; ++ _6 = const 0_usize; ++ _5 = must_use::(const 0_usize) -> [return: bb3, unwind unreachable]; } bb3: { StorageDead(_6); StorageLive(_7); StorageLive(_8); - _8 = OffsetOf(Delta, [2]); - _7 = must_use::(move _8) -> [return: bb4, unwind unreachable]; +- _8 = OffsetOf(Delta, [2]); +- _7 = must_use::(move _8) -> [return: bb4, unwind unreachable]; ++ _8 = const 2_usize; ++ _7 = must_use::(const 2_usize) -> [return: bb4, unwind unreachable]; } bb4: { diff --git a/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/offset_of.generic.GVN.panic-unwind.diff similarity index 73% rename from tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/offset_of.generic.GVN.panic-unwind.diff index fd5206e460c6d..b24bb1add2fa2 100644 --- a/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/offset_of.generic.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `generic` before ConstProp -+ // MIR for `generic` after ConstProp +- // MIR for `generic` before GVN ++ // MIR for `generic` after GVN fn generic() -> () { let mut _0: (); @@ -43,16 +43,20 @@ StorageDead(_4); StorageLive(_5); StorageLive(_6); - _6 = OffsetOf(Delta, [1]); - _5 = must_use::(move _6) -> [return: bb3, unwind continue]; +- _6 = OffsetOf(Delta, [1]); +- _5 = must_use::(move _6) -> [return: bb3, unwind continue]; ++ _6 = const 0_usize; ++ _5 = must_use::(const 0_usize) -> [return: bb3, unwind continue]; } bb3: { StorageDead(_6); StorageLive(_7); StorageLive(_8); - _8 = OffsetOf(Delta, [2]); - _7 = must_use::(move _8) -> [return: bb4, unwind continue]; +- _8 = OffsetOf(Delta, [2]); +- _7 = must_use::(move _8) -> [return: bb4, unwind continue]; ++ _8 = const 2_usize; ++ _7 = must_use::(const 2_usize) -> [return: bb4, unwind continue]; } bb4: { diff --git a/tests/mir-opt/const_prop/offset_of.rs b/tests/mir-opt/const_prop/offset_of.rs index 164db59572b29..aead41048a198 100644 --- a/tests/mir-opt/const_prop/offset_of.rs +++ b/tests/mir-opt/const_prop/offset_of.rs @@ -1,4 +1,4 @@ -// unit-test: ConstProp +// unit-test: GVN // EMIT_MIR_FOR_EACH_PANIC_STRATEGY #![feature(offset_of)] @@ -27,7 +27,7 @@ struct Delta { y: u16, } -// EMIT_MIR offset_of.concrete.ConstProp.diff +// EMIT_MIR offset_of.concrete.GVN.diff fn concrete() { let x = offset_of!(Alpha, x); let y = offset_of!(Alpha, y); @@ -35,7 +35,7 @@ fn concrete() { let z1 = offset_of!(Alpha, z.1); } -// EMIT_MIR offset_of.generic.ConstProp.diff +// EMIT_MIR offset_of.generic.GVN.diff fn generic() { let gx = offset_of!(Gamma, x); let gy = offset_of!(Gamma, y); diff --git a/tests/mir-opt/const_prop/read_immutable_static.main.ConstProp.diff b/tests/mir-opt/const_prop/read_immutable_static.main.GVN.diff similarity index 85% rename from tests/mir-opt/const_prop/read_immutable_static.main.ConstProp.diff rename to tests/mir-opt/const_prop/read_immutable_static.main.GVN.diff index 29c455f35b35a..602b99ef3987d 100644 --- a/tests/mir-opt/const_prop/read_immutable_static.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/read_immutable_static.main.GVN.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -14,7 +14,8 @@ bb0: { StorageLive(_1); - StorageLive(_2); +- StorageLive(_2); ++ nop; StorageLive(_3); _3 = const {alloc1: &u8}; - _2 = (*_3); @@ -27,7 +28,8 @@ + _4 = const 2_u8; + _1 = const 4_u8; StorageDead(_4); - StorageDead(_2); +- StorageDead(_2); ++ nop; StorageDead(_5); StorageDead(_3); _0 = const (); diff --git a/tests/mir-opt/const_prop/read_immutable_static.rs b/tests/mir-opt/const_prop/read_immutable_static.rs index fb8f9fe996a6d..453ac8e644d5b 100644 --- a/tests/mir-opt/const_prop/read_immutable_static.rs +++ b/tests/mir-opt/const_prop/read_immutable_static.rs @@ -1,8 +1,8 @@ -// unit-test: ConstProp +// unit-test: GVN static FOO: u8 = 2; -// EMIT_MIR read_immutable_static.main.ConstProp.diff +// EMIT_MIR read_immutable_static.main.GVN.diff fn main() { let x = FOO + FOO; } diff --git a/tests/mir-opt/const_prop/ref_deref.main.ConstProp.diff b/tests/mir-opt/const_prop/ref_deref.main.GVN.diff similarity index 76% rename from tests/mir-opt/const_prop/ref_deref.main.ConstProp.diff rename to tests/mir-opt/const_prop/ref_deref.main.GVN.diff index 6b897a88181b8..621fd1a65dec5 100644 --- a/tests/mir-opt/const_prop/ref_deref.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/ref_deref.main.GVN.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -13,7 +13,8 @@ StorageLive(_2); _4 = const _; _2 = &(*_4); - _1 = (*_2); +- _1 = (*_2); ++ _1 = const 4_i32; StorageDead(_2); StorageDead(_1); _0 = const (); diff --git a/tests/mir-opt/const_prop/ref_deref.rs b/tests/mir-opt/const_prop/ref_deref.rs index 76e56916af09a..f3c997d57f470 100644 --- a/tests/mir-opt/const_prop/ref_deref.rs +++ b/tests/mir-opt/const_prop/ref_deref.rs @@ -1,5 +1,5 @@ -// unit-test: ConstProp -// EMIT_MIR ref_deref.main.ConstProp.diff +// unit-test: GVN +// EMIT_MIR ref_deref.main.GVN.diff fn main() { *(&4); diff --git a/tests/mir-opt/const_prop/ref_deref_project.main.ConstProp.diff b/tests/mir-opt/const_prop/ref_deref_project.main.GVN.diff similarity index 77% rename from tests/mir-opt/const_prop/ref_deref_project.main.ConstProp.diff rename to tests/mir-opt/const_prop/ref_deref_project.main.GVN.diff index 7f616166573cd..2292d36e5d8ab 100644 --- a/tests/mir-opt/const_prop/ref_deref_project.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/ref_deref_project.main.GVN.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -13,7 +13,8 @@ StorageLive(_2); _4 = const _; _2 = &((*_4).1: i32); - _1 = (*_2); +- _1 = (*_2); ++ _1 = const 5_i32; StorageDead(_2); StorageDead(_1); _0 = const (); diff --git a/tests/mir-opt/const_prop/ref_deref_project.rs b/tests/mir-opt/const_prop/ref_deref_project.rs index 04fc7f8daa124..96aa8e6405f4a 100644 --- a/tests/mir-opt/const_prop/ref_deref_project.rs +++ b/tests/mir-opt/const_prop/ref_deref_project.rs @@ -1,5 +1,5 @@ -// unit-test: ConstProp -// EMIT_MIR ref_deref_project.main.ConstProp.diff +// unit-test: GVN +// EMIT_MIR ref_deref_project.main.GVN.diff fn main() { *(&(4, 5).1); // This does not currently propagate (#67862) diff --git a/tests/mir-opt/const_prop/reify_fn_ptr.main.ConstProp.diff b/tests/mir-opt/const_prop/reify_fn_ptr.main.GVN.diff similarity index 88% rename from tests/mir-opt/const_prop/reify_fn_ptr.main.ConstProp.diff rename to tests/mir-opt/const_prop/reify_fn_ptr.main.GVN.diff index e7aa015d078ec..cde0cb32f7563 100644 --- a/tests/mir-opt/const_prop/reify_fn_ptr.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/reify_fn_ptr.main.GVN.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_prop/reify_fn_ptr.rs b/tests/mir-opt/const_prop/reify_fn_ptr.rs index 5f63820669b30..d13523b157661 100644 --- a/tests/mir-opt/const_prop/reify_fn_ptr.rs +++ b/tests/mir-opt/const_prop/reify_fn_ptr.rs @@ -1,5 +1,5 @@ -// unit-test: ConstProp -// EMIT_MIR reify_fn_ptr.main.ConstProp.diff +// unit-test: GVN +// EMIT_MIR reify_fn_ptr.main.GVN.diff fn main() { let _ = main as usize as *const fn(); diff --git a/tests/mir-opt/const_prop/repeat.main.ConstProp.32bit.panic-abort.diff b/tests/mir-opt/const_prop/repeat.main.ConstProp.32bit.panic-abort.diff deleted file mode 100644 index a55bd029e99ab..0000000000000 --- a/tests/mir-opt/const_prop/repeat.main.ConstProp.32bit.panic-abort.diff +++ /dev/null @@ -1,44 +0,0 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp - - fn main() -> () { - let mut _0: (); - let _1: u32; - let mut _2: u32; - let mut _3: [u32; 8]; - let _4: usize; - let mut _5: usize; - let mut _6: bool; - scope 1 { - debug x => _1; - } - - bb0: { - StorageLive(_1); - StorageLive(_2); - StorageLive(_3); - _3 = [const 42_u32; 8]; - StorageLive(_4); - _4 = const 2_usize; -- _5 = Len(_3); -- _6 = Lt(_4, _5); -- assert(move _6, "index out of bounds: the length is {} but the index is {}", move _5, _4) -> [success: bb1, unwind unreachable]; -+ _5 = const 8_usize; -+ _6 = const true; -+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 8_usize, const 2_usize) -> [success: bb1, unwind unreachable]; - } - - bb1: { -- _2 = _3[_4]; -- _1 = Add(move _2, const 0_u32); -+ _2 = const 42_u32; -+ _1 = const 42_u32; - StorageDead(_2); - StorageDead(_4); - StorageDead(_3); - _0 = const (); - StorageDead(_1); - return; - } - } - diff --git a/tests/mir-opt/const_prop/repeat.main.ConstProp.64bit.panic-abort.diff b/tests/mir-opt/const_prop/repeat.main.GVN.32bit.panic-abort.diff similarity index 64% rename from tests/mir-opt/const_prop/repeat.main.ConstProp.64bit.panic-abort.diff rename to tests/mir-opt/const_prop/repeat.main.GVN.32bit.panic-abort.diff index a55bd029e99ab..f610ca68f0d0e 100644 --- a/tests/mir-opt/const_prop/repeat.main.ConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/repeat.main.GVN.32bit.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -20,19 +20,16 @@ _3 = [const 42_u32; 8]; StorageLive(_4); _4 = const 2_usize; -- _5 = Len(_3); + _5 = Len(_3); - _6 = Lt(_4, _5); - assert(move _6, "index out of bounds: the length is {} but the index is {}", move _5, _4) -> [success: bb1, unwind unreachable]; -+ _5 = const 8_usize; -+ _6 = const true; -+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 8_usize, const 2_usize) -> [success: bb1, unwind unreachable]; ++ _6 = Lt(const 2_usize, _5); ++ assert(move _6, "index out of bounds: the length is {} but the index is {}", move _5, const 2_usize) -> [success: bb1, unwind unreachable]; } bb1: { -- _2 = _3[_4]; -- _1 = Add(move _2, const 0_u32); -+ _2 = const 42_u32; -+ _1 = const 42_u32; + _2 = _3[_4]; + _1 = Add(move _2, const 0_u32); StorageDead(_2); StorageDead(_4); StorageDead(_3); diff --git a/tests/mir-opt/const_prop/repeat.main.ConstProp.64bit.panic-unwind.diff b/tests/mir-opt/const_prop/repeat.main.GVN.32bit.panic-unwind.diff similarity index 64% rename from tests/mir-opt/const_prop/repeat.main.ConstProp.64bit.panic-unwind.diff rename to tests/mir-opt/const_prop/repeat.main.GVN.32bit.panic-unwind.diff index d49ef2e0179f8..8d4c79ed2698d 100644 --- a/tests/mir-opt/const_prop/repeat.main.ConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/repeat.main.GVN.32bit.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -20,19 +20,16 @@ _3 = [const 42_u32; 8]; StorageLive(_4); _4 = const 2_usize; -- _5 = Len(_3); + _5 = Len(_3); - _6 = Lt(_4, _5); - assert(move _6, "index out of bounds: the length is {} but the index is {}", move _5, _4) -> [success: bb1, unwind continue]; -+ _5 = const 8_usize; -+ _6 = const true; -+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 8_usize, const 2_usize) -> [success: bb1, unwind continue]; ++ _6 = Lt(const 2_usize, _5); ++ assert(move _6, "index out of bounds: the length is {} but the index is {}", move _5, const 2_usize) -> [success: bb1, unwind continue]; } bb1: { -- _2 = _3[_4]; -- _1 = Add(move _2, const 0_u32); -+ _2 = const 42_u32; -+ _1 = const 42_u32; + _2 = _3[_4]; + _1 = Add(move _2, const 0_u32); StorageDead(_2); StorageDead(_4); StorageDead(_3); diff --git a/tests/mir-opt/const_prop/repeat.main.ConstProp.32bit.panic-unwind.diff b/tests/mir-opt/const_prop/repeat.main.GVN.64bit.panic-unwind.diff similarity index 64% rename from tests/mir-opt/const_prop/repeat.main.ConstProp.32bit.panic-unwind.diff rename to tests/mir-opt/const_prop/repeat.main.GVN.64bit.panic-unwind.diff index d49ef2e0179f8..8d4c79ed2698d 100644 --- a/tests/mir-opt/const_prop/repeat.main.ConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/repeat.main.GVN.64bit.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -20,19 +20,16 @@ _3 = [const 42_u32; 8]; StorageLive(_4); _4 = const 2_usize; -- _5 = Len(_3); + _5 = Len(_3); - _6 = Lt(_4, _5); - assert(move _6, "index out of bounds: the length is {} but the index is {}", move _5, _4) -> [success: bb1, unwind continue]; -+ _5 = const 8_usize; -+ _6 = const true; -+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 8_usize, const 2_usize) -> [success: bb1, unwind continue]; ++ _6 = Lt(const 2_usize, _5); ++ assert(move _6, "index out of bounds: the length is {} but the index is {}", move _5, const 2_usize) -> [success: bb1, unwind continue]; } bb1: { -- _2 = _3[_4]; -- _1 = Add(move _2, const 0_u32); -+ _2 = const 42_u32; -+ _1 = const 42_u32; + _2 = _3[_4]; + _1 = Add(move _2, const 0_u32); StorageDead(_2); StorageDead(_4); StorageDead(_3); diff --git a/tests/mir-opt/const_prop/repeat.rs b/tests/mir-opt/const_prop/repeat.rs index fb8b825ee368b..f1d20add6fb9d 100644 --- a/tests/mir-opt/const_prop/repeat.rs +++ b/tests/mir-opt/const_prop/repeat.rs @@ -1,8 +1,8 @@ -// unit-test: ConstProp +// unit-test: GVN // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // EMIT_MIR_FOR_EACH_BIT_WIDTH -// EMIT_MIR repeat.main.ConstProp.diff +// EMIT_MIR repeat.main.GVN.diff fn main() { let x: u32 = [42; 8][2] + 0; } diff --git a/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/return_place.add.GVN.panic-abort.diff similarity index 87% rename from tests/mir-opt/const_prop/return_place.add.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/return_place.add.GVN.panic-abort.diff index 6c9de4764658d..77c3fd4fd3d53 100644 --- a/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/return_place.add.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `add` before ConstProp -+ // MIR for `add` after ConstProp +- // MIR for `add` before GVN ++ // MIR for `add` after GVN fn add() -> u32 { let mut _0: u32; @@ -19,7 +19,7 @@ } + } + -+ alloc5 (size: 8, align: 4) { ++ alloc3 (size: 8, align: 4) { + 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/return_place.add.GVN.panic-unwind.diff similarity index 86% rename from tests/mir-opt/const_prop/return_place.add.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/return_place.add.GVN.panic-unwind.diff index 0f079278c43d9..974baea00187a 100644 --- a/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/return_place.add.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `add` before ConstProp -+ // MIR for `add` after ConstProp +- // MIR for `add` before GVN ++ // MIR for `add` after GVN fn add() -> u32 { let mut _0: u32; @@ -19,7 +19,7 @@ } + } + -+ alloc5 (size: 8, align: 4) { ++ alloc3 (size: 8, align: 4) { + 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir index c2488f3944cbb..4184c8296aafe 100644 --- a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir +++ b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir @@ -15,6 +15,6 @@ fn add() -> u32 { } } -alloc5 (size: 8, align: 4) { +alloc3 (size: 8, align: 4) { 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir index fa0b9c77eaf61..e126f8bda3190 100644 --- a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir +++ b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir @@ -15,6 +15,6 @@ fn add() -> u32 { } } -alloc5 (size: 8, align: 4) { +alloc3 (size: 8, align: 4) { 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/const_prop/return_place.rs b/tests/mir-opt/const_prop/return_place.rs index 0576b02a84562..6f5579f3097e4 100644 --- a/tests/mir-opt/const_prop/return_place.rs +++ b/tests/mir-opt/const_prop/return_place.rs @@ -1,8 +1,8 @@ -// unit-test: ConstProp +// unit-test: GVN // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // compile-flags: -C overflow-checks=on -// EMIT_MIR return_place.add.ConstProp.diff +// EMIT_MIR return_place.add.GVN.diff // EMIT_MIR return_place.add.PreCodegen.before.mir fn add() -> u32 { 2 + 2 diff --git a/tests/mir-opt/const_prop/scalar_literal_propagation.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/scalar_literal_propagation.main.GVN.panic-abort.diff similarity index 79% rename from tests/mir-opt/const_prop/scalar_literal_propagation.main.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/scalar_literal_propagation.main.GVN.panic-abort.diff index c5c09c8edd7f8..0a20fb0e59ef0 100644 --- a/tests/mir-opt/const_prop/scalar_literal_propagation.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/scalar_literal_propagation.main.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -11,7 +11,8 @@ } bb0: { - StorageLive(_1); +- StorageLive(_1); ++ nop; _1 = const 1_u32; StorageLive(_2); StorageLive(_3); @@ -25,7 +26,8 @@ StorageDead(_3); StorageDead(_2); _0 = const (); - StorageDead(_1); +- StorageDead(_1); ++ nop; return; } } diff --git a/tests/mir-opt/const_prop/scalar_literal_propagation.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/scalar_literal_propagation.main.GVN.panic-unwind.diff similarity index 79% rename from tests/mir-opt/const_prop/scalar_literal_propagation.main.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/scalar_literal_propagation.main.GVN.panic-unwind.diff index b256c56765e3e..8b9519d3adc49 100644 --- a/tests/mir-opt/const_prop/scalar_literal_propagation.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/scalar_literal_propagation.main.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -11,7 +11,8 @@ } bb0: { - StorageLive(_1); +- StorageLive(_1); ++ nop; _1 = const 1_u32; StorageLive(_2); StorageLive(_3); @@ -25,7 +26,8 @@ StorageDead(_3); StorageDead(_2); _0 = const (); - StorageDead(_1); +- StorageDead(_1); ++ nop; return; } } diff --git a/tests/mir-opt/const_prop/scalar_literal_propagation.rs b/tests/mir-opt/const_prop/scalar_literal_propagation.rs index dfe41e6145bdd..422d69d56e9c5 100644 --- a/tests/mir-opt/const_prop/scalar_literal_propagation.rs +++ b/tests/mir-opt/const_prop/scalar_literal_propagation.rs @@ -1,6 +1,6 @@ -// unit-test: ConstProp +// unit-test: GVN // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// EMIT_MIR scalar_literal_propagation.main.ConstProp.diff +// EMIT_MIR scalar_literal_propagation.main.GVN.diff fn main() { let x = 1; consume(x); diff --git a/tests/mir-opt/const_prop/slice_len.main.ConstProp.32bit.panic-abort.diff b/tests/mir-opt/const_prop/slice_len.main.ConstProp.32bit.panic-abort.diff deleted file mode 100644 index c2e1288b41e44..0000000000000 --- a/tests/mir-opt/const_prop/slice_len.main.ConstProp.32bit.panic-abort.diff +++ /dev/null @@ -1,47 +0,0 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp - - fn main() -> () { - let mut _0: (); - let _1: u32; - let mut _2: &[u32]; - let mut _3: &[u32; 3]; - let _4: &[u32; 3]; - let _5: [u32; 3]; - let _6: usize; - let mut _7: usize; - let mut _8: bool; - let mut _9: &[u32; 3]; - - bb0: { - StorageLive(_1); - StorageLive(_2); - StorageLive(_3); - StorageLive(_4); - _9 = const _; - _4 = _9; - _3 = _4; - _2 = move _3 as &[u32] (PointerCoercion(Unsize)); - StorageDead(_3); - StorageLive(_6); - _6 = const 1_usize; -- _7 = Len((*_2)); -- _8 = Lt(_6, _7); -- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind unreachable]; -+ _7 = const 3_usize; -+ _8 = const true; -+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb1, unwind unreachable]; - } - - bb1: { -- _1 = (*_2)[_6]; -+ _1 = const 2_u32; - StorageDead(_6); - StorageDead(_4); - StorageDead(_2); - StorageDead(_1); - _0 = const (); - return; - } - } - diff --git a/tests/mir-opt/const_prop/slice_len.main.ConstProp.64bit.panic-abort.diff b/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff similarity index 62% rename from tests/mir-opt/const_prop/slice_len.main.ConstProp.64bit.panic-abort.diff rename to tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff index c2e1288b41e44..b21cb4ba165f1 100644 --- a/tests/mir-opt/const_prop/slice_len.main.ConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -19,23 +19,24 @@ StorageLive(_3); StorageLive(_4); _9 = const _; - _4 = _9; - _3 = _4; - _2 = move _3 as &[u32] (PointerCoercion(Unsize)); +- _4 = _9; +- _3 = _4; +- _2 = move _3 as &[u32] (PointerCoercion(Unsize)); ++ _4 = const _; ++ _3 = const _; ++ _2 = const _ as &[u32] (PointerCoercion(Unsize)); StorageDead(_3); StorageLive(_6); _6 = const 1_usize; -- _7 = Len((*_2)); + _7 = Len((*_2)); - _8 = Lt(_6, _7); - assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind unreachable]; -+ _7 = const 3_usize; -+ _8 = const true; -+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb1, unwind unreachable]; ++ _8 = Lt(const 1_usize, _7); ++ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 1_usize) -> [success: bb1, unwind unreachable]; } bb1: { -- _1 = (*_2)[_6]; -+ _1 = const 2_u32; + _1 = (*_2)[_6]; StorageDead(_6); StorageDead(_4); StorageDead(_2); diff --git a/tests/mir-opt/const_prop/slice_len.main.ConstProp.32bit.panic-unwind.diff b/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff similarity index 62% rename from tests/mir-opt/const_prop/slice_len.main.ConstProp.32bit.panic-unwind.diff rename to tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff index 23646c3c9762c..841ba26e5ef57 100644 --- a/tests/mir-opt/const_prop/slice_len.main.ConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -19,23 +19,24 @@ StorageLive(_3); StorageLive(_4); _9 = const _; - _4 = _9; - _3 = _4; - _2 = move _3 as &[u32] (PointerCoercion(Unsize)); +- _4 = _9; +- _3 = _4; +- _2 = move _3 as &[u32] (PointerCoercion(Unsize)); ++ _4 = const _; ++ _3 = const _; ++ _2 = const _ as &[u32] (PointerCoercion(Unsize)); StorageDead(_3); StorageLive(_6); _6 = const 1_usize; -- _7 = Len((*_2)); + _7 = Len((*_2)); - _8 = Lt(_6, _7); - assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind continue]; -+ _7 = const 3_usize; -+ _8 = const true; -+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb1, unwind continue]; ++ _8 = Lt(const 1_usize, _7); ++ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 1_usize) -> [success: bb1, unwind continue]; } bb1: { -- _1 = (*_2)[_6]; -+ _1 = const 2_u32; + _1 = (*_2)[_6]; StorageDead(_6); StorageDead(_4); StorageDead(_2); diff --git a/tests/mir-opt/const_prop/slice_len.main.ConstProp.64bit.panic-unwind.diff b/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff similarity index 62% rename from tests/mir-opt/const_prop/slice_len.main.ConstProp.64bit.panic-unwind.diff rename to tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff index 23646c3c9762c..841ba26e5ef57 100644 --- a/tests/mir-opt/const_prop/slice_len.main.ConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -19,23 +19,24 @@ StorageLive(_3); StorageLive(_4); _9 = const _; - _4 = _9; - _3 = _4; - _2 = move _3 as &[u32] (PointerCoercion(Unsize)); +- _4 = _9; +- _3 = _4; +- _2 = move _3 as &[u32] (PointerCoercion(Unsize)); ++ _4 = const _; ++ _3 = const _; ++ _2 = const _ as &[u32] (PointerCoercion(Unsize)); StorageDead(_3); StorageLive(_6); _6 = const 1_usize; -- _7 = Len((*_2)); + _7 = Len((*_2)); - _8 = Lt(_6, _7); - assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind continue]; -+ _7 = const 3_usize; -+ _8 = const true; -+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb1, unwind continue]; ++ _8 = Lt(const 1_usize, _7); ++ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 1_usize) -> [success: bb1, unwind continue]; } bb1: { -- _1 = (*_2)[_6]; -+ _1 = const 2_u32; + _1 = (*_2)[_6]; StorageDead(_6); StorageDead(_4); StorageDead(_2); diff --git a/tests/mir-opt/const_prop/slice_len.rs b/tests/mir-opt/const_prop/slice_len.rs index e91724536f918..213abd08583e0 100644 --- a/tests/mir-opt/const_prop/slice_len.rs +++ b/tests/mir-opt/const_prop/slice_len.rs @@ -1,9 +1,9 @@ // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// unit-test: ConstProp +// unit-test: GVN // compile-flags: -Zmir-enable-passes=+InstSimplify // EMIT_MIR_FOR_EACH_BIT_WIDTH -// EMIT_MIR slice_len.main.ConstProp.diff +// EMIT_MIR slice_len.main.GVN.diff fn main() { (&[1u32, 2, 3] as &[u32])[1]; } diff --git a/tests/mir-opt/const_prop/switch_int.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/switch_int.main.GVN.panic-abort.diff similarity index 87% rename from tests/mir-opt/const_prop/switch_int.main.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/switch_int.main.GVN.panic-abort.diff index 508cc15732c0c..ee9f2d5c7f5bd 100644 --- a/tests/mir-opt/const_prop/switch_int.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/switch_int.main.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_prop/switch_int.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/switch_int.main.GVN.panic-unwind.diff similarity index 87% rename from tests/mir-opt/const_prop/switch_int.main.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/switch_int.main.GVN.panic-unwind.diff index 1ce28e979a5b0..143d04ac984bc 100644 --- a/tests/mir-opt/const_prop/switch_int.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/switch_int.main.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_prop/switch_int.rs b/tests/mir-opt/const_prop/switch_int.rs index bf708c8298e16..1d8cce81b9a24 100644 --- a/tests/mir-opt/const_prop/switch_int.rs +++ b/tests/mir-opt/const_prop/switch_int.rs @@ -1,10 +1,10 @@ -// unit-test: ConstProp +// unit-test: GVN // compile-flags: -Zmir-enable-passes=+SimplifyConstCondition-after-const-prop // EMIT_MIR_FOR_EACH_PANIC_STRATEGY #[inline(never)] fn foo(_: i32) { } -// EMIT_MIR switch_int.main.ConstProp.diff +// EMIT_MIR switch_int.main.GVN.diff // EMIT_MIR switch_int.main.SimplifyConstCondition-after-const-prop.diff fn main() { match 1 { diff --git a/tests/mir-opt/const_prop/transmute.from_char.ConstProp.32bit.diff b/tests/mir-opt/const_prop/transmute.from_char.GVN.32bit.diff similarity index 70% rename from tests/mir-opt/const_prop/transmute.from_char.ConstProp.32bit.diff rename to tests/mir-opt/const_prop/transmute.from_char.GVN.32bit.diff index febfebc85347c..47dfb421ebc8f 100644 --- a/tests/mir-opt/const_prop/transmute.from_char.ConstProp.32bit.diff +++ b/tests/mir-opt/const_prop/transmute.from_char.GVN.32bit.diff @@ -1,5 +1,5 @@ -- // MIR for `from_char` before ConstProp -+ // MIR for `from_char` after ConstProp +- // MIR for `from_char` before GVN ++ // MIR for `from_char` after GVN fn from_char() -> i32 { let mut _0: i32; diff --git a/tests/mir-opt/const_prop/transmute.from_char.ConstProp.64bit.diff b/tests/mir-opt/const_prop/transmute.from_char.GVN.64bit.diff similarity index 70% rename from tests/mir-opt/const_prop/transmute.from_char.ConstProp.64bit.diff rename to tests/mir-opt/const_prop/transmute.from_char.GVN.64bit.diff index febfebc85347c..47dfb421ebc8f 100644 --- a/tests/mir-opt/const_prop/transmute.from_char.ConstProp.64bit.diff +++ b/tests/mir-opt/const_prop/transmute.from_char.GVN.64bit.diff @@ -1,5 +1,5 @@ -- // MIR for `from_char` before ConstProp -+ // MIR for `from_char` after ConstProp +- // MIR for `from_char` before GVN ++ // MIR for `from_char` after GVN fn from_char() -> i32 { let mut _0: i32; diff --git a/tests/mir-opt/const_prop/transmute.invalid_bool.ConstProp.64bit.diff b/tests/mir-opt/const_prop/transmute.invalid_bool.GVN.32bit.diff similarity index 71% rename from tests/mir-opt/const_prop/transmute.invalid_bool.ConstProp.64bit.diff rename to tests/mir-opt/const_prop/transmute.invalid_bool.GVN.32bit.diff index 38a1eb5a15b57..f0c6f55f775f6 100644 --- a/tests/mir-opt/const_prop/transmute.invalid_bool.ConstProp.64bit.diff +++ b/tests/mir-opt/const_prop/transmute.invalid_bool.GVN.32bit.diff @@ -1,5 +1,5 @@ -- // MIR for `invalid_bool` before ConstProp -+ // MIR for `invalid_bool` after ConstProp +- // MIR for `invalid_bool` before GVN ++ // MIR for `invalid_bool` after GVN fn invalid_bool() -> bool { let mut _0: bool; diff --git a/tests/mir-opt/const_prop/transmute.invalid_bool.ConstProp.32bit.diff b/tests/mir-opt/const_prop/transmute.invalid_bool.GVN.64bit.diff similarity index 71% rename from tests/mir-opt/const_prop/transmute.invalid_bool.ConstProp.32bit.diff rename to tests/mir-opt/const_prop/transmute.invalid_bool.GVN.64bit.diff index 38a1eb5a15b57..f0c6f55f775f6 100644 --- a/tests/mir-opt/const_prop/transmute.invalid_bool.ConstProp.32bit.diff +++ b/tests/mir-opt/const_prop/transmute.invalid_bool.GVN.64bit.diff @@ -1,5 +1,5 @@ -- // MIR for `invalid_bool` before ConstProp -+ // MIR for `invalid_bool` after ConstProp +- // MIR for `invalid_bool` before GVN ++ // MIR for `invalid_bool` after GVN fn invalid_bool() -> bool { let mut _0: bool; diff --git a/tests/mir-opt/const_prop/transmute.invalid_char.ConstProp.32bit.diff b/tests/mir-opt/const_prop/transmute.invalid_char.GVN.32bit.diff similarity index 71% rename from tests/mir-opt/const_prop/transmute.invalid_char.ConstProp.32bit.diff rename to tests/mir-opt/const_prop/transmute.invalid_char.GVN.32bit.diff index 2c0998f77eaee..a9e32d4d92544 100644 --- a/tests/mir-opt/const_prop/transmute.invalid_char.ConstProp.32bit.diff +++ b/tests/mir-opt/const_prop/transmute.invalid_char.GVN.32bit.diff @@ -1,5 +1,5 @@ -- // MIR for `invalid_char` before ConstProp -+ // MIR for `invalid_char` after ConstProp +- // MIR for `invalid_char` before GVN ++ // MIR for `invalid_char` after GVN fn invalid_char() -> char { let mut _0: char; diff --git a/tests/mir-opt/const_prop/transmute.invalid_char.ConstProp.64bit.diff b/tests/mir-opt/const_prop/transmute.invalid_char.GVN.64bit.diff similarity index 71% rename from tests/mir-opt/const_prop/transmute.invalid_char.ConstProp.64bit.diff rename to tests/mir-opt/const_prop/transmute.invalid_char.GVN.64bit.diff index 2c0998f77eaee..a9e32d4d92544 100644 --- a/tests/mir-opt/const_prop/transmute.invalid_char.ConstProp.64bit.diff +++ b/tests/mir-opt/const_prop/transmute.invalid_char.GVN.64bit.diff @@ -1,5 +1,5 @@ -- // MIR for `invalid_char` before ConstProp -+ // MIR for `invalid_char` after ConstProp +- // MIR for `invalid_char` before GVN ++ // MIR for `invalid_char` after GVN fn invalid_char() -> char { let mut _0: char; diff --git a/tests/mir-opt/const_prop/transmute.less_as_i8.ConstProp.32bit.diff b/tests/mir-opt/const_prop/transmute.less_as_i8.GVN.32bit.diff similarity index 79% rename from tests/mir-opt/const_prop/transmute.less_as_i8.ConstProp.32bit.diff rename to tests/mir-opt/const_prop/transmute.less_as_i8.GVN.32bit.diff index 7ac7bed8a5f70..5e0c076b9819f 100644 --- a/tests/mir-opt/const_prop/transmute.less_as_i8.ConstProp.32bit.diff +++ b/tests/mir-opt/const_prop/transmute.less_as_i8.GVN.32bit.diff @@ -1,5 +1,5 @@ -- // MIR for `less_as_i8` before ConstProp -+ // MIR for `less_as_i8` after ConstProp +- // MIR for `less_as_i8` before GVN ++ // MIR for `less_as_i8` after GVN fn less_as_i8() -> i8 { let mut _0: i8; diff --git a/tests/mir-opt/const_prop/transmute.less_as_i8.ConstProp.64bit.diff b/tests/mir-opt/const_prop/transmute.less_as_i8.GVN.64bit.diff similarity index 79% rename from tests/mir-opt/const_prop/transmute.less_as_i8.ConstProp.64bit.diff rename to tests/mir-opt/const_prop/transmute.less_as_i8.GVN.64bit.diff index 7ac7bed8a5f70..5e0c076b9819f 100644 --- a/tests/mir-opt/const_prop/transmute.less_as_i8.ConstProp.64bit.diff +++ b/tests/mir-opt/const_prop/transmute.less_as_i8.GVN.64bit.diff @@ -1,5 +1,5 @@ -- // MIR for `less_as_i8` before ConstProp -+ // MIR for `less_as_i8` after ConstProp +- // MIR for `less_as_i8` before GVN ++ // MIR for `less_as_i8` after GVN fn less_as_i8() -> i8 { let mut _0: i8; diff --git a/tests/mir-opt/const_prop/transmute.rs b/tests/mir-opt/const_prop/transmute.rs index 762c421715ab5..8c70b1eb0d8f4 100644 --- a/tests/mir-opt/const_prop/transmute.rs +++ b/tests/mir-opt/const_prop/transmute.rs @@ -1,60 +1,60 @@ -// unit-test: ConstProp +// unit-test: GVN // compile-flags: -O --crate-type=lib // ignore-endian-big // EMIT_MIR_FOR_EACH_BIT_WIDTH use std::mem::transmute; -// EMIT_MIR transmute.less_as_i8.ConstProp.diff +// EMIT_MIR transmute.less_as_i8.GVN.diff pub fn less_as_i8() -> i8 { unsafe { transmute(std::cmp::Ordering::Less) } } -// EMIT_MIR transmute.from_char.ConstProp.diff +// EMIT_MIR transmute.from_char.GVN.diff pub fn from_char() -> i32 { unsafe { transmute('R') } } -// EMIT_MIR transmute.valid_char.ConstProp.diff +// EMIT_MIR transmute.valid_char.GVN.diff pub fn valid_char() -> char { unsafe { transmute(0x52_u32) } } -// EMIT_MIR transmute.invalid_char.ConstProp.diff +// EMIT_MIR transmute.invalid_char.GVN.diff pub unsafe fn invalid_char() -> char { unsafe { transmute(i32::MAX) } } -// EMIT_MIR transmute.invalid_bool.ConstProp.diff +// EMIT_MIR transmute.invalid_bool.GVN.diff pub unsafe fn invalid_bool() -> bool { unsafe { transmute(-1_i8) } } -// EMIT_MIR transmute.undef_union_as_integer.ConstProp.diff +// EMIT_MIR transmute.undef_union_as_integer.GVN.diff pub unsafe fn undef_union_as_integer() -> u32 { union Union32 { value: u32, unit: () } unsafe { transmute(Union32 { unit: () }) } } -// EMIT_MIR transmute.unreachable_direct.ConstProp.diff +// EMIT_MIR transmute.unreachable_direct.GVN.diff pub unsafe fn unreachable_direct() -> ! { let x: Never = unsafe { transmute(()) }; match x {} } -// EMIT_MIR transmute.unreachable_ref.ConstProp.diff +// EMIT_MIR transmute.unreachable_ref.GVN.diff pub unsafe fn unreachable_ref() -> ! { let x: &Never = unsafe { transmute(1_usize) }; match *x {} } -// EMIT_MIR transmute.unreachable_mut.ConstProp.diff +// EMIT_MIR transmute.unreachable_mut.GVN.diff pub unsafe fn unreachable_mut() -> ! { let x: &mut Never = unsafe { transmute(1_usize) }; match *x {} } -// EMIT_MIR transmute.unreachable_box.ConstProp.diff +// EMIT_MIR transmute.unreachable_box.GVN.diff pub unsafe fn unreachable_box() -> ! { let x: Box = unsafe { transmute(1_usize) }; match *x {} diff --git a/tests/mir-opt/const_prop/transmute.undef_union_as_integer.ConstProp.64bit.diff b/tests/mir-opt/const_prop/transmute.undef_union_as_integer.GVN.32bit.diff similarity index 61% rename from tests/mir-opt/const_prop/transmute.undef_union_as_integer.ConstProp.64bit.diff rename to tests/mir-opt/const_prop/transmute.undef_union_as_integer.GVN.32bit.diff index afedf2a306137..78b107b232460 100644 --- a/tests/mir-opt/const_prop/transmute.undef_union_as_integer.ConstProp.64bit.diff +++ b/tests/mir-opt/const_prop/transmute.undef_union_as_integer.GVN.32bit.diff @@ -1,5 +1,5 @@ -- // MIR for `undef_union_as_integer` before ConstProp -+ // MIR for `undef_union_as_integer` after ConstProp +- // MIR for `undef_union_as_integer` before GVN ++ // MIR for `undef_union_as_integer` after GVN fn undef_union_as_integer() -> u32 { let mut _0: u32; @@ -11,8 +11,10 @@ bb0: { StorageLive(_1); StorageLive(_2); - _2 = (); - _1 = Union32 { value: move _2 }; +- _2 = (); +- _1 = Union32 { value: move _2 }; ++ _2 = const (); ++ _1 = Union32 { value: const () }; StorageDead(_2); _0 = move _1 as u32 (Transmute); StorageDead(_1); diff --git a/tests/mir-opt/const_prop/transmute.undef_union_as_integer.ConstProp.32bit.diff b/tests/mir-opt/const_prop/transmute.undef_union_as_integer.GVN.64bit.diff similarity index 61% rename from tests/mir-opt/const_prop/transmute.undef_union_as_integer.ConstProp.32bit.diff rename to tests/mir-opt/const_prop/transmute.undef_union_as_integer.GVN.64bit.diff index afedf2a306137..78b107b232460 100644 --- a/tests/mir-opt/const_prop/transmute.undef_union_as_integer.ConstProp.32bit.diff +++ b/tests/mir-opt/const_prop/transmute.undef_union_as_integer.GVN.64bit.diff @@ -1,5 +1,5 @@ -- // MIR for `undef_union_as_integer` before ConstProp -+ // MIR for `undef_union_as_integer` after ConstProp +- // MIR for `undef_union_as_integer` before GVN ++ // MIR for `undef_union_as_integer` after GVN fn undef_union_as_integer() -> u32 { let mut _0: u32; @@ -11,8 +11,10 @@ bb0: { StorageLive(_1); StorageLive(_2); - _2 = (); - _1 = Union32 { value: move _2 }; +- _2 = (); +- _1 = Union32 { value: move _2 }; ++ _2 = const (); ++ _1 = Union32 { value: const () }; StorageDead(_2); _0 = move _1 as u32 (Transmute); StorageDead(_1); diff --git a/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.64bit.diff b/tests/mir-opt/const_prop/transmute.unreachable_box.GVN.32bit.diff similarity index 83% rename from tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.64bit.diff rename to tests/mir-opt/const_prop/transmute.unreachable_box.GVN.32bit.diff index 100982382ddbf..cc642ba6ca34e 100644 --- a/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.64bit.diff +++ b/tests/mir-opt/const_prop/transmute.unreachable_box.GVN.32bit.diff @@ -1,5 +1,5 @@ -- // MIR for `unreachable_box` before ConstProp -+ // MIR for `unreachable_box` after ConstProp +- // MIR for `unreachable_box` before GVN ++ // MIR for `unreachable_box` after GVN fn unreachable_box() -> ! { let mut _0: !; diff --git a/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.32bit.diff b/tests/mir-opt/const_prop/transmute.unreachable_box.GVN.64bit.diff similarity index 83% rename from tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.32bit.diff rename to tests/mir-opt/const_prop/transmute.unreachable_box.GVN.64bit.diff index 100982382ddbf..cc642ba6ca34e 100644 --- a/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.32bit.diff +++ b/tests/mir-opt/const_prop/transmute.unreachable_box.GVN.64bit.diff @@ -1,5 +1,5 @@ -- // MIR for `unreachable_box` before ConstProp -+ // MIR for `unreachable_box` after ConstProp +- // MIR for `unreachable_box` before GVN ++ // MIR for `unreachable_box` after GVN fn unreachable_box() -> ! { let mut _0: !; diff --git a/tests/mir-opt/const_prop/transmute.unreachable_direct.ConstProp.32bit.diff b/tests/mir-opt/const_prop/transmute.unreachable_direct.GVN.32bit.diff similarity index 56% rename from tests/mir-opt/const_prop/transmute.unreachable_direct.ConstProp.32bit.diff rename to tests/mir-opt/const_prop/transmute.unreachable_direct.GVN.32bit.diff index 896608e7eff5d..02ff29dcb7766 100644 --- a/tests/mir-opt/const_prop/transmute.unreachable_direct.ConstProp.32bit.diff +++ b/tests/mir-opt/const_prop/transmute.unreachable_direct.GVN.32bit.diff @@ -1,5 +1,5 @@ -- // MIR for `unreachable_direct` before ConstProp -+ // MIR for `unreachable_direct` after ConstProp +- // MIR for `unreachable_direct` before GVN ++ // MIR for `unreachable_direct` after GVN fn unreachable_direct() -> ! { let mut _0: !; @@ -14,8 +14,10 @@ bb0: { StorageLive(_1); StorageLive(_2); - _2 = (); - _1 = move _2 as Never (Transmute); +- _2 = (); +- _1 = move _2 as Never (Transmute); ++ _2 = const (); ++ _1 = const ZeroSized: Never; unreachable; } } diff --git a/tests/mir-opt/const_prop/transmute.unreachable_direct.ConstProp.64bit.diff b/tests/mir-opt/const_prop/transmute.unreachable_direct.GVN.64bit.diff similarity index 56% rename from tests/mir-opt/const_prop/transmute.unreachable_direct.ConstProp.64bit.diff rename to tests/mir-opt/const_prop/transmute.unreachable_direct.GVN.64bit.diff index 896608e7eff5d..02ff29dcb7766 100644 --- a/tests/mir-opt/const_prop/transmute.unreachable_direct.ConstProp.64bit.diff +++ b/tests/mir-opt/const_prop/transmute.unreachable_direct.GVN.64bit.diff @@ -1,5 +1,5 @@ -- // MIR for `unreachable_direct` before ConstProp -+ // MIR for `unreachable_direct` after ConstProp +- // MIR for `unreachable_direct` before GVN ++ // MIR for `unreachable_direct` after GVN fn unreachable_direct() -> ! { let mut _0: !; @@ -14,8 +14,10 @@ bb0: { StorageLive(_1); StorageLive(_2); - _2 = (); - _1 = move _2 as Never (Transmute); +- _2 = (); +- _1 = move _2 as Never (Transmute); ++ _2 = const (); ++ _1 = const ZeroSized: Never; unreachable; } } diff --git a/tests/mir-opt/const_prop/transmute.unreachable_mut.ConstProp.32bit.diff b/tests/mir-opt/const_prop/transmute.unreachable_mut.GVN.32bit.diff similarity index 82% rename from tests/mir-opt/const_prop/transmute.unreachable_mut.ConstProp.32bit.diff rename to tests/mir-opt/const_prop/transmute.unreachable_mut.GVN.32bit.diff index c9d5ccf0bfdd1..5518ab36cc4fc 100644 --- a/tests/mir-opt/const_prop/transmute.unreachable_mut.ConstProp.32bit.diff +++ b/tests/mir-opt/const_prop/transmute.unreachable_mut.GVN.32bit.diff @@ -1,5 +1,5 @@ -- // MIR for `unreachable_mut` before ConstProp -+ // MIR for `unreachable_mut` after ConstProp +- // MIR for `unreachable_mut` before GVN ++ // MIR for `unreachable_mut` after GVN fn unreachable_mut() -> ! { let mut _0: !; diff --git a/tests/mir-opt/const_prop/transmute.unreachable_mut.ConstProp.64bit.diff b/tests/mir-opt/const_prop/transmute.unreachable_mut.GVN.64bit.diff similarity index 82% rename from tests/mir-opt/const_prop/transmute.unreachable_mut.ConstProp.64bit.diff rename to tests/mir-opt/const_prop/transmute.unreachable_mut.GVN.64bit.diff index c9d5ccf0bfdd1..5518ab36cc4fc 100644 --- a/tests/mir-opt/const_prop/transmute.unreachable_mut.ConstProp.64bit.diff +++ b/tests/mir-opt/const_prop/transmute.unreachable_mut.GVN.64bit.diff @@ -1,5 +1,5 @@ -- // MIR for `unreachable_mut` before ConstProp -+ // MIR for `unreachable_mut` after ConstProp +- // MIR for `unreachable_mut` before GVN ++ // MIR for `unreachable_mut` after GVN fn unreachable_mut() -> ! { let mut _0: !; diff --git a/tests/mir-opt/const_prop/transmute.unreachable_ref.ConstProp.32bit.diff b/tests/mir-opt/const_prop/transmute.unreachable_ref.GVN.32bit.diff similarity index 77% rename from tests/mir-opt/const_prop/transmute.unreachable_ref.ConstProp.32bit.diff rename to tests/mir-opt/const_prop/transmute.unreachable_ref.GVN.32bit.diff index b684ba34c691a..430d16c97a6c5 100644 --- a/tests/mir-opt/const_prop/transmute.unreachable_ref.ConstProp.32bit.diff +++ b/tests/mir-opt/const_prop/transmute.unreachable_ref.GVN.32bit.diff @@ -1,5 +1,5 @@ -- // MIR for `unreachable_ref` before ConstProp -+ // MIR for `unreachable_ref` after ConstProp +- // MIR for `unreachable_ref` before GVN ++ // MIR for `unreachable_ref` after GVN fn unreachable_ref() -> ! { let mut _0: !; diff --git a/tests/mir-opt/const_prop/transmute.unreachable_ref.ConstProp.64bit.diff b/tests/mir-opt/const_prop/transmute.unreachable_ref.GVN.64bit.diff similarity index 77% rename from tests/mir-opt/const_prop/transmute.unreachable_ref.ConstProp.64bit.diff rename to tests/mir-opt/const_prop/transmute.unreachable_ref.GVN.64bit.diff index b684ba34c691a..430d16c97a6c5 100644 --- a/tests/mir-opt/const_prop/transmute.unreachable_ref.ConstProp.64bit.diff +++ b/tests/mir-opt/const_prop/transmute.unreachable_ref.GVN.64bit.diff @@ -1,5 +1,5 @@ -- // MIR for `unreachable_ref` before ConstProp -+ // MIR for `unreachable_ref` after ConstProp +- // MIR for `unreachable_ref` before GVN ++ // MIR for `unreachable_ref` after GVN fn unreachable_ref() -> ! { let mut _0: !; diff --git a/tests/mir-opt/const_prop/transmute.valid_char.ConstProp.32bit.diff b/tests/mir-opt/const_prop/transmute.valid_char.GVN.32bit.diff similarity index 70% rename from tests/mir-opt/const_prop/transmute.valid_char.ConstProp.32bit.diff rename to tests/mir-opt/const_prop/transmute.valid_char.GVN.32bit.diff index f215b3ca398a7..f9d002f96ab09 100644 --- a/tests/mir-opt/const_prop/transmute.valid_char.ConstProp.32bit.diff +++ b/tests/mir-opt/const_prop/transmute.valid_char.GVN.32bit.diff @@ -1,5 +1,5 @@ -- // MIR for `valid_char` before ConstProp -+ // MIR for `valid_char` after ConstProp +- // MIR for `valid_char` before GVN ++ // MIR for `valid_char` after GVN fn valid_char() -> char { let mut _0: char; diff --git a/tests/mir-opt/const_prop/transmute.valid_char.ConstProp.64bit.diff b/tests/mir-opt/const_prop/transmute.valid_char.GVN.64bit.diff similarity index 70% rename from tests/mir-opt/const_prop/transmute.valid_char.ConstProp.64bit.diff rename to tests/mir-opt/const_prop/transmute.valid_char.GVN.64bit.diff index f215b3ca398a7..f9d002f96ab09 100644 --- a/tests/mir-opt/const_prop/transmute.valid_char.ConstProp.64bit.diff +++ b/tests/mir-opt/const_prop/transmute.valid_char.GVN.64bit.diff @@ -1,5 +1,5 @@ -- // MIR for `valid_char` before ConstProp -+ // MIR for `valid_char` after ConstProp +- // MIR for `valid_char` before GVN ++ // MIR for `valid_char` after GVN fn valid_char() -> char { let mut _0: char; diff --git a/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-abort.diff similarity index 66% rename from tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-abort.diff rename to tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-abort.diff index 988ef7dd2254a..7a9f8bb76356d 100644 --- a/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -11,8 +11,9 @@ } bb0: { - StorageLive(_1); +- StorageLive(_1); - _1 = (const 1_u32, const 2_u32); ++ nop; + _1 = const (1_u32, 2_u32); StorageLive(_2); StorageLive(_3); @@ -26,20 +27,13 @@ StorageDead(_3); StorageDead(_2); _0 = const (); - StorageDead(_1); +- StorageDead(_1); ++ nop; return; } + } + -+ alloc9 (size: 8, align: 4) { -+ 01 00 00 00 02 00 00 00 │ ........ -+ } -+ -+ alloc8 (size: 8, align: 4) { -+ 01 00 00 00 02 00 00 00 │ ........ -+ } -+ -+ alloc6 (size: 8, align: 4) { ++ alloc4 (size: 8, align: 4) { + 01 00 00 00 02 00 00 00 │ ........ } diff --git a/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-unwind.diff similarity index 66% rename from tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-unwind.diff rename to tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-unwind.diff index 298446197203d..7f22b45139186 100644 --- a/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); @@ -11,8 +11,9 @@ } bb0: { - StorageLive(_1); +- StorageLive(_1); - _1 = (const 1_u32, const 2_u32); ++ nop; + _1 = const (1_u32, 2_u32); StorageLive(_2); StorageLive(_3); @@ -26,20 +27,13 @@ StorageDead(_3); StorageDead(_2); _0 = const (); - StorageDead(_1); +- StorageDead(_1); ++ nop; return; } + } + -+ alloc9 (size: 8, align: 4) { -+ 01 00 00 00 02 00 00 00 │ ........ -+ } -+ -+ alloc8 (size: 8, align: 4) { -+ 01 00 00 00 02 00 00 00 │ ........ -+ } -+ -+ alloc6 (size: 8, align: 4) { ++ alloc4 (size: 8, align: 4) { + 01 00 00 00 02 00 00 00 │ ........ } diff --git a/tests/mir-opt/const_prop/tuple_literal_propagation.rs b/tests/mir-opt/const_prop/tuple_literal_propagation.rs index 5890a343f26c3..2e071eb2ce3e5 100644 --- a/tests/mir-opt/const_prop/tuple_literal_propagation.rs +++ b/tests/mir-opt/const_prop/tuple_literal_propagation.rs @@ -1,6 +1,6 @@ -// unit-test: ConstProp +// unit-test: GVN // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// EMIT_MIR tuple_literal_propagation.main.ConstProp.diff +// EMIT_MIR tuple_literal_propagation.main.GVN.diff fn main() { let x = (1, 2); diff --git a/tests/mir-opt/const_prop/while_let_loops.change_loop_body.ConstProp.diff b/tests/mir-opt/const_prop/while_let_loops.change_loop_body.GVN.diff similarity index 68% rename from tests/mir-opt/const_prop/while_let_loops.change_loop_body.ConstProp.diff rename to tests/mir-opt/const_prop/while_let_loops.change_loop_body.GVN.diff index f54908b4a38a6..953fa717d85d4 100644 --- a/tests/mir-opt/const_prop/while_let_loops.change_loop_body.ConstProp.diff +++ b/tests/mir-opt/const_prop/while_let_loops.change_loop_body.GVN.diff @@ -1,5 +1,5 @@ -- // MIR for `change_loop_body` before ConstProp -+ // MIR for `change_loop_body` after ConstProp +- // MIR for `change_loop_body` before GVN ++ // MIR for `change_loop_body` after GVN fn change_loop_body() -> () { let mut _0: (); @@ -21,15 +21,17 @@ StorageLive(_1); _1 = const 0_i32; StorageLive(_3); - _3 = Option::::None; +- _3 = Option::::None; - _4 = discriminant(_3); - switchInt(move _4) -> [1: bb1, otherwise: bb3]; ++ _3 = const Option::::None; + _4 = const 0_isize; + switchInt(const 0_isize) -> [1: bb1, otherwise: bb3]; } bb1: { - switchInt(((_3 as Some).0: u32)) -> [0: bb2, otherwise: bb3]; +- switchInt(((_3 as Some).0: u32)) -> [0: bb2, otherwise: bb3]; ++ switchInt(const Indirect { alloc_id: alloc4, offset: Size(4 bytes) }: u32) -> [0: bb2, otherwise: bb3]; } bb2: { @@ -50,5 +52,9 @@ StorageDead(_1); return; } ++ } ++ ++ alloc4 (size: 8, align: 4) { ++ 00 00 00 00 __ __ __ __ │ ....░░░░ } diff --git a/tests/mir-opt/const_prop/while_let_loops.rs b/tests/mir-opt/const_prop/while_let_loops.rs index 595a94b88be0e..349cb11795f4c 100644 --- a/tests/mir-opt/const_prop/while_let_loops.rs +++ b/tests/mir-opt/const_prop/while_let_loops.rs @@ -1,5 +1,5 @@ -// unit-test: ConstProp -// EMIT_MIR while_let_loops.change_loop_body.ConstProp.diff +// unit-test: GVN +// EMIT_MIR while_let_loops.change_loop_body.GVN.diff pub fn change_loop_body() { let mut _x = 0; diff --git a/tests/mir-opt/const_prop_miscompile.bar.ConstProp.diff b/tests/mir-opt/const_prop_miscompile.bar.GVN.diff similarity index 87% rename from tests/mir-opt/const_prop_miscompile.bar.ConstProp.diff rename to tests/mir-opt/const_prop_miscompile.bar.GVN.diff index 4eafb8d09178e..b389080c4977a 100644 --- a/tests/mir-opt/const_prop_miscompile.bar.ConstProp.diff +++ b/tests/mir-opt/const_prop_miscompile.bar.GVN.diff @@ -1,5 +1,5 @@ -- // MIR for `bar` before ConstProp -+ // MIR for `bar` after ConstProp +- // MIR for `bar` before GVN ++ // MIR for `bar` after GVN fn bar() -> () { let mut _0: (); @@ -19,7 +19,8 @@ bb0: { StorageLive(_1); - _1 = (const 1_i32,); +- _1 = (const 1_i32,); ++ _1 = const (1_i32,); StorageLive(_2); StorageLive(_3); _3 = &raw mut (_1.0: i32); diff --git a/tests/mir-opt/const_prop_miscompile.foo.ConstProp.diff b/tests/mir-opt/const_prop_miscompile.foo.GVN.diff similarity index 84% rename from tests/mir-opt/const_prop_miscompile.foo.ConstProp.diff rename to tests/mir-opt/const_prop_miscompile.foo.GVN.diff index 445d9895d6a8f..c21869dece65c 100644 --- a/tests/mir-opt/const_prop_miscompile.foo.ConstProp.diff +++ b/tests/mir-opt/const_prop_miscompile.foo.GVN.diff @@ -1,5 +1,5 @@ -- // MIR for `foo` before ConstProp -+ // MIR for `foo` after ConstProp +- // MIR for `foo` before GVN ++ // MIR for `foo` after GVN fn foo() -> () { let mut _0: (); @@ -16,7 +16,8 @@ bb0: { StorageLive(_1); - _1 = (const 1_i32,); +- _1 = (const 1_i32,); ++ _1 = const (1_i32,); StorageLive(_2); _2 = &mut (_1.0: i32); (*_2) = const 5_i32; diff --git a/tests/mir-opt/const_prop_miscompile.rs b/tests/mir-opt/const_prop_miscompile.rs index dbbe5ee08408f..07fd530b2b1fb 100644 --- a/tests/mir-opt/const_prop_miscompile.rs +++ b/tests/mir-opt/const_prop_miscompile.rs @@ -1,14 +1,14 @@ -// unit-test: ConstProp +// unit-test: GVN #![feature(raw_ref_op)] -// EMIT_MIR const_prop_miscompile.foo.ConstProp.diff +// EMIT_MIR const_prop_miscompile.foo.GVN.diff fn foo() { let mut u = (1,); *&mut u.0 = 5; let y = { u.0 } == 5; } -// EMIT_MIR const_prop_miscompile.bar.ConstProp.diff +// EMIT_MIR const_prop_miscompile.bar.GVN.diff fn bar() { let mut v = (1,); unsafe { diff --git a/tests/mir-opt/dest-prop/unreachable.f.DestinationPropagation.panic-abort.diff b/tests/mir-opt/dest-prop/unreachable.f.DestinationPropagation.panic-abort.diff index 97ca825092e4a..80b5681ad062c 100644 --- a/tests/mir-opt/dest-prop/unreachable.f.DestinationPropagation.panic-abort.diff +++ b/tests/mir-opt/dest-prop/unreachable.f.DestinationPropagation.panic-abort.diff @@ -33,8 +33,8 @@ - StorageLive(_5); - _5 = _1; - StorageLive(_6); -- _6 = _2; -- _4 = g::(move _5, move _6) -> [return: bb2, unwind unreachable]; +- _6 = _1; +- _4 = g::(_1, _1) -> [return: bb2, unwind unreachable]; - } - - bb2: { @@ -48,20 +48,22 @@ - bb3: { StorageLive(_7); - StorageLive(_8); -- _8 = _2; +- _8 = _1; +- StorageLive(_9); +- _9 = _1; +- _7 = g::(_1, _1) -> [return: bb4, unwind unreachable]; + nop; + nop; - StorageLive(_9); -- _9 = _2; -- _7 = g::(move _8, move _9) -> [return: bb4, unwind unreachable]; -+ _9 = _1; -+ _7 = g::(move _1, move _9) -> [return: bb2, unwind unreachable]; ++ nop; ++ nop; ++ _7 = g::(_1, _1) -> [return: bb2, unwind unreachable]; } - bb4: { -+ bb2: { - StorageDead(_9); +- StorageDead(_9); - StorageDead(_8); ++ bb2: { ++ nop; + nop; StorageDead(_7); _0 = const (); diff --git a/tests/mir-opt/dest-prop/unreachable.f.DestinationPropagation.panic-unwind.diff b/tests/mir-opt/dest-prop/unreachable.f.DestinationPropagation.panic-unwind.diff index 7f730a77b06ab..eae7dd17b4882 100644 --- a/tests/mir-opt/dest-prop/unreachable.f.DestinationPropagation.panic-unwind.diff +++ b/tests/mir-opt/dest-prop/unreachable.f.DestinationPropagation.panic-unwind.diff @@ -33,8 +33,8 @@ - StorageLive(_5); - _5 = _1; - StorageLive(_6); -- _6 = _2; -- _4 = g::(move _5, move _6) -> [return: bb2, unwind continue]; +- _6 = _1; +- _4 = g::(_1, _1) -> [return: bb2, unwind continue]; - } - - bb2: { @@ -48,20 +48,22 @@ - bb3: { StorageLive(_7); - StorageLive(_8); -- _8 = _2; +- _8 = _1; +- StorageLive(_9); +- _9 = _1; +- _7 = g::(_1, _1) -> [return: bb4, unwind continue]; + nop; + nop; - StorageLive(_9); -- _9 = _2; -- _7 = g::(move _8, move _9) -> [return: bb4, unwind continue]; -+ _9 = _1; -+ _7 = g::(move _1, move _9) -> [return: bb2, unwind continue]; ++ nop; ++ nop; ++ _7 = g::(_1, _1) -> [return: bb2, unwind continue]; } - bb4: { -+ bb2: { - StorageDead(_9); +- StorageDead(_9); - StorageDead(_8); ++ bb2: { ++ nop; + nop; StorageDead(_7); _0 = const (); diff --git a/tests/mir-opt/dest-prop/unreachable.rs b/tests/mir-opt/dest-prop/unreachable.rs index e950dbbf5c917..c7cc252357964 100644 --- a/tests/mir-opt/dest-prop/unreachable.rs +++ b/tests/mir-opt/dest-prop/unreachable.rs @@ -3,7 +3,7 @@ // Regression test for issue #105428. // // compile-flags: --crate-type=lib -Zmir-opt-level=0 -// compile-flags: -Zmir-enable-passes=+ConstProp,+SimplifyConstCondition-after-const-prop,+DestinationPropagation +// compile-flags: -Zmir-enable-passes=+GVN,+SimplifyConstCondition-after-const-prop,+DestinationPropagation // EMIT_MIR unreachable.f.DestinationPropagation.diff pub fn f(a: T) { diff --git a/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-abort.diff b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.panic-abort.diff similarity index 68% rename from tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-abort.diff rename to tests/mir-opt/funky_arms.float_to_exponential_common.GVN.panic-abort.diff index 9b1d2ee890ef6..87cd105be9426 100644 --- a/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-abort.diff +++ b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `float_to_exponential_common` before ConstProp -+ // MIR for `float_to_exponential_common` after ConstProp +- // MIR for `float_to_exponential_common` before GVN ++ // MIR for `float_to_exponential_common` after GVN fn float_to_exponential_common(_1: &mut Formatter<'_>, _2: &T, _3: bool) -> Result<(), std::fmt::Error> { debug fmt => _1; @@ -11,10 +11,17 @@ let mut _7: std::option::Option; let mut _8: &std::fmt::Formatter<'_>; let mut _9: isize; - let mut _11: core::num::flt2dec::Sign; - let mut _12: u32; - let mut _13: u32; - let mut _14: core::num::flt2dec::Sign; + let mut _11: &mut std::fmt::Formatter<'_>; + let mut _12: &T; + let mut _13: core::num::flt2dec::Sign; + let mut _14: u32; + let mut _15: u32; + let mut _16: usize; + let mut _17: bool; + let mut _18: &mut std::fmt::Formatter<'_>; + let mut _19: &T; + let mut _20: core::num::flt2dec::Sign; + let mut _21: bool; scope 1 { debug force_sign => _4; let _6: core::num::flt2dec::Sign; @@ -41,12 +48,14 @@ } bb2: { - _6 = const MinusPlus; +- _6 = MinusPlus; ++ _6 = const MinusPlus; goto -> bb4; } bb3: { - _6 = const Minus; +- _6 = Minus; ++ _6 = const Minus; goto -> bb4; } @@ -65,30 +74,30 @@ bb6: { _10 = ((_7 as Some).0: usize); - StorageLive(_11); - _11 = _6; - StorageLive(_12); StorageLive(_13); - _13 = _10 as u32 (IntToInt); - _12 = Add(move _13, const 1_u32); - StorageDead(_13); - _0 = float_to_exponential_common_exact::(_1, _2, move _11, move _12, _3) -> [return: bb7, unwind unreachable]; + _13 = _6; + StorageLive(_14); + StorageLive(_15); + _15 = _10 as u32 (IntToInt); + _14 = Add(move _15, const 1_u32); + StorageDead(_15); + _0 = float_to_exponential_common_exact::(_1, _2, move _13, move _14, _3) -> [return: bb7, unwind unreachable]; } bb7: { - StorageDead(_12); - StorageDead(_11); + StorageDead(_14); + StorageDead(_13); goto -> bb10; } bb8: { - StorageLive(_14); - _14 = _6; - _0 = float_to_exponential_common_shortest::(_1, _2, move _14, _3) -> [return: bb9, unwind unreachable]; + StorageLive(_20); + _20 = _6; + _0 = float_to_exponential_common_shortest::(_1, _2, move _20, _3) -> [return: bb9, unwind unreachable]; } bb9: { - StorageDead(_14); + StorageDead(_20); goto -> bb10; } diff --git a/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-unwind.diff b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.panic-unwind.diff similarity index 68% rename from tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-unwind.diff rename to tests/mir-opt/funky_arms.float_to_exponential_common.GVN.panic-unwind.diff index 4f8b8dc7c60c8..e553dc7a7ae4e 100644 --- a/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `float_to_exponential_common` before ConstProp -+ // MIR for `float_to_exponential_common` after ConstProp +- // MIR for `float_to_exponential_common` before GVN ++ // MIR for `float_to_exponential_common` after GVN fn float_to_exponential_common(_1: &mut Formatter<'_>, _2: &T, _3: bool) -> Result<(), std::fmt::Error> { debug fmt => _1; @@ -11,10 +11,17 @@ let mut _7: std::option::Option; let mut _8: &std::fmt::Formatter<'_>; let mut _9: isize; - let mut _11: core::num::flt2dec::Sign; - let mut _12: u32; - let mut _13: u32; - let mut _14: core::num::flt2dec::Sign; + let mut _11: &mut std::fmt::Formatter<'_>; + let mut _12: &T; + let mut _13: core::num::flt2dec::Sign; + let mut _14: u32; + let mut _15: u32; + let mut _16: usize; + let mut _17: bool; + let mut _18: &mut std::fmt::Formatter<'_>; + let mut _19: &T; + let mut _20: core::num::flt2dec::Sign; + let mut _21: bool; scope 1 { debug force_sign => _4; let _6: core::num::flt2dec::Sign; @@ -41,12 +48,14 @@ } bb2: { - _6 = const MinusPlus; +- _6 = MinusPlus; ++ _6 = const MinusPlus; goto -> bb4; } bb3: { - _6 = const Minus; +- _6 = Minus; ++ _6 = const Minus; goto -> bb4; } @@ -65,30 +74,30 @@ bb6: { _10 = ((_7 as Some).0: usize); - StorageLive(_11); - _11 = _6; - StorageLive(_12); StorageLive(_13); - _13 = _10 as u32 (IntToInt); - _12 = Add(move _13, const 1_u32); - StorageDead(_13); - _0 = float_to_exponential_common_exact::(_1, _2, move _11, move _12, _3) -> [return: bb7, unwind continue]; + _13 = _6; + StorageLive(_14); + StorageLive(_15); + _15 = _10 as u32 (IntToInt); + _14 = Add(move _15, const 1_u32); + StorageDead(_15); + _0 = float_to_exponential_common_exact::(_1, _2, move _13, move _14, _3) -> [return: bb7, unwind continue]; } bb7: { - StorageDead(_12); - StorageDead(_11); + StorageDead(_14); + StorageDead(_13); goto -> bb10; } bb8: { - StorageLive(_14); - _14 = _6; - _0 = float_to_exponential_common_shortest::(_1, _2, move _14, _3) -> [return: bb9, unwind continue]; + StorageLive(_20); + _20 = _6; + _0 = float_to_exponential_common_shortest::(_1, _2, move _20, _3) -> [return: bb9, unwind continue]; } bb9: { - StorageDead(_14); + StorageDead(_20); goto -> bb10; } diff --git a/tests/mir-opt/funky_arms.rs b/tests/mir-opt/funky_arms.rs index 79fd9457ce1ec..f09c9b6c27ba6 100644 --- a/tests/mir-opt/funky_arms.rs +++ b/tests/mir-opt/funky_arms.rs @@ -8,7 +8,7 @@ extern crate core; use core::num::flt2dec; use std::fmt::{Formatter, Result}; -// EMIT_MIR funky_arms.float_to_exponential_common.ConstProp.diff +// EMIT_MIR funky_arms.float_to_exponential_common.GVN.diff pub fn float_to_exponential_common(fmt: &mut Formatter<'_>, num: &T, upper: bool) -> Result where T: flt2dec::DecodableFloat, diff --git a/tests/mir-opt/issue_101973.inner.ConstProp.panic-abort.diff b/tests/mir-opt/issue_101973.inner.ConstProp.panic-abort.diff deleted file mode 100644 index e9f492769d818..0000000000000 --- a/tests/mir-opt/issue_101973.inner.ConstProp.panic-abort.diff +++ /dev/null @@ -1,66 +0,0 @@ -- // MIR for `inner` before ConstProp -+ // MIR for `inner` after ConstProp - - fn inner(_1: u32) -> i64 { - debug fields => _1; - let mut _0: i64; - let mut _2: i32; - let mut _3: u32; - let mut _4: u32; - let mut _5: u32; - let mut _6: u32; - let mut _7: u32; - scope 1 (inlined imm8) { - debug x => _1; - let mut _8: u32; - let mut _9: u32; - scope 2 { - debug out => _4; - } - } - scope 3 (inlined core::num::::rotate_right) { - debug self => _4; - debug n => _5; - } - - bb0: { - StorageLive(_2); - StorageLive(_3); - StorageLive(_4); - StorageLive(_9); - StorageLive(_8); - _8 = Shr(_1, const 0_i32); - _9 = BitAnd(move _8, const 255_u32); - StorageDead(_8); - _4 = BitOr(const 0_u32, move _9); - StorageDead(_9); - StorageLive(_5); - StorageLive(_6); - StorageLive(_7); - assert(const true, "attempt to shift right by `{}`, which would overflow", const 8_i32) -> [success: bb1, unwind unreachable]; - } - - bb1: { - _7 = Shr(_1, const 8_i32); - _6 = BitAnd(move _7, const 15_u32); - StorageDead(_7); - assert(const true, "attempt to shift left by `{}`, which would overflow", const 1_i32) -> [success: bb2, unwind unreachable]; - } - - bb2: { - _5 = Shl(move _6, const 1_i32); - StorageDead(_6); - _3 = rotate_right::(move _4, move _5) -> [return: bb3, unwind unreachable]; - } - - bb3: { - StorageDead(_5); - StorageDead(_4); - _2 = move _3 as i32 (IntToInt); - StorageDead(_3); - _0 = move _2 as i64 (IntToInt); - StorageDead(_2); - return; - } - } - diff --git a/tests/mir-opt/issue_101973.inner.ConstProp.panic-unwind.diff b/tests/mir-opt/issue_101973.inner.ConstProp.panic-unwind.diff deleted file mode 100644 index c0b49ad6e6d4b..0000000000000 --- a/tests/mir-opt/issue_101973.inner.ConstProp.panic-unwind.diff +++ /dev/null @@ -1,66 +0,0 @@ -- // MIR for `inner` before ConstProp -+ // MIR for `inner` after ConstProp - - fn inner(_1: u32) -> i64 { - debug fields => _1; - let mut _0: i64; - let mut _2: i32; - let mut _3: u32; - let mut _4: u32; - let mut _5: u32; - let mut _6: u32; - let mut _7: u32; - scope 1 (inlined imm8) { - debug x => _1; - let mut _8: u32; - let mut _9: u32; - scope 2 { - debug out => _4; - } - } - scope 3 (inlined core::num::::rotate_right) { - debug self => _4; - debug n => _5; - } - - bb0: { - StorageLive(_2); - StorageLive(_3); - StorageLive(_4); - StorageLive(_9); - StorageLive(_8); - _8 = Shr(_1, const 0_i32); - _9 = BitAnd(move _8, const 255_u32); - StorageDead(_8); - _4 = BitOr(const 0_u32, move _9); - StorageDead(_9); - StorageLive(_5); - StorageLive(_6); - StorageLive(_7); - assert(const true, "attempt to shift right by `{}`, which would overflow", const 8_i32) -> [success: bb1, unwind continue]; - } - - bb1: { - _7 = Shr(_1, const 8_i32); - _6 = BitAnd(move _7, const 15_u32); - StorageDead(_7); - assert(const true, "attempt to shift left by `{}`, which would overflow", const 1_i32) -> [success: bb2, unwind continue]; - } - - bb2: { - _5 = Shl(move _6, const 1_i32); - StorageDead(_6); - _3 = rotate_right::(move _4, move _5) -> [return: bb3, unwind unreachable]; - } - - bb3: { - StorageDead(_5); - StorageDead(_4); - _2 = move _3 as i32 (IntToInt); - StorageDead(_3); - _0 = move _2 as i64 (IntToInt); - StorageDead(_2); - return; - } - } - diff --git a/tests/mir-opt/issue_101973.inner.GVN.panic-abort.diff b/tests/mir-opt/issue_101973.inner.GVN.panic-abort.diff new file mode 100644 index 0000000000000..6587b98c8c79e --- /dev/null +++ b/tests/mir-opt/issue_101973.inner.GVN.panic-abort.diff @@ -0,0 +1,82 @@ +- // MIR for `inner` before GVN ++ // MIR for `inner` after GVN + + fn inner(_1: u32) -> i64 { + debug fields => _1; + let mut _0: i64; + let mut _2: i32; + let mut _3: u32; + let mut _4: u32; + let mut _5: u32; + let mut _6: u32; + let mut _7: u32; + let mut _8: u32; + let mut _9: u32; + let mut _10: u32; + let mut _11: bool; + let mut _12: u32; + let mut _13: bool; + scope 1 (inlined imm8) { + debug x => _1; + let mut _14: u32; + let mut _15: u32; + scope 2 { + debug out => _4; + } + } + scope 3 (inlined core::num::::rotate_right) { + debug self => _4; + debug n => _6; + } + + bb0: { + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + StorageLive(_15); + StorageLive(_14); + _14 = Shr(_1, const 0_i32); + _15 = BitAnd(move _14, const 255_u32); + StorageDead(_14); + _4 = BitOr(const 0_u32, move _15); + StorageDead(_15); + StorageLive(_6); + StorageLive(_7); + StorageLive(_8); +- _10 = const 8_i32 as u32 (IntToInt); +- _11 = Lt(move _10, const 32_u32); +- assert(move _11, "attempt to shift right by `{}`, which would overflow", const 8_i32) -> [success: bb1, unwind unreachable]; ++ _10 = const 8_u32; ++ _11 = const true; ++ assert(const true, "attempt to shift right by `{}`, which would overflow", const 8_i32) -> [success: bb1, unwind unreachable]; + } + + bb1: { + _8 = Shr(_1, const 8_i32); + _7 = BitAnd(move _8, const 15_u32); + StorageDead(_8); +- _12 = const 1_i32 as u32 (IntToInt); +- _13 = Lt(move _12, const 32_u32); +- assert(move _13, "attempt to shift left by `{}`, which would overflow", const 1_i32) -> [success: bb2, unwind unreachable]; ++ _12 = const 1_u32; ++ _13 = const true; ++ assert(const true, "attempt to shift left by `{}`, which would overflow", const 1_i32) -> [success: bb2, unwind unreachable]; + } + + bb2: { + _6 = Shl(move _7, const 1_i32); + StorageDead(_7); + _3 = rotate_right::(move _4, move _6) -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_6); + StorageDead(_4); + _2 = move _3 as i32 (IntToInt); + StorageDead(_3); + _0 = move _2 as i64 (IntToInt); + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/issue_101973.inner.GVN.panic-unwind.diff b/tests/mir-opt/issue_101973.inner.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..934f3155cf25a --- /dev/null +++ b/tests/mir-opt/issue_101973.inner.GVN.panic-unwind.diff @@ -0,0 +1,82 @@ +- // MIR for `inner` before GVN ++ // MIR for `inner` after GVN + + fn inner(_1: u32) -> i64 { + debug fields => _1; + let mut _0: i64; + let mut _2: i32; + let mut _3: u32; + let mut _4: u32; + let mut _5: u32; + let mut _6: u32; + let mut _7: u32; + let mut _8: u32; + let mut _9: u32; + let mut _10: u32; + let mut _11: bool; + let mut _12: u32; + let mut _13: bool; + scope 1 (inlined imm8) { + debug x => _1; + let mut _14: u32; + let mut _15: u32; + scope 2 { + debug out => _4; + } + } + scope 3 (inlined core::num::::rotate_right) { + debug self => _4; + debug n => _6; + } + + bb0: { + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + StorageLive(_15); + StorageLive(_14); + _14 = Shr(_1, const 0_i32); + _15 = BitAnd(move _14, const 255_u32); + StorageDead(_14); + _4 = BitOr(const 0_u32, move _15); + StorageDead(_15); + StorageLive(_6); + StorageLive(_7); + StorageLive(_8); +- _10 = const 8_i32 as u32 (IntToInt); +- _11 = Lt(move _10, const 32_u32); +- assert(move _11, "attempt to shift right by `{}`, which would overflow", const 8_i32) -> [success: bb1, unwind continue]; ++ _10 = const 8_u32; ++ _11 = const true; ++ assert(const true, "attempt to shift right by `{}`, which would overflow", const 8_i32) -> [success: bb1, unwind continue]; + } + + bb1: { + _8 = Shr(_1, const 8_i32); + _7 = BitAnd(move _8, const 15_u32); + StorageDead(_8); +- _12 = const 1_i32 as u32 (IntToInt); +- _13 = Lt(move _12, const 32_u32); +- assert(move _13, "attempt to shift left by `{}`, which would overflow", const 1_i32) -> [success: bb2, unwind continue]; ++ _12 = const 1_u32; ++ _13 = const true; ++ assert(const true, "attempt to shift left by `{}`, which would overflow", const 1_i32) -> [success: bb2, unwind continue]; + } + + bb2: { + _6 = Shl(move _7, const 1_i32); + StorageDead(_7); + _3 = rotate_right::(move _4, move _6) -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_6); + StorageDead(_4); + _2 = move _3 as i32 (IntToInt); + StorageDead(_3); + _0 = move _2 as i64 (IntToInt); + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/issue_101973.rs b/tests/mir-opt/issue_101973.rs index 01b342f4dc3a5..6fe1799e4d5ef 100644 --- a/tests/mir-opt/issue_101973.rs +++ b/tests/mir-opt/issue_101973.rs @@ -1,6 +1,6 @@ // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // compile-flags: -O -C debug-assertions=on -// This needs inlining followed by ConstProp to reproduce, so we cannot use "unit-test". +// This needs inlining followed by GVN to reproduce, so we cannot use "unit-test". #[inline] pub fn imm8(x: u32) -> u32 { @@ -9,7 +9,7 @@ pub fn imm8(x: u32) -> u32 { out } -// EMIT_MIR issue_101973.inner.ConstProp.diff +// EMIT_MIR issue_101973.inner.GVN.diff #[inline(never)] pub fn inner(fields: u32) -> i64 { imm8(fields).rotate_right(((fields >> 8) & 0xf) << 1) as i32 as i64 diff --git a/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.mir index a5a07383a6b12..8774c30c5e864 100644 --- a/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.mir @@ -67,6 +67,6 @@ fn checked_shl(_1: u32, _2: u32) -> Option { } } -alloc8 (size: 8, align: 4) { +alloc7 (size: 8, align: 4) { 00 00 00 00 __ __ __ __ │ ....░░░░ } diff --git a/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir index 5d58bdb9e7392..761e2023d99f1 100644 --- a/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir @@ -116,6 +116,6 @@ fn int_range(_1: usize, _2: usize) -> () { } } -alloc11 (size: 16, align: 8) { +alloc7 (size: 16, align: 8) { 00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ │ ........░░░░░░░░ } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-abort.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-abort.diff deleted file mode 100644 index 4c26145e5752d..0000000000000 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-abort.diff +++ /dev/null @@ -1,47 +0,0 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp - - fn main() -> () { - let mut _0: (); - let _1: i32; - let mut _3: [i32; 6]; - let _4: usize; - let mut _5: u32; - scope 1 { - debug x => _1; - let _2: i32; - scope 2 { - debug y => _2; - scope 3 { - debug z => _5; - } - } - } - - bb0: { - StorageLive(_1); - assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind unreachable]; - } - - bb1: { - _1 = const 4_i32; - StorageLive(_2); - StorageLive(_3); - _3 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32]; - StorageLive(_4); - _4 = const 3_usize; - assert(const true, "index out of bounds: the length is {} but the index is {}", const 6_usize, const 3_usize) -> [success: bb2, unwind unreachable]; - } - - bb2: { -- _2 = _3[_4]; -+ _2 = const 3_i32; - StorageDead(_4); - StorageDead(_3); - _5 = const 42_u32; - StorageDead(_2); - StorageDead(_1); - return; - } - } - diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-unwind.diff deleted file mode 100644 index 2a0bc5dcfd8dd..0000000000000 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-unwind.diff +++ /dev/null @@ -1,47 +0,0 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp - - fn main() -> () { - let mut _0: (); - let _1: i32; - let mut _3: [i32; 6]; - let _4: usize; - let mut _5: u32; - scope 1 { - debug x => _1; - let _2: i32; - scope 2 { - debug y => _2; - scope 3 { - debug z => _5; - } - } - } - - bb0: { - StorageLive(_1); - assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind continue]; - } - - bb1: { - _1 = const 4_i32; - StorageLive(_2); - StorageLive(_3); - _3 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32]; - StorageLive(_4); - _4 = const 3_usize; - assert(const true, "index out of bounds: the length is {} but the index is {}", const 6_usize, const 3_usize) -> [success: bb2, unwind continue]; - } - - bb2: { -- _2 = _3[_4]; -+ _2 = const 3_i32; - StorageDead(_4); - StorageDead(_3); - _5 = const 42_u32; - StorageDead(_2); - StorageDead(_1); - return; - } - } - diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-abort.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-abort.diff deleted file mode 100644 index 4c26145e5752d..0000000000000 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-abort.diff +++ /dev/null @@ -1,47 +0,0 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp - - fn main() -> () { - let mut _0: (); - let _1: i32; - let mut _3: [i32; 6]; - let _4: usize; - let mut _5: u32; - scope 1 { - debug x => _1; - let _2: i32; - scope 2 { - debug y => _2; - scope 3 { - debug z => _5; - } - } - } - - bb0: { - StorageLive(_1); - assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind unreachable]; - } - - bb1: { - _1 = const 4_i32; - StorageLive(_2); - StorageLive(_3); - _3 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32]; - StorageLive(_4); - _4 = const 3_usize; - assert(const true, "index out of bounds: the length is {} but the index is {}", const 6_usize, const 3_usize) -> [success: bb2, unwind unreachable]; - } - - bb2: { -- _2 = _3[_4]; -+ _2 = const 3_i32; - StorageDead(_4); - StorageDead(_3); - _5 = const 42_u32; - StorageDead(_2); - StorageDead(_1); - return; - } - } - diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-unwind.diff deleted file mode 100644 index 2a0bc5dcfd8dd..0000000000000 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-unwind.diff +++ /dev/null @@ -1,47 +0,0 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp - - fn main() -> () { - let mut _0: (); - let _1: i32; - let mut _3: [i32; 6]; - let _4: usize; - let mut _5: u32; - scope 1 { - debug x => _1; - let _2: i32; - scope 2 { - debug y => _2; - scope 3 { - debug z => _5; - } - } - } - - bb0: { - StorageLive(_1); - assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind continue]; - } - - bb1: { - _1 = const 4_i32; - StorageLive(_2); - StorageLive(_3); - _3 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32]; - StorageLive(_4); - _4 = const 3_usize; - assert(const true, "index out of bounds: the length is {} but the index is {}", const 6_usize, const 3_usize) -> [success: bb2, unwind continue]; - } - - bb2: { -- _2 = _3[_4]; -+ _2 = const 3_i32; - StorageDead(_4); - StorageDead(_3); - _5 = const 42_u32; - StorageDead(_2); - StorageDead(_1); - return; - } - } - diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-abort.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-abort.diff new file mode 100644 index 0000000000000..45ebd482d9eb9 --- /dev/null +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-abort.diff @@ -0,0 +1,62 @@ +- // MIR for `main` before GVN ++ // MIR for `main` after GVN + + fn main() -> () { + let mut _0: (); + let _1: i32; + let mut _2: (i32, bool); + let mut _4: [i32; 6]; + let _5: usize; + let mut _6: usize; + let mut _7: bool; + let mut _9: u32; + scope 1 { + debug x => _1; + let _3: i32; + scope 2 { + debug y => _3; + let _8: u32; + scope 3 { + debug z => _9; + } + } + } + + bb0: { + StorageLive(_1); +- _2 = CheckedAdd(const 2_i32, const 2_i32); +- assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind unreachable]; ++ _2 = const (4_i32, false); ++ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind unreachable]; + } + + bb1: { +- _1 = move (_2.0: i32); ++ _1 = const 4_i32; + StorageLive(_3); + StorageLive(_4); + _4 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32]; + StorageLive(_5); + _5 = const 3_usize; + _6 = const 6_usize; +- _7 = Lt(_5, _6); +- assert(move _7, "index out of bounds: the length is {} but the index is {}", move _6, _5) -> [success: bb2, unwind unreachable]; ++ _7 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 6_usize, const 3_usize) -> [success: bb2, unwind unreachable]; + } + + bb2: { + _3 = _4[_5]; + StorageDead(_5); + StorageDead(_4); + _9 = const 42_u32; + StorageDead(_3); + StorageDead(_1); + return; + } ++ } ++ ++ alloc5 (size: 8, align: 4) { ++ 04 00 00 00 00 __ __ __ │ .....░░░ + } + diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-unwind.diff new file mode 100644 index 0000000000000..d97b781258662 --- /dev/null +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-unwind.diff @@ -0,0 +1,62 @@ +- // MIR for `main` before GVN ++ // MIR for `main` after GVN + + fn main() -> () { + let mut _0: (); + let _1: i32; + let mut _2: (i32, bool); + let mut _4: [i32; 6]; + let _5: usize; + let mut _6: usize; + let mut _7: bool; + let mut _9: u32; + scope 1 { + debug x => _1; + let _3: i32; + scope 2 { + debug y => _3; + let _8: u32; + scope 3 { + debug z => _9; + } + } + } + + bb0: { + StorageLive(_1); +- _2 = CheckedAdd(const 2_i32, const 2_i32); +- assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind continue]; ++ _2 = const (4_i32, false); ++ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind continue]; + } + + bb1: { +- _1 = move (_2.0: i32); ++ _1 = const 4_i32; + StorageLive(_3); + StorageLive(_4); + _4 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32]; + StorageLive(_5); + _5 = const 3_usize; + _6 = const 6_usize; +- _7 = Lt(_5, _6); +- assert(move _7, "index out of bounds: the length is {} but the index is {}", move _6, _5) -> [success: bb2, unwind continue]; ++ _7 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 6_usize, const 3_usize) -> [success: bb2, unwind continue]; + } + + bb2: { + _3 = _4[_5]; + StorageDead(_5); + StorageDead(_4); + _9 = const 42_u32; + StorageDead(_3); + StorageDead(_1); + return; + } ++ } ++ ++ alloc5 (size: 8, align: 4) { ++ 04 00 00 00 00 __ __ __ │ .....░░░ + } + diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.64bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.64bit.panic-unwind.diff new file mode 100644 index 0000000000000..d97b781258662 --- /dev/null +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.64bit.panic-unwind.diff @@ -0,0 +1,62 @@ +- // MIR for `main` before GVN ++ // MIR for `main` after GVN + + fn main() -> () { + let mut _0: (); + let _1: i32; + let mut _2: (i32, bool); + let mut _4: [i32; 6]; + let _5: usize; + let mut _6: usize; + let mut _7: bool; + let mut _9: u32; + scope 1 { + debug x => _1; + let _3: i32; + scope 2 { + debug y => _3; + let _8: u32; + scope 3 { + debug z => _9; + } + } + } + + bb0: { + StorageLive(_1); +- _2 = CheckedAdd(const 2_i32, const 2_i32); +- assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind continue]; ++ _2 = const (4_i32, false); ++ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind continue]; + } + + bb1: { +- _1 = move (_2.0: i32); ++ _1 = const 4_i32; + StorageLive(_3); + StorageLive(_4); + _4 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32]; + StorageLive(_5); + _5 = const 3_usize; + _6 = const 6_usize; +- _7 = Lt(_5, _6); +- assert(move _7, "index out of bounds: the length is {} but the index is {}", move _6, _5) -> [success: bb2, unwind continue]; ++ _7 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 6_usize, const 3_usize) -> [success: bb2, unwind continue]; + } + + bb2: { + _3 = _4[_5]; + StorageDead(_5); + StorageDead(_4); + _9 = const 42_u32; + StorageDead(_3); + StorageDead(_1); + return; + } ++ } ++ ++ alloc5 (size: 8, align: 4) { ++ 04 00 00 00 00 __ __ __ │ .....░░░ + } + diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-abort.mir b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-abort.mir index 681dadff302b9..e98b6b720230b 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-abort.mir @@ -4,8 +4,9 @@ fn main() -> () { let mut _0: (); scope 1 { debug x => const 4_i32; + let _1: i32; scope 2 { - debug y => const 3_i32; + debug y => _1; scope 3 { debug z => const 42_u32; } @@ -13,6 +14,8 @@ fn main() -> () { } bb0: { + StorageLive(_1); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-unwind.mir index 681dadff302b9..e98b6b720230b 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-unwind.mir @@ -4,8 +4,9 @@ fn main() -> () { let mut _0: (); scope 1 { debug x => const 4_i32; + let _1: i32; scope 2 { - debug y => const 3_i32; + debug y => _1; scope 3 { debug z => const 42_u32; } @@ -13,6 +14,8 @@ fn main() -> () { } bb0: { + StorageLive(_1); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.64bit.panic-abort.mir b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.64bit.panic-abort.mir index 681dadff302b9..e98b6b720230b 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.64bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.64bit.panic-abort.mir @@ -4,8 +4,9 @@ fn main() -> () { let mut _0: (); scope 1 { debug x => const 4_i32; + let _1: i32; scope 2 { - debug y => const 3_i32; + debug y => _1; scope 3 { debug z => const 42_u32; } @@ -13,6 +14,8 @@ fn main() -> () { } bb0: { + StorageLive(_1); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.64bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.64bit.panic-unwind.mir index 681dadff302b9..e98b6b720230b 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.64bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.64bit.panic-unwind.mir @@ -4,8 +4,9 @@ fn main() -> () { let mut _0: (); scope 1 { debug x => const 4_i32; + let _1: i32; scope 2 { - debug y => const 3_i32; + debug y => _1; scope 3 { debug z => const 42_u32; } @@ -13,6 +14,8 @@ fn main() -> () { } bb0: { + StorageLive(_1); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.32bit.panic-abort.mir b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.32bit.panic-abort.mir index 425b95db3363a..6045e890e9831 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.32bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.32bit.panic-abort.mir @@ -4,8 +4,9 @@ fn main() -> () { let mut _0: (); scope 1 { debug x => const 4_i32; + let _1: i32; scope 2 { - debug y => const 3_i32; + debug y => _1; scope 3 { debug z => const 42_u32; } @@ -13,6 +14,8 @@ fn main() -> () { } bb0: { + StorageLive(_1); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.32bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.32bit.panic-unwind.mir index 425b95db3363a..6045e890e9831 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.32bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.32bit.panic-unwind.mir @@ -4,8 +4,9 @@ fn main() -> () { let mut _0: (); scope 1 { debug x => const 4_i32; + let _1: i32; scope 2 { - debug y => const 3_i32; + debug y => _1; scope 3 { debug z => const 42_u32; } @@ -13,6 +14,8 @@ fn main() -> () { } bb0: { + StorageLive(_1); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.64bit.panic-abort.mir b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.64bit.panic-abort.mir index 425b95db3363a..6045e890e9831 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.64bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.64bit.panic-abort.mir @@ -4,8 +4,9 @@ fn main() -> () { let mut _0: (); scope 1 { debug x => const 4_i32; + let _1: i32; scope 2 { - debug y => const 3_i32; + debug y => _1; scope 3 { debug z => const 42_u32; } @@ -13,6 +14,8 @@ fn main() -> () { } bb0: { + StorageLive(_1); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.64bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.64bit.panic-unwind.mir index 425b95db3363a..6045e890e9831 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.64bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.64bit.panic-unwind.mir @@ -4,8 +4,9 @@ fn main() -> () { let mut _0: (); scope 1 { debug x => const 4_i32; + let _1: i32; scope 2 { - debug y => const 3_i32; + debug y => _1; scope 3 { debug z => const 42_u32; } @@ -13,6 +14,8 @@ fn main() -> () { } bb0: { + StorageLive(_1); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.rs b/tests/mir-opt/pre-codegen/optimizes_into_variable.rs index 704f8f887e3ea..cdfc0f620a2ba 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.rs +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.rs @@ -8,7 +8,7 @@ struct Point { // EMIT_MIR_FOR_EACH_BIT_WIDTH // EMIT_MIR optimizes_into_variable.main.ScalarReplacementOfAggregates.diff -// EMIT_MIR optimizes_into_variable.main.ConstProp.diff +// EMIT_MIR optimizes_into_variable.main.GVN.diff // EMIT_MIR optimizes_into_variable.main.SimplifyLocals-final.after.mir // EMIT_MIR optimizes_into_variable.main.PreCodegen.after.mir fn main() { diff --git a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir index 04cd61aced593..f90531ed97a74 100644 --- a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir @@ -70,6 +70,6 @@ fn range_iter_next(_1: &mut std::ops::Range) -> Option { } } -alloc17 (size: 8, align: 4) { +alloc9 (size: 8, align: 4) { 00 00 00 00 __ __ __ __ │ ....░░░░ } diff --git a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir index f766699c3e74d..8e255e322acf3 100644 --- a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir @@ -70,6 +70,6 @@ fn range_iter_next(_1: &mut std::ops::Range) -> Option { } } -alloc17 (size: 8, align: 4) { +alloc9 (size: 8, align: 4) { 00 00 00 00 __ __ __ __ │ ....░░░░ } diff --git a/tests/mir-opt/pre-codegen/simple_option_map.ezmap.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/simple_option_map.ezmap.PreCodegen.after.mir index 116e64170d16d..a575bfcf7a215 100644 --- a/tests/mir-opt/pre-codegen/simple_option_map.ezmap.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/simple_option_map.ezmap.PreCodegen.after.mir @@ -45,6 +45,6 @@ fn ezmap(_1: Option) -> Option { } } -alloc18 (size: 8, align: 4) { +alloc14 (size: 8, align: 4) { 00 00 00 00 __ __ __ __ │ ....░░░░ } diff --git a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir index 2ba456dcb206c..6ba6d7d8831e5 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir @@ -145,6 +145,6 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } } -alloc24 (size: 16, align: 8) { +alloc16 (size: 16, align: 8) { 00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ │ ........░░░░░░░░ } diff --git a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir index 25df1aeff7934..a4ed902fa4de6 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir @@ -153,6 +153,6 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } } -alloc24 (size: 16, align: 8) { +alloc16 (size: 16, align: 8) { 00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ │ ........░░░░░░░░ } diff --git a/tests/mir-opt/simplify_match.main.ConstProp.panic-unwind.diff b/tests/mir-opt/simplify_match.main.ConstProp.panic-unwind.diff deleted file mode 100644 index 2d60e234e066d..0000000000000 --- a/tests/mir-opt/simplify_match.main.ConstProp.panic-unwind.diff +++ /dev/null @@ -1,28 +0,0 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp - - fn main() -> () { - let mut _0: (); - let _1: bool; - scope 1 { - debug x => _1; - } - - bb0: { - _1 = const false; - switchInt(const false) -> [0: bb1, otherwise: bb2]; - } - - bb1: { - goto -> bb3; - } - - bb2: { - _0 = noop() -> [return: bb3, unwind continue]; - } - - bb3: { - return; - } - } - diff --git a/tests/mir-opt/simplify_match.main.ConstProp.panic-abort.diff b/tests/mir-opt/simplify_match.main.GVN.panic-abort.diff similarity index 50% rename from tests/mir-opt/simplify_match.main.ConstProp.panic-abort.diff rename to tests/mir-opt/simplify_match.main.GVN.panic-abort.diff index 2bb54d5a66694..825babe7994ac 100644 --- a/tests/mir-opt/simplify_match.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/simplify_match.main.GVN.panic-abort.diff @@ -1,16 +1,18 @@ -- // MIR for `main` before ConstProp -+ // MIR for `main` after ConstProp +- // MIR for `main` before GVN ++ // MIR for `main` after GVN fn main() -> () { let mut _0: (); - let _1: bool; + let mut _1: bool; + let _2: bool; scope 1 { - debug x => _1; + debug x => _2; } bb0: { - _1 = const false; - switchInt(const false) -> [0: bb1, otherwise: bb2]; + _2 = const false; +- switchInt(_2) -> [0: bb1, otherwise: bb2]; ++ switchInt(const false) -> [0: bb1, otherwise: bb2]; } bb1: { diff --git a/tests/mir-opt/simplify_match.main.GVN.panic-unwind.diff b/tests/mir-opt/simplify_match.main.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..24ab6c39788fa --- /dev/null +++ b/tests/mir-opt/simplify_match.main.GVN.panic-unwind.diff @@ -0,0 +1,30 @@ +- // MIR for `main` before GVN ++ // MIR for `main` after GVN + + fn main() -> () { + let mut _0: (); + let mut _1: bool; + let _2: bool; + scope 1 { + debug x => _2; + } + + bb0: { + _2 = const false; +- switchInt(_2) -> [0: bb1, otherwise: bb2]; ++ switchInt(const false) -> [0: bb1, otherwise: bb2]; + } + + bb1: { + goto -> bb3; + } + + bb2: { + _0 = noop() -> [return: bb3, unwind continue]; + } + + bb3: { + return; + } + } + diff --git a/tests/mir-opt/simplify_match.rs b/tests/mir-opt/simplify_match.rs index 5d8e94b093568..1782c2f31cce5 100644 --- a/tests/mir-opt/simplify_match.rs +++ b/tests/mir-opt/simplify_match.rs @@ -2,7 +2,7 @@ #[inline(never)] fn noop() {} -// EMIT_MIR simplify_match.main.ConstProp.diff +// EMIT_MIR simplify_match.main.GVN.diff fn main() { match { let x = false; x } { true => noop(), From 81d5ac44a193330c06fdfc4ea0112d5590ad89f6 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 23 Sep 2023 09:57:13 +0000 Subject: [PATCH 18/18] Bless coverage. --- tests/coverage-map/status-quo/async2.cov-map | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/coverage-map/status-quo/async2.cov-map b/tests/coverage-map/status-quo/async2.cov-map index fe74dcd88403f..bc054352c4449 100644 --- a/tests/coverage-map/status-quo/async2.cov-map +++ b/tests/coverage-map/status-quo/async2.cov-map @@ -7,19 +7,17 @@ Number of file 0 mappings: 1 - Code(Counter(0)) at (prev + 11, 1) to (start + 0, 23) Function name: async2::async_func::{closure#0} -Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 0b, 17, 03, 09, 05, 03, 0a, 02, 06, 02, 02, 06, 00, 07, 07, 01, 01, 00, 02] +Raw bytes (26): 0x[01, 01, 01, 05, 00, 04, 01, 0b, 17, 03, 09, 05, 03, 0a, 02, 06, 00, 02, 06, 00, 07, 03, 01, 01, 00, 02] Number of files: 1 - file 0 => global file 1 -Number of expressions: 2 -- expression 0 operands: lhs = Counter(0), rhs = Counter(1) -- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of expressions: 1 +- expression 0 operands: lhs = Counter(1), rhs = Zero Number of file 0 mappings: 4 - Code(Counter(0)) at (prev + 11, 23) to (start + 3, 9) - Code(Counter(1)) at (prev + 3, 10) to (start + 2, 6) -- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7) - = (c0 - c1) -- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2) - = (c1 + (c0 - c1)) +- Code(Zero) at (prev + 2, 6) to (start + 0, 7) +- Code(Expression(0, Add)) at (prev + 1, 1) to (start + 0, 2) + = (c1 + Zero) Function name: async2::async_func_just_println Raw bytes (9): 0x[01, 01, 00, 01, 01, 13, 01, 00, 24]