diff --git a/compiler/rustc_const_eval/src/interpret/discriminant.rs b/compiler/rustc_const_eval/src/interpret/discriminant.rs index 8dab45d65ee11..fd17367037438 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 coroutines). -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/intern.rs b/compiler/rustc_const_eval/src/interpret/intern.rs index fd89e34204f0c..3d90e95c09c79 100644 --- a/compiler/rustc_const_eval/src/interpret/intern.rs +++ b/compiler/rustc_const_eval/src/interpret/intern.rs @@ -450,6 +450,42 @@ pub fn intern_const_alloc_recursive< Ok(()) } +/// Intern `ret`. This function assumes that `ret` references no other allocation. +#[instrument(level = "debug", skip(ecx))] +pub fn intern_const_alloc_for_constprop< + 'mir, + 'tcx: 'mir, + T, + M: CompileTimeMachine<'mir, 'tcx, T>, +>( + ecx: &mut InterpCx<'mir, 'tcx, M>, + alloc_id: AllocId, +) -> InterpResult<'tcx, ()> { + // Move allocation to `tcx`. + let Some((_, mut alloc)) = ecx.memory.alloc_map.remove(&alloc_id) else { + // Pointer not found in local memory map. It is either a pointer to the global + // map, or dangling. + if ecx.tcx.try_get_global_alloc(alloc_id).is_none() { + throw_ub!(DeadLocal) + } + // The constant is already in global memory. Do nothing. + return Ok(()); + }; + + alloc.mutability = Mutability::Not; + + // We are not doing recursive interning, so we don't currently support provenance. + // (If this assertion ever triggers, we should just implement a + // proper recursive interning loop.) + assert!(alloc.provenance().ptrs().is_empty()); + + // Link the alloc id to the actual allocation + let alloc = ecx.tcx.mk_const_alloc(alloc); + ecx.tcx.set_alloc_id_memory(alloc_id, alloc); + + Ok(()) +} + impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx, !>> InterpCx<'mir, 'tcx, M> { diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index c97207a61ac3b..c48857fcf3cd2 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -218,7 +218,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/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index d7c7e27984966..16905e93bf1f8 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -1011,7 +1011,7 @@ impl<'tcx, 'a, Prov: Provenance, Extra, Bytes: AllocBytes> AllocRef<'a, 'tcx, Pr } /// Returns whether the allocation has provenance anywhere in the range of the `AllocRef`. - pub(crate) fn has_provenance(&self) -> bool { + pub fn has_provenance(&self) -> bool { !self.alloc.provenance().range_empty(self.range, &self.tcx) } } diff --git a/compiler/rustc_const_eval/src/interpret/mod.rs b/compiler/rustc_const_eval/src/interpret/mod.rs index 13664456987e9..7d286d103adfe 100644 --- a/compiler/rustc_const_eval/src/interpret/mod.rs +++ b/compiler/rustc_const_eval/src/interpret/mod.rs @@ -21,7 +21,9 @@ mod visitor; pub use rustc_middle::mir::interpret::*; // have all the `interpret` symbols in one place: here pub use self::eval_context::{Frame, FrameInfo, InterpCx, StackPopCleanup}; -pub use self::intern::{intern_const_alloc_recursive, InternKind}; +pub use self::intern::{ + intern_const_alloc_for_constprop, intern_const_alloc_recursive, InternKind, +}; pub use self::machine::{compile_time_machine, AllocMap, Machine, MayLeak, StackPopJump}; pub use self::memory::{AllocKind, AllocRef, AllocRefMut, FnVal, Memory, MemoryKind}; pub use self::operand::{ImmTy, Immediate, OpTy, Readable}; diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index 6716888290dc1..255dd1eba97f2 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -169,6 +169,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 79cbda545f1f4..8c34d05042b1d 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -297,7 +297,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 4e429f316e806..3cb2e349ce084 100644 --- a/compiler/rustc_middle/src/mir/consts.rs +++ b/compiler/rustc_middle/src/mir/consts.rs @@ -172,6 +172,24 @@ impl<'tcx> ConstValue<'tcx> { let end = end.try_into().unwrap(); Some(data.inner().inspect_with_uninit_and_ptr_outside_interpreter(start..end)) } + + /// Check if a constant may contain provenance information. This is used by MIR opts. + /// Can return `true` even if there is no provenance. + pub fn may_have_provenance(&self, tcx: TyCtxt<'tcx>, size: Size) -> bool { + match *self { + ConstValue::ZeroSized | ConstValue::Scalar(Scalar::Int(_)) => return false, + ConstValue::Scalar(Scalar::Ptr(..)) => return true, + // It's hard to find out the part of the allocation we point to; + // just conservatively check everything. + ConstValue::Slice { data, meta: _ } => !data.inner().provenance().ptrs().is_empty(), + ConstValue::Indirect { alloc_id, offset } => !tcx + .global_alloc(alloc_id) + .unwrap_memory() + .inner() + .provenance() + .range_empty(super::AllocRange::from(offset..offset + size), &tcx), + } + } } /////////////////////////////////////////////////////////////////////////// @@ -485,6 +503,38 @@ impl<'tcx> Const<'tcx> { _ => Self::Ty(c), } } + + /// Return true if any evaluation of this constant always returns the same value, + /// taking into account even pointer identity tests. + pub fn is_deterministic(&self) -> bool { + // Some constants may generate fresh allocations for pointers they contain, + // so using the same constant twice can yield two different results: + // - valtrees purposefully generate new allocations + // - ConstValue::Slice also generate new allocations + match self { + Const::Ty(c) => match c.kind() { + ty::ConstKind::Param(..) => true, + // A valtree may be a reference. Valtree references correspond to a + // different allocation each time they are evaluated. Valtrees for primitive + // types are fine though. + ty::ConstKind::Value(_) => c.ty().is_primitive(), + ty::ConstKind::Unevaluated(..) | ty::ConstKind::Expr(..) => false, + // Should not appear in runtime MIR. + ty::ConstKind::Infer(..) + | ty::ConstKind::Bound(..) + | ty::ConstKind::Placeholder(..) + | ty::ConstKind::Error(..) => bug!(), + }, + Const::Unevaluated(..) => false, + // 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 { .. }, _) => false, + Const::Val( + ConstValue::ZeroSized | ConstValue::Scalar(_) | ConstValue::Indirect { .. }, + _, + ) => true, + } + } } /// An unevaluated (potentially generic) constant used in MIR. diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index 2c29978173ff5..fd067cb234bdb 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()) } @@ -854,7 +856,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>); diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index eece7c3e83412..de0dc25808b30 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -52,19 +52,59 @@ //! _a = *_b // _b is &Freeze //! _c = *_b // replaced by _c = _a //! ``` +//! +//! # Determinism of constant propagation +//! +//! When registering a new `Value`, we attempt to opportunistically evaluate it as a constant. +//! The evaluated form is inserted in `evaluated` as an `OpTy` or `None` if evaluation failed. +//! +//! The difficulty is non-deterministic evaluation of MIR constants. Some `Const` can have +//! different runtime values each time they are evaluated. This is the case with +//! `Const::Slice` which have a new pointer each time they are evaluated, and constants that +//! contain a fn pointer (`AllocId` pointing to a `GlobalAlloc::Function`) pointing to a different +//! symbol in each codegen unit. +//! +//! Meanwhile, we want to be able to read indirect constants. For instance: +//! ``` +//! static A: &'static &'static u8 = &&63; +//! fn foo() -> u8 { +//! **A // We want to replace by 63. +//! } +//! fn bar() -> u8 { +//! b"abc"[1] // We want to replace by 'b'. +//! } +//! ``` +//! +//! The `Value::Constant` variant stores a possibly unevaluated constant. Evaluating that constant +//! may be non-deterministic. When that happens, we assign a disambiguator to ensure that we do not +//! merge the constants. See `duplicate_slice` test in `gvn.rs`. +//! +//! Second, when writing constants in MIR, we do not write `Const::Slice` or `Const` +//! that contain `AllocId`s. +use rustc_const_eval::interpret::{intern_const_alloc_for_constprop, MemoryKind}; +use rustc_const_eval::interpret::{ImmTy, InterpCx, OpTy, Projectable, Scalar}; use rustc_data_structures::fx::{FxHashMap, FxIndexSet}; use rustc_data_structures::graph::dominators::Dominators; +use rustc_hir::def::DefKind; 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::adjustment::PointerCoercion; +use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeAndMut}; +use rustc_span::def_id::DefId; +use rustc_span::DUMMY_SP; +use rustc_target::abi::{self, Abi, Size, VariantIdx, FIRST_VARIANT}; +use std::borrow::Cow; +use crate::dataflow_const_prop::DummyMachine; use crate::ssa::{AssignedValue, SsaLocals}; use crate::MirPass; +use either::Either; pub struct GVN; @@ -118,22 +158,33 @@ 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! { struct VnIndex {} } +/// Computing the aggregate's type can be quite slow, so we only keep the minimal amount of +/// information to reconstruct it when needed. +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +enum AggregateTy<'tcx> { + /// Invariant: this must not be used for an empty array. + Array, + Tuple, + Def(DefId, ty::GenericArgsRef<'tcx>), +} + +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +enum AddressKind { + Ref(BorrowKind), + Address(Mutability), +} + #[derive(Debug, PartialEq, Eq, Hash)] enum Value<'tcx> { // Root values. @@ -141,15 +192,21 @@ enum Value<'tcx> { /// The `usize` is a counter incremented by `new_opaque`. Opaque(usize), /// Evaluated or unevaluated constant value. - Constant(Const<'tcx>), + Constant { + value: Const<'tcx>, + /// Some constants do not have a deterministic value. To avoid merging two instances of the + /// same `Const`, we assign them an additional integer index. + disambiguator: usize, + }, /// 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), + Aggregate(AggregateTy<'tcx>, VariantIdx, Vec), /// This corresponds to a `[value; count]` expression. Repeat(VnIndex, ty::Const<'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, }, @@ -177,6 +234,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. @@ -184,13 +242,14 @@ 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, ssa: &'body SsaLocals, dominators: &'body Dominators, reused_locals: BitSet, - any_replacement: bool, } impl<'body, 'tcx> VnState<'body, 'tcx> { @@ -203,23 +262,30 @@ 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, reused_locals: BitSet::new_empty(local_decls.len()), - any_replacement: false, } } #[instrument(level = "trace", skip(self), ret)] fn insert(&mut self, value: Value<'tcx>) -> VnIndex { - let (index, _) = self.values.insert_full(value); - VnIndex::from_usize(index) + 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 @@ -234,9 +300,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)) } @@ -258,6 +324,343 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { } } + fn insert_constant(&mut self, value: Const<'tcx>) -> Option { + let disambiguator = if value.is_deterministic() { + // The constant is deterministic, no need to disambiguate. + 0 + } else { + // Multiple mentions of this constant will yield different values, + // so assign a different `disambiguator` to ensure they do not get the same `VnIndex`. + let next_opaque = self.next_opaque.as_mut()?; + let disambiguator = *next_opaque; + *next_opaque += 1; + disambiguator + }; + Some(self.insert(Value::Constant { value, disambiguator })) + } + + fn insert_scalar(&mut self, scalar: Scalar, ty: Ty<'tcx>) -> VnIndex { + self.insert_constant(Const::from_scalar(self.tcx, scalar, ty)) + .expect("scalars are deterministic") + } + + #[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 value, disambiguator: _ } => { + self.ecx.eval_mir_constant(value, None, None).ok()? + } + Aggregate(kind, variant, ref fields) => { + let fields = fields + .iter() + .map(|&f| self.evaluated[f].as_ref()) + .collect::>>()?; + let ty = match kind { + AggregateTy::Array => { + assert!(fields.len() > 0); + Ty::new_array(self.tcx, fields[0].layout.ty, fields.len() as u64) + } + AggregateTy::Tuple => { + Ty::new_tup_from_iter(self.tcx, fields.iter().map(|f| f.layout.ty)) + } + AggregateTy::Def(def_id, args) => { + self.tcx.type_of(def_id).instantiate(self.tcx, args) + } + }; + let variant = if ty.is_enum() { Some(variant) } else { None }; + let ty = self.ecx.layout_of(ty).ok()?; + if ty.is_zst() { + ImmTy::uninit(ty).into() + } else if matches!(ty.abi, Abi::Scalar(..) | Abi::ScalarPair(..)) { + let dest = self.ecx.allocate(ty, MemoryKind::Stack).ok()?; + let variant_dest = if let Some(variant) = variant { + self.ecx.project_downcast(&dest, variant).ok()? + } else { + dest.clone() + }; + for (field_index, op) in fields.into_iter().enumerate() { + let field_dest = self.ecx.project_field(&variant_dest, field_index).ok()?; + self.ecx.copy_op(op, &field_dest, /*allow_transmute*/ false).ok()?; + } + self.ecx.write_discriminant(variant.unwrap_or(FIRST_VARIANT), &dest).ok()?; + self.ecx.alloc_mark_immutable(dest.ptr().provenance.unwrap()).ok()?; + dest.into() + } else { + return None; + } + } + + 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), + ProjectionElem::Subtype(ty) => ProjectionElem::Subtype(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()?; + // `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 (value.layout.abi, to.abi) { + (Abi::Scalar(..), Abi::Scalar(..)) => {} + (Abi::ScalarPair(..), Abi::ScalarPair(..)) => {} + _ => return None, + } + } + value.offset(Size::ZERO, to, &self.ecx).ok()? + } + _ => return None, + }, + }; + Some(op) + } + + fn project( + &mut self, + place: PlaceRef<'tcx>, + value: VnIndex, + proj: PlaceElem<'tcx>, + ) -> Option { + let proj = match proj { + ProjectionElem::Deref => { + let ty = place.ty(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::Downcast(name, index) => ProjectionElem::Downcast(name, index), + ProjectionElem::Field(f, ty) => { + if let Value::Aggregate(_, _, fields) = self.get(value) { + return Some(fields[f.as_usize()]); + } else if let Value::Projection(outer_value, ProjectionElem::Downcast(_, read_variant)) = self.get(value) + && let Value::Aggregate(_, written_variant, fields) = self.get(*outer_value) + // This pass is not aware of control-flow, so we do not know whether the + // replacement we are doing is actually reachable. We could be in any arm of + // ``` + // match Some(x) { + // Some(y) => /* stuff */, + // None => /* other */, + // } + // ``` + // + // In surface rust, the current statement would be unreachable. + // + // However, from the reference chapter on enums and RFC 2195, + // accessing the wrong variant is not UB if the enum has repr. + // So it's not impossible for a series of MIR opts to generate + // a downcast to an inactive variant. + && written_variant == read_variant + { + return Some(fields[f.as_usize()]); + } + ProjectionElem::Field(f, ty) + } + ProjectionElem::Index(idx) => { + if let Value::Repeat(inner, _) = self.get(value) { + return Some(*inner); + } + let idx = self.locals[idx]?; + ProjectionElem::Index(idx) + } + ProjectionElem::ConstantIndex { offset, min_length, from_end } => { + match self.get(value) { + Value::Repeat(inner, _) => { + return Some(*inner); + } + Value::Aggregate(AggregateTy::Array, _, operands) => { + let offset = if from_end { + operands.len() - offset as usize + } else { + offset as usize + }; + return operands.get(offset).copied(); + } + _ => {} + }; + 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), + ProjectionElem::Subtype(ty) => ProjectionElem::Subtype(ty), + }; + + Some(self.insert(Value::Projection(value, proj))) + } + + /// Simplify the projection chain if we know better. + #[instrument(level = "trace", skip(self))] + fn simplify_place_projection(&mut self, place: &mut Place<'tcx>, location: Location) { + // If the projection is indirect, we treat the local as a value, so can replace it with + // another local. + if place.is_indirect() + && let Some(base) = self.locals[place.local] + && let Some(new_local) = self.try_as_local(base, location) + { + place.local = new_local; + self.reused_locals.insert(new_local); + } + + let mut projection = Cow::Borrowed(&place.projection[..]); + + for i in 0..projection.len() { + let elem = projection[i]; + if let ProjectionElem::Index(idx) = elem + && let Some(idx) = self.locals[idx] + { + if let Some(offset) = self.evaluated[idx].as_ref() + && let Ok(offset) = self.ecx.read_target_usize(offset) + { + projection.to_mut()[i] = ProjectionElem::ConstantIndex { + offset, + min_length: offset + 1, + from_end: false, + }; + } else if let Some(new_idx) = self.try_as_local(idx, location) { + projection.to_mut()[i] = ProjectionElem::Index(new_idx); + self.reused_locals.insert(new_idx); + } + } + } + + if projection.is_owned() { + place.projection = self.tcx.mk_place_elems(&projection); + } + + trace!(?place); + } + /// Represent the *value* which would be read from `place`, and point `place` to a preexisting /// place with the same value (if that already exists). #[instrument(level = "trace", skip(self), ret)] @@ -266,6 +669,8 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { place: &mut Place<'tcx>, location: Location, ) -> Option { + self.simplify_place_projection(place, location); + // Invariant: `place` and `place_ref` point to the same value, even if they point to // different memory locations. let mut place_ref = place.as_ref(); @@ -280,58 +685,18 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { place_ref = PlaceRef { local, projection: &place.projection[index..] }; } - let proj = match proj { - ProjectionElem::Deref => { - let ty = Place::ty_from( - place.local, - &place.projection[..index], - self.local_decls, - self.tcx, - ) - .ty; - if let Some(Mutability::Not) = ty.ref_mutability() - && let Some(pointee_ty) = ty.builtin_deref(true) - && pointee_ty.ty.is_freeze(self.tcx, self.param_env) - { - // An immutable borrow `_x` always points to the same value for the - // lifetime of the borrow, so we can merge all instances of `*_x`. - ProjectionElem::Deref - } else { - return None; - } - } - ProjectionElem::Field(f, ty) => ProjectionElem::Field(f, ty), - ProjectionElem::Index(idx) => { - let idx = self.locals[idx]?; - ProjectionElem::Index(idx) - } - ProjectionElem::ConstantIndex { offset, min_length, from_end } => { - ProjectionElem::ConstantIndex { offset, min_length, from_end } - } - ProjectionElem::Subslice { from, to, from_end } => { - ProjectionElem::Subslice { from, to, from_end } - } - ProjectionElem::Downcast(name, index) => ProjectionElem::Downcast(name, index), - ProjectionElem::OpaqueCast(ty) => ProjectionElem::OpaqueCast(ty), - ProjectionElem::Subtype(ty) => ProjectionElem::Subtype(ty), - }; - value = self.insert(Value::Projection(value, proj)); + let base = PlaceRef { local: place.local, projection: &place.projection[..index] }; + value = self.project(base, value, proj)?; } - if let Some(local) = self.try_as_local(value, location) - && local != place.local - // in case we had no projection to begin with. - { - *place = local.into(); - self.reused_locals.insert(local); - self.any_replacement = true; - } else if place_ref.local != place.local - || place_ref.projection.len() < place.projection.len() - { + if let Some(new_local) = self.try_as_local(value, location) { + place_ref = PlaceRef { local: new_local, projection: &[] }; + } + + if place_ref.local != place.local || place_ref.projection.len() < place.projection.len() { // By the invariant on `place_ref`. *place = place_ref.project_deeper(&[], self.tcx); self.reused_locals.insert(place_ref.local); - self.any_replacement = true; } Some(value) @@ -344,12 +709,14 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { location: Location, ) -> Option { match *operand { - Operand::Constant(ref constant) => Some(self.insert(Value::Constant(constant.const_))), + Operand::Constant(ref mut constant) => { + let const_ = constant.const_.normalize(self.tcx, self.param_env); + self.insert_constant(const_) + } Operand::Copy(ref mut place) | Operand::Move(ref mut place) => { let value = self.simplify_place_value(place, location)?; if let Some(const_) = self.try_as_constant(value) { *operand = Operand::Constant(Box::new(const_)); - self.any_replacement = true; } Some(value) } @@ -378,24 +745,15 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { Value::Repeat(op, amount) } Rvalue::NullaryOp(op, ty) => Value::NullaryOp(op, ty), - Rvalue::Aggregate(box ref kind, ref mut fields) => { - let variant_index = match *kind { - AggregateKind::Array(..) - | AggregateKind::Tuple - | AggregateKind::Closure(..) - | AggregateKind::Coroutine(..) => FIRST_VARIANT, - AggregateKind::Adt(_, variant_index, _, _, None) => variant_index, - // Do not track unions. - AggregateKind::Adt(_, _, _, _, Some(_)) => return None, - }; - let fields: Option> = fields - .iter_mut() - .map(|op| self.simplify_operand(op, location).or_else(|| self.new_opaque())) - .collect(); - let ty = rvalue.ty(self.local_decls, self.tcx); - Value::Aggregate(ty, variant_index, fields?) + Rvalue::Aggregate(..) => return self.simplify_aggregate(rvalue, location), + Rvalue::Ref(_, borrow_kind, ref mut place) => { + self.simplify_place_projection(place, location); + return self.new_pointer(*place, AddressKind::Ref(borrow_kind)); + } + Rvalue::AddressOf(mutbl, ref mut place) => { + self.simplify_place_projection(place, location); + return self.new_pointer(*place, AddressKind::Address(mutbl)); } - Rvalue::Ref(.., place) | Rvalue::AddressOf(_, place) => return self.new_pointer(place), // Operations. Rvalue::Len(ref mut place) => { @@ -405,6 +763,14 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { Rvalue::Cast(kind, ref mut value, to) => { let from = value.ty(self.local_decls, self.tcx); let value = self.simplify_operand(value, location)?; + if let CastKind::PointerCoercion( + PointerCoercion::ReifyFnPointer | PointerCoercion::ClosureFnPointer(_), + ) = kind + { + // Each reification of a generic fn may get a different pointer. + // Do not try to merge them. + return self.new_opaque(); + } Value::Cast { kind, value, from, to } } Rvalue::BinaryOp(op, box (ref mut lhs, ref mut rhs)) => { @@ -423,6 +789,9 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { } Rvalue::Discriminant(ref mut place) => { let place = self.simplify_place_value(place, location)?; + if let Some(discr) = self.simplify_discriminant(place) { + return Some(discr); + } Value::Discriminant(place) } @@ -432,45 +801,182 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { debug!(?value); Some(self.insert(value)) } + + fn simplify_discriminant(&mut self, place: VnIndex) -> Option { + if let Value::Aggregate(enum_ty, variant, _) = *self.get(place) + && let AggregateTy::Def(enum_did, enum_substs) = enum_ty + && let DefKind::Enum = self.tcx.def_kind(enum_did) + { + let enum_ty = self.tcx.type_of(enum_did).instantiate(self.tcx, enum_substs); + let discr = self.ecx.discriminant_for_variant(enum_ty, variant).ok()?; + return Some(self.insert_scalar(discr.to_scalar(), discr.layout.ty)); + } + + None + } + + fn simplify_aggregate( + &mut self, + rvalue: &mut Rvalue<'tcx>, + location: Location, + ) -> Option { + let Rvalue::Aggregate(box ref kind, ref mut fields) = *rvalue else { bug!() }; + + let tcx = self.tcx; + if fields.is_empty() { + let is_zst = match *kind { + AggregateKind::Array(..) | AggregateKind::Tuple | AggregateKind::Closure(..) => { + true + } + // Only enums can be non-ZST. + AggregateKind::Adt(did, ..) => tcx.def_kind(did) != DefKind::Enum, + // Coroutines are never ZST, as they at least contain the implicit states. + AggregateKind::Coroutine(..) => false, + }; + + if is_zst { + let ty = rvalue.ty(self.local_decls, tcx); + return self.insert_constant(Const::zero_sized(ty)); + } + } + + let (ty, variant_index) = match *kind { + AggregateKind::Array(..) => { + assert!(!fields.is_empty()); + (AggregateTy::Array, FIRST_VARIANT) + } + AggregateKind::Tuple => { + assert!(!fields.is_empty()); + (AggregateTy::Tuple, FIRST_VARIANT) + } + AggregateKind::Closure(did, substs) | AggregateKind::Coroutine(did, substs, _) => { + (AggregateTy::Def(did, substs), FIRST_VARIANT) + } + AggregateKind::Adt(did, variant_index, substs, _, None) => { + (AggregateTy::Def(did, substs), variant_index) + } + // Do not track unions. + AggregateKind::Adt(_, _, _, _, Some(_)) => return None, + }; + + let fields: Option> = fields + .iter_mut() + .map(|op| self.simplify_operand(op, location).or_else(|| self.new_opaque())) + .collect(); + let fields = fields?; + + if let AggregateTy::Array = ty && fields.len() > 4 { + let first = fields[0]; + if fields.iter().all(|&v| v == first) { + let len = ty::Const::from_target_usize(self.tcx, fields.len().try_into().unwrap()); + if let Some(const_) = self.try_as_constant(first) { + *rvalue = Rvalue::Repeat(Operand::Constant(Box::new(const_)), len); + } else if let Some(local) = self.try_as_local(first, location) { + *rvalue = Rvalue::Repeat(Operand::Copy(local.into()), len); + self.reused_locals.insert(local); + } + return Some(self.insert(Value::Repeat(first, len))); + } + } + + Some(self.insert(Value::Aggregate(ty, variant_index, fields))) + } +} + +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) + && scalar.try_to_int().is_ok() + { + return Some(ConstValue::Scalar(scalar)); + } + + // If this constant is already represented as an `Allocation`, + // try putting it into global memory to return it. + if let Either::Left(mplace) = op.as_mplace_or_imm() { + let (size, _align) = ecx.size_and_align_of_mplace(&mplace).ok()??; + + // Do not try interning a value that contains provenance. + // Due to https://github.com/rust-lang/rust/issues/79738, doing so could lead to bugs. + // FIXME: remove this hack once that issue is fixed. + let alloc_ref = ecx.get_ptr_alloc(mplace.ptr(), size).ok()??; + if alloc_ref.has_provenance() { + return None; + } + + let pointer = mplace.ptr().into_pointer_or_addr().ok()?; + let (alloc_id, offset) = pointer.into_parts(); + intern_const_alloc_for_constprop(ecx, alloc_id).ok()?; + if matches!(ecx.tcx.global_alloc(alloc_id), GlobalAlloc::Memory(_)) { + // `alloc_id` may point to a static. Codegen will choke on an `Indirect` with anything + // by `GlobalAlloc::Memory`, so do fall through to copying if needed. + // FIXME: find a way to treat this more uniformly + // (probably by fixing codegen) + return Some(ConstValue::Indirect { alloc_id, offset }); + } + } + + // 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()?; + let value = ConstValue::Indirect { alloc_id, offset: Size::ZERO }; + + // Check that we do not leak a pointer. + // Those pointers may lose part of their identity in codegen. + // FIXME: remove this hack once https://github.com/rust-lang/rust/issues/79738 is fixed. + if ecx.tcx.global_alloc(alloc_id).unwrap_memory().inner().provenance().ptrs().is_empty() { + return Some(value); + } + + None } 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 + // This was already constant in MIR, do not change it. + if let Value::Constant { value, disambiguator: _ } = *self.get(index) + // If the constant is not deterministic, adding an additional mention of it in MIR will + // not give the same value as the former mention. + && value.is_deterministic() + { + return Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_: value }); } + + 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. + // FIXME: remove this hack once https://github.com/rust-lang/rust/issues/79738 is fixed. + assert!(!value.may_have_provenance(self.tcx, op.layout.size)); + + 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`, @@ -489,27 +995,32 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> { self.tcx } + fn visit_place(&mut self, place: &mut Place<'tcx>, _: PlaceContext, location: Location) { + self.simplify_place_projection(place, location); + } + fn visit_operand(&mut self, operand: &mut Operand<'tcx>, location: Location) { self.simplify_operand(operand, location); } fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, location: Location) { - self.super_statement(stmt, location); if let StatementKind::Assign(box (_, ref mut rvalue)) = stmt.kind // Do not try to simplify a constant, it's already in canonical shape. && !matches!(rvalue, Rvalue::Use(Operand::Constant(_))) - && let Some(value) = self.simplify_rvalue(rvalue, location) { - if let Some(const_) = self.try_as_constant(value) { - *rvalue = Rvalue::Use(Operand::Constant(Box::new(const_))); - self.any_replacement = true; - } else if let Some(local) = self.try_as_local(value, location) - && *rvalue != Rvalue::Use(Operand::Move(local.into())) + if let Some(value) = self.simplify_rvalue(rvalue, location) { - *rvalue = Rvalue::Use(Operand::Copy(local.into())); - self.reused_locals.insert(local); - self.any_replacement = true; + if let Some(const_) = self.try_as_constant(value) { + *rvalue = Rvalue::Use(Operand::Constant(Box::new(const_))); + } 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); + } } + } else { + self.super_statement(stmt, location); } } } diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 9aaa54110bdfe..bdd5bf702c8a6 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -2,6 +2,7 @@ #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] #![feature(box_patterns)] +#![feature(cow_is_borrowed)] #![feature(decl_macro)] #![feature(is_sorted)] #![feature(let_chains)] @@ -570,6 +571,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_debuginfo::ConstDebugInfo, &o1(simplify_branches::SimplifyConstCondition::AfterConstProp), diff --git a/compiler/rustc_mir_transform/src/simplify.rs b/compiler/rustc_mir_transform/src/simplify.rs index 88c89e106fd56..0a1c011147ae0 100644 --- a/compiler/rustc_mir_transform/src/simplify.rs +++ b/compiler/rustc_mir_transform/src/simplify.rs @@ -366,6 +366,7 @@ pub fn remove_dead_blocks(body: &mut Body<'_>) { pub enum SimplifyLocals { BeforeConstProp, + AfterGVN, Final, } @@ -373,6 +374,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/src/tools/miri/tests/pass/function_pointers.rs b/src/tools/miri/tests/pass/function_pointers.rs index 1c99a96feda94..36679b7180a64 100644 --- a/src/tools/miri/tests/pass/function_pointers.rs +++ b/src/tools/miri/tests/pass/function_pointers.rs @@ -80,9 +80,8 @@ fn main() { // 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; + // Miri gives different addresses to different reifications of a generic function. + assert!(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; diff --git a/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff b/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff index 313e5dddbbba4..f5d822520a70a 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,34 +19,34 @@ 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; +- debug o => _6; + debug o => const Option::::Some(99_u16); - let _17: u32; - let _18: u32; + 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; } } @@ -69,30 +63,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 = const Option::::Some(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 = const Option::::Some(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..d524ad242fecc 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,17 +119,18 @@ StorageDead(_11); StorageLive(_14); StorageLive(_15); -- StorageLive(_16); -- _16 = _1; - _17 = Eq(const 0_u64, const 0_u64); + 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]; ++ _17 = const true; ++ assert(!const true, "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); + StorageDead(_16); _14 = opaque::(move _15) -> [return: bb6, unwind unreachable]; } @@ -138,17 +139,18 @@ StorageDead(_14); StorageLive(_18); StorageLive(_19); -- StorageLive(_20); -- _20 = _1; - _21 = Eq(const 1_u64, const 0_u64); + 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]; ++ _21 = const false; ++ assert(!const false, "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); + StorageDead(_20); _18 = opaque::(move _19) -> [return: bb8, unwind unreachable]; } @@ -157,8 +159,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 +169,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 +179,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 +199,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]; -+ 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: { - _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 +219,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]; -+ 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: { - _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 +239,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 +259,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 +279,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 +292,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 +305,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 +318,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 +331,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..9d69353934c79 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,17 +119,18 @@ StorageDead(_11); StorageLive(_14); StorageLive(_15); -- StorageLive(_16); -- _16 = _1; - _17 = Eq(const 0_u64, const 0_u64); + 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]; ++ _17 = const true; ++ assert(!const true, "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); + StorageDead(_16); _14 = opaque::(move _15) -> [return: bb6, unwind continue]; } @@ -138,17 +139,18 @@ StorageDead(_14); StorageLive(_18); StorageLive(_19); -- StorageLive(_20); -- _20 = _1; - _21 = Eq(const 1_u64, const 0_u64); + 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]; ++ _21 = const false; ++ assert(!const false, "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); + StorageDead(_20); _18 = opaque::(move _19) -> [return: bb8, unwind continue]; } @@ -157,8 +159,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 +169,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 +179,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 +199,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]; -+ 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: { - _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 +219,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]; -+ 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: { - _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 +239,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 +259,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 +279,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 +292,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 +305,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 +318,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 +331,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..6633df3ae702c 100644 --- a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff @@ -20,63 +20,12 @@ 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; + 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 +34,7 @@ bb1: { _3 = move (_5.0: u64); -- StorageDead(_4); + StorageDead(_4); _2 = opaque::(move _3) -> [return: bb2, unwind unreachable]; } @@ -94,8 +43,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 +53,7 @@ bb3: { _7 = move (_9.0: u64); -- StorageDead(_8); + StorageDead(_8); _6 = opaque::(move _7) -> [return: bb4, unwind unreachable]; } @@ -113,8 +62,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 +72,7 @@ bb5: { _11 = move (_13.0: u64); -- StorageDead(_12); + StorageDead(_12); _10 = opaque::(move _11) -> [return: bb6, unwind unreachable]; } @@ -132,8 +81,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,246 +91,13 @@ bb7: { _15 = move (_17.0: u64); -- StorageDead(_16); + 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 index 7813c29b962d2..d100a77fee5f3 100644 --- a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff @@ -20,63 +20,12 @@ 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; + 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 +34,7 @@ bb1: { _3 = move (_5.0: u64); -- StorageDead(_4); + StorageDead(_4); _2 = opaque::(move _3) -> [return: bb2, unwind continue]; } @@ -94,8 +43,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 +53,7 @@ bb3: { _7 = move (_9.0: u64); -- StorageDead(_8); + StorageDead(_8); _6 = opaque::(move _7) -> [return: bb4, unwind continue]; } @@ -113,8 +62,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 +72,7 @@ bb5: { _11 = move (_13.0: u64); -- StorageDead(_12); + StorageDead(_12); _10 = opaque::(move _11) -> [return: bb6, unwind continue]; } @@ -132,8 +81,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,246 +91,13 @@ bb7: { _15 = move (_17.0: u64); -- StorageDead(_16); + 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 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..d43198c99110d 100644 --- a/tests/mir-opt/gvn.cast.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.cast.GVN.panic-abort.diff @@ -105,19 +105,24 @@ 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); -+ _5 = const 1_i64 as u8 (IntToInt); - _4 = opaque::(move _5) -> [return: bb1, unwind unreachable]; ++ _6 = const 1_i64; ++ _5 = const 1_u8; + StorageDead(_6); +- _4 = opaque::(move _5) -> [return: bb1, unwind unreachable]; ++ _4 = opaque::(const 1_u8) -> [return: bb1, unwind unreachable]; } bb1: { @@ -125,12 +130,14 @@ StorageDead(_4); StorageLive(_7); StorageLive(_8); -- StorageLive(_9); + 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]; ++ _9 = const 1_i64; ++ _8 = const 1_u16; + StorageDead(_9); +- _7 = opaque::(move _8) -> [return: bb2, unwind unreachable]; ++ _7 = opaque::(const 1_u16) -> [return: bb2, unwind unreachable]; } bb2: { @@ -138,12 +145,14 @@ StorageDead(_7); StorageLive(_10); StorageLive(_11); -- StorageLive(_12); + 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]; ++ _12 = const 1_i64; ++ _11 = const 1_u32; + StorageDead(_12); +- _10 = opaque::(move _11) -> [return: bb3, unwind unreachable]; ++ _10 = opaque::(const 1_u32) -> [return: bb3, unwind unreachable]; } bb3: { @@ -151,12 +160,14 @@ StorageDead(_10); StorageLive(_13); StorageLive(_14); -- StorageLive(_15); + 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]; ++ _15 = const 1_i64; ++ _14 = const 1_u64; + StorageDead(_15); +- _13 = opaque::(move _14) -> [return: bb4, unwind unreachable]; ++ _13 = opaque::(const 1_u64) -> [return: bb4, unwind unreachable]; } bb4: { @@ -164,12 +175,14 @@ StorageDead(_13); StorageLive(_16); StorageLive(_17); -- StorageLive(_18); + 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]; ++ _18 = const 1_i64; ++ _17 = const 1_i8; + StorageDead(_18); +- _16 = opaque::(move _17) -> [return: bb5, unwind unreachable]; ++ _16 = opaque::(const 1_i8) -> [return: bb5, unwind unreachable]; } bb5: { @@ -177,12 +190,14 @@ StorageDead(_16); StorageLive(_19); StorageLive(_20); -- StorageLive(_21); + 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]; ++ _21 = const 1_i64; ++ _20 = const 1_i16; + StorageDead(_21); +- _19 = opaque::(move _20) -> [return: bb6, unwind unreachable]; ++ _19 = opaque::(const 1_i16) -> [return: bb6, unwind unreachable]; } bb6: { @@ -190,35 +205,40 @@ StorageDead(_19); StorageLive(_22); StorageLive(_23); -- StorageLive(_24); + 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]; ++ _24 = const 1_i64; ++ _23 = const 1_i32; + StorageDead(_24); +- _22 = opaque::(move _23) -> [return: bb7, unwind unreachable]; ++ _22 = opaque::(const 1_i32) -> [return: bb7, unwind unreachable]; } bb7: { 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); -+ _28 = const 1_i64 as f32 (IntToFloat); - _27 = opaque::(move _28) -> [return: bb9, unwind unreachable]; ++ _29 = const 1_i64; ++ _28 = const 1f32; + StorageDead(_29); +- _27 = opaque::(move _28) -> [return: bb9, unwind unreachable]; ++ _27 = opaque::(const 1f32) -> [return: bb9, unwind unreachable]; } bb9: { @@ -226,12 +246,14 @@ StorageDead(_27); StorageLive(_30); StorageLive(_31); -- StorageLive(_32); + 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]; ++ _32 = const 1_i64; ++ _31 = const 1f64; + StorageDead(_32); +- _30 = opaque::(move _31) -> [return: bb10, unwind unreachable]; ++ _30 = opaque::(const 1f64) -> [return: bb10, unwind unreachable]; } bb10: { @@ -239,12 +261,14 @@ StorageDead(_30); StorageLive(_33); StorageLive(_34); -- StorageLive(_35); + 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]; ++ _35 = const 1_u64; ++ _34 = const 1_u8; + StorageDead(_35); +- _33 = opaque::(move _34) -> [return: bb11, unwind unreachable]; ++ _33 = opaque::(const 1_u8) -> [return: bb11, unwind unreachable]; } bb11: { @@ -252,12 +276,14 @@ StorageDead(_33); StorageLive(_36); StorageLive(_37); -- StorageLive(_38); + 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]; ++ _38 = const 1_u64; ++ _37 = const 1_u16; + StorageDead(_38); +- _36 = opaque::(move _37) -> [return: bb12, unwind unreachable]; ++ _36 = opaque::(const 1_u16) -> [return: bb12, unwind unreachable]; } bb12: { @@ -265,35 +291,40 @@ StorageDead(_36); StorageLive(_39); StorageLive(_40); -- StorageLive(_41); + 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]; ++ _41 = const 1_u64; ++ _40 = const 1_u32; + StorageDead(_41); +- _39 = opaque::(move _40) -> [return: bb13, unwind unreachable]; ++ _39 = opaque::(const 1_u32) -> [return: bb13, unwind unreachable]; } bb13: { 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); -+ _45 = const 1_u64 as i8 (IntToInt); - _44 = opaque::(move _45) -> [return: bb15, unwind unreachable]; ++ _46 = const 1_u64; ++ _45 = const 1_i8; + StorageDead(_46); +- _44 = opaque::(move _45) -> [return: bb15, unwind unreachable]; ++ _44 = opaque::(const 1_i8) -> [return: bb15, unwind unreachable]; } bb15: { @@ -301,12 +332,14 @@ StorageDead(_44); StorageLive(_47); StorageLive(_48); -- StorageLive(_49); + 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]; ++ _49 = const 1_u64; ++ _48 = const 1_i16; + StorageDead(_49); +- _47 = opaque::(move _48) -> [return: bb16, unwind unreachable]; ++ _47 = opaque::(const 1_i16) -> [return: bb16, unwind unreachable]; } bb16: { @@ -314,12 +347,14 @@ StorageDead(_47); StorageLive(_50); StorageLive(_51); -- StorageLive(_52); + 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]; ++ _52 = const 1_u64; ++ _51 = const 1_i32; + StorageDead(_52); +- _50 = opaque::(move _51) -> [return: bb17, unwind unreachable]; ++ _50 = opaque::(const 1_i32) -> [return: bb17, unwind unreachable]; } bb17: { @@ -327,12 +362,14 @@ StorageDead(_50); StorageLive(_53); StorageLive(_54); -- StorageLive(_55); + 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]; ++ _55 = const 1_u64; ++ _54 = const 1_i64; + StorageDead(_55); +- _53 = opaque::(move _54) -> [return: bb18, unwind unreachable]; ++ _53 = opaque::(const 1_i64) -> [return: bb18, unwind unreachable]; } bb18: { @@ -340,12 +377,14 @@ StorageDead(_53); StorageLive(_56); StorageLive(_57); -- StorageLive(_58); + 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]; ++ _58 = const 1_u64; ++ _57 = const 1f32; + StorageDead(_58); +- _56 = opaque::(move _57) -> [return: bb19, unwind unreachable]; ++ _56 = opaque::(const 1f32) -> [return: bb19, unwind unreachable]; } bb19: { @@ -353,12 +392,14 @@ StorageDead(_56); StorageLive(_59); StorageLive(_60); -- StorageLive(_61); + 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]; ++ _61 = const 1_u64; ++ _60 = const 1f64; + StorageDead(_61); +- _59 = opaque::(move _60) -> [return: bb20, unwind unreachable]; ++ _59 = opaque::(const 1f64) -> [return: bb20, unwind unreachable]; } bb20: { @@ -366,12 +407,14 @@ StorageDead(_59); StorageLive(_62); StorageLive(_63); -- StorageLive(_64); + 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]; ++ _64 = const 1f64; ++ _63 = const 1_u8; + StorageDead(_64); +- _62 = opaque::(move _63) -> [return: bb21, unwind unreachable]; ++ _62 = opaque::(const 1_u8) -> [return: bb21, unwind unreachable]; } bb21: { @@ -379,12 +422,14 @@ StorageDead(_62); StorageLive(_65); StorageLive(_66); -- StorageLive(_67); + 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]; ++ _67 = const 1f64; ++ _66 = const 1_u16; + StorageDead(_67); +- _65 = opaque::(move _66) -> [return: bb22, unwind unreachable]; ++ _65 = opaque::(const 1_u16) -> [return: bb22, unwind unreachable]; } bb22: { @@ -392,12 +437,14 @@ StorageDead(_65); StorageLive(_68); StorageLive(_69); -- StorageLive(_70); + 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]; ++ _70 = const 1f64; ++ _69 = const 1_u32; + StorageDead(_70); +- _68 = opaque::(move _69) -> [return: bb23, unwind unreachable]; ++ _68 = opaque::(const 1_u32) -> [return: bb23, unwind unreachable]; } bb23: { @@ -405,12 +452,14 @@ StorageDead(_68); StorageLive(_71); StorageLive(_72); -- StorageLive(_73); + 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]; ++ _73 = const 1f64; ++ _72 = const 1_u64; + StorageDead(_73); +- _71 = opaque::(move _72) -> [return: bb24, unwind unreachable]; ++ _71 = opaque::(const 1_u64) -> [return: bb24, unwind unreachable]; } bb24: { @@ -418,12 +467,14 @@ StorageDead(_71); StorageLive(_74); StorageLive(_75); -- StorageLive(_76); + 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]; ++ _76 = const 1f64; ++ _75 = const 1_i8; + StorageDead(_76); +- _74 = opaque::(move _75) -> [return: bb25, unwind unreachable]; ++ _74 = opaque::(const 1_i8) -> [return: bb25, unwind unreachable]; } bb25: { @@ -431,12 +482,14 @@ StorageDead(_74); StorageLive(_77); StorageLive(_78); -- StorageLive(_79); + 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]; ++ _79 = const 1f64; ++ _78 = const 1_i16; + StorageDead(_79); +- _77 = opaque::(move _78) -> [return: bb26, unwind unreachable]; ++ _77 = opaque::(const 1_i16) -> [return: bb26, unwind unreachable]; } bb26: { @@ -444,12 +497,14 @@ StorageDead(_77); StorageLive(_80); StorageLive(_81); -- StorageLive(_82); + 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]; ++ _82 = const 1f64; ++ _81 = const 1_i32; + StorageDead(_82); +- _80 = opaque::(move _81) -> [return: bb27, unwind unreachable]; ++ _80 = opaque::(const 1_i32) -> [return: bb27, unwind unreachable]; } bb27: { @@ -457,12 +512,14 @@ StorageDead(_80); StorageLive(_83); StorageLive(_84); -- StorageLive(_85); + 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]; ++ _85 = const 1f64; ++ _84 = const 1_i64; + StorageDead(_85); +- _83 = opaque::(move _84) -> [return: bb28, unwind unreachable]; ++ _83 = opaque::(const 1_i64) -> [return: bb28, unwind unreachable]; } bb28: { @@ -470,31 +527,37 @@ StorageDead(_83); StorageLive(_86); StorageLive(_87); -- StorageLive(_88); + 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]; ++ _88 = const 1f64; ++ _87 = const 1f32; + StorageDead(_88); +- _86 = opaque::(move _87) -> [return: bb29, unwind unreachable]; ++ _86 = opaque::(const 1f32) -> [return: bb29, unwind unreachable]; } bb29: { 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..08b97e13aa0ba 100644 --- a/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff @@ -105,19 +105,24 @@ 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); -+ _5 = const 1_i64 as u8 (IntToInt); - _4 = opaque::(move _5) -> [return: bb1, unwind continue]; ++ _6 = const 1_i64; ++ _5 = const 1_u8; + StorageDead(_6); +- _4 = opaque::(move _5) -> [return: bb1, unwind continue]; ++ _4 = opaque::(const 1_u8) -> [return: bb1, unwind continue]; } bb1: { @@ -125,12 +130,14 @@ StorageDead(_4); StorageLive(_7); StorageLive(_8); -- StorageLive(_9); + 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]; ++ _9 = const 1_i64; ++ _8 = const 1_u16; + StorageDead(_9); +- _7 = opaque::(move _8) -> [return: bb2, unwind continue]; ++ _7 = opaque::(const 1_u16) -> [return: bb2, unwind continue]; } bb2: { @@ -138,12 +145,14 @@ StorageDead(_7); StorageLive(_10); StorageLive(_11); -- StorageLive(_12); + 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]; ++ _12 = const 1_i64; ++ _11 = const 1_u32; + StorageDead(_12); +- _10 = opaque::(move _11) -> [return: bb3, unwind continue]; ++ _10 = opaque::(const 1_u32) -> [return: bb3, unwind continue]; } bb3: { @@ -151,12 +160,14 @@ StorageDead(_10); StorageLive(_13); StorageLive(_14); -- StorageLive(_15); + 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]; ++ _15 = const 1_i64; ++ _14 = const 1_u64; + StorageDead(_15); +- _13 = opaque::(move _14) -> [return: bb4, unwind continue]; ++ _13 = opaque::(const 1_u64) -> [return: bb4, unwind continue]; } bb4: { @@ -164,12 +175,14 @@ StorageDead(_13); StorageLive(_16); StorageLive(_17); -- StorageLive(_18); + 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]; ++ _18 = const 1_i64; ++ _17 = const 1_i8; + StorageDead(_18); +- _16 = opaque::(move _17) -> [return: bb5, unwind continue]; ++ _16 = opaque::(const 1_i8) -> [return: bb5, unwind continue]; } bb5: { @@ -177,12 +190,14 @@ StorageDead(_16); StorageLive(_19); StorageLive(_20); -- StorageLive(_21); + 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]; ++ _21 = const 1_i64; ++ _20 = const 1_i16; + StorageDead(_21); +- _19 = opaque::(move _20) -> [return: bb6, unwind continue]; ++ _19 = opaque::(const 1_i16) -> [return: bb6, unwind continue]; } bb6: { @@ -190,35 +205,40 @@ StorageDead(_19); StorageLive(_22); StorageLive(_23); -- StorageLive(_24); + 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]; ++ _24 = const 1_i64; ++ _23 = const 1_i32; + StorageDead(_24); +- _22 = opaque::(move _23) -> [return: bb7, unwind continue]; ++ _22 = opaque::(const 1_i32) -> [return: bb7, unwind continue]; } bb7: { 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); -+ _28 = const 1_i64 as f32 (IntToFloat); - _27 = opaque::(move _28) -> [return: bb9, unwind continue]; ++ _29 = const 1_i64; ++ _28 = const 1f32; + StorageDead(_29); +- _27 = opaque::(move _28) -> [return: bb9, unwind continue]; ++ _27 = opaque::(const 1f32) -> [return: bb9, unwind continue]; } bb9: { @@ -226,12 +246,14 @@ StorageDead(_27); StorageLive(_30); StorageLive(_31); -- StorageLive(_32); + 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]; ++ _32 = const 1_i64; ++ _31 = const 1f64; + StorageDead(_32); +- _30 = opaque::(move _31) -> [return: bb10, unwind continue]; ++ _30 = opaque::(const 1f64) -> [return: bb10, unwind continue]; } bb10: { @@ -239,12 +261,14 @@ StorageDead(_30); StorageLive(_33); StorageLive(_34); -- StorageLive(_35); + 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]; ++ _35 = const 1_u64; ++ _34 = const 1_u8; + StorageDead(_35); +- _33 = opaque::(move _34) -> [return: bb11, unwind continue]; ++ _33 = opaque::(const 1_u8) -> [return: bb11, unwind continue]; } bb11: { @@ -252,12 +276,14 @@ StorageDead(_33); StorageLive(_36); StorageLive(_37); -- StorageLive(_38); + 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]; ++ _38 = const 1_u64; ++ _37 = const 1_u16; + StorageDead(_38); +- _36 = opaque::(move _37) -> [return: bb12, unwind continue]; ++ _36 = opaque::(const 1_u16) -> [return: bb12, unwind continue]; } bb12: { @@ -265,35 +291,40 @@ StorageDead(_36); StorageLive(_39); StorageLive(_40); -- StorageLive(_41); + 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]; ++ _41 = const 1_u64; ++ _40 = const 1_u32; + StorageDead(_41); +- _39 = opaque::(move _40) -> [return: bb13, unwind continue]; ++ _39 = opaque::(const 1_u32) -> [return: bb13, unwind continue]; } bb13: { 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); -+ _45 = const 1_u64 as i8 (IntToInt); - _44 = opaque::(move _45) -> [return: bb15, unwind continue]; ++ _46 = const 1_u64; ++ _45 = const 1_i8; + StorageDead(_46); +- _44 = opaque::(move _45) -> [return: bb15, unwind continue]; ++ _44 = opaque::(const 1_i8) -> [return: bb15, unwind continue]; } bb15: { @@ -301,12 +332,14 @@ StorageDead(_44); StorageLive(_47); StorageLive(_48); -- StorageLive(_49); + 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]; ++ _49 = const 1_u64; ++ _48 = const 1_i16; + StorageDead(_49); +- _47 = opaque::(move _48) -> [return: bb16, unwind continue]; ++ _47 = opaque::(const 1_i16) -> [return: bb16, unwind continue]; } bb16: { @@ -314,12 +347,14 @@ StorageDead(_47); StorageLive(_50); StorageLive(_51); -- StorageLive(_52); + 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]; ++ _52 = const 1_u64; ++ _51 = const 1_i32; + StorageDead(_52); +- _50 = opaque::(move _51) -> [return: bb17, unwind continue]; ++ _50 = opaque::(const 1_i32) -> [return: bb17, unwind continue]; } bb17: { @@ -327,12 +362,14 @@ StorageDead(_50); StorageLive(_53); StorageLive(_54); -- StorageLive(_55); + 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]; ++ _55 = const 1_u64; ++ _54 = const 1_i64; + StorageDead(_55); +- _53 = opaque::(move _54) -> [return: bb18, unwind continue]; ++ _53 = opaque::(const 1_i64) -> [return: bb18, unwind continue]; } bb18: { @@ -340,12 +377,14 @@ StorageDead(_53); StorageLive(_56); StorageLive(_57); -- StorageLive(_58); + 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]; ++ _58 = const 1_u64; ++ _57 = const 1f32; + StorageDead(_58); +- _56 = opaque::(move _57) -> [return: bb19, unwind continue]; ++ _56 = opaque::(const 1f32) -> [return: bb19, unwind continue]; } bb19: { @@ -353,12 +392,14 @@ StorageDead(_56); StorageLive(_59); StorageLive(_60); -- StorageLive(_61); + 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]; ++ _61 = const 1_u64; ++ _60 = const 1f64; + StorageDead(_61); +- _59 = opaque::(move _60) -> [return: bb20, unwind continue]; ++ _59 = opaque::(const 1f64) -> [return: bb20, unwind continue]; } bb20: { @@ -366,12 +407,14 @@ StorageDead(_59); StorageLive(_62); StorageLive(_63); -- StorageLive(_64); + 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]; ++ _64 = const 1f64; ++ _63 = const 1_u8; + StorageDead(_64); +- _62 = opaque::(move _63) -> [return: bb21, unwind continue]; ++ _62 = opaque::(const 1_u8) -> [return: bb21, unwind continue]; } bb21: { @@ -379,12 +422,14 @@ StorageDead(_62); StorageLive(_65); StorageLive(_66); -- StorageLive(_67); + 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]; ++ _67 = const 1f64; ++ _66 = const 1_u16; + StorageDead(_67); +- _65 = opaque::(move _66) -> [return: bb22, unwind continue]; ++ _65 = opaque::(const 1_u16) -> [return: bb22, unwind continue]; } bb22: { @@ -392,12 +437,14 @@ StorageDead(_65); StorageLive(_68); StorageLive(_69); -- StorageLive(_70); + 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]; ++ _70 = const 1f64; ++ _69 = const 1_u32; + StorageDead(_70); +- _68 = opaque::(move _69) -> [return: bb23, unwind continue]; ++ _68 = opaque::(const 1_u32) -> [return: bb23, unwind continue]; } bb23: { @@ -405,12 +452,14 @@ StorageDead(_68); StorageLive(_71); StorageLive(_72); -- StorageLive(_73); + 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]; ++ _73 = const 1f64; ++ _72 = const 1_u64; + StorageDead(_73); +- _71 = opaque::(move _72) -> [return: bb24, unwind continue]; ++ _71 = opaque::(const 1_u64) -> [return: bb24, unwind continue]; } bb24: { @@ -418,12 +467,14 @@ StorageDead(_71); StorageLive(_74); StorageLive(_75); -- StorageLive(_76); + 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]; ++ _76 = const 1f64; ++ _75 = const 1_i8; + StorageDead(_76); +- _74 = opaque::(move _75) -> [return: bb25, unwind continue]; ++ _74 = opaque::(const 1_i8) -> [return: bb25, unwind continue]; } bb25: { @@ -431,12 +482,14 @@ StorageDead(_74); StorageLive(_77); StorageLive(_78); -- StorageLive(_79); + 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]; ++ _79 = const 1f64; ++ _78 = const 1_i16; + StorageDead(_79); +- _77 = opaque::(move _78) -> [return: bb26, unwind continue]; ++ _77 = opaque::(const 1_i16) -> [return: bb26, unwind continue]; } bb26: { @@ -444,12 +497,14 @@ StorageDead(_77); StorageLive(_80); StorageLive(_81); -- StorageLive(_82); + 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]; ++ _82 = const 1f64; ++ _81 = const 1_i32; + StorageDead(_82); +- _80 = opaque::(move _81) -> [return: bb27, unwind continue]; ++ _80 = opaque::(const 1_i32) -> [return: bb27, unwind continue]; } bb27: { @@ -457,12 +512,14 @@ StorageDead(_80); StorageLive(_83); StorageLive(_84); -- StorageLive(_85); + 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]; ++ _85 = const 1f64; ++ _84 = const 1_i64; + StorageDead(_85); +- _83 = opaque::(move _84) -> [return: bb28, unwind continue]; ++ _83 = opaque::(const 1_i64) -> [return: bb28, unwind continue]; } bb28: { @@ -470,31 +527,37 @@ StorageDead(_83); StorageLive(_86); StorageLive(_87); -- StorageLive(_88); + 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]; ++ _88 = const 1f64; ++ _87 = const 1f32; + StorageDead(_88); +- _86 = opaque::(move _87) -> [return: bb29, unwind continue]; ++ _86 = opaque::(const 1f32) -> [return: bb29, unwind continue]; } bb29: { 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.comparison.GVN.panic-abort.diff b/tests/mir-opt/gvn.comparison.GVN.panic-abort.diff new file mode 100644 index 0000000000000..ee3b9da2122bd --- /dev/null +++ b/tests/mir-opt/gvn.comparison.GVN.panic-abort.diff @@ -0,0 +1,94 @@ +- // MIR for `comparison` before GVN ++ // MIR for `comparison` after GVN + + fn comparison(_1: u64, _2: u64) -> () { + debug x => _1; + debug y => _2; + let mut _0: (); + let _3: (); + let mut _4: bool; + let mut _5: u64; + let mut _6: u64; + let _7: (); + let mut _8: bool; + let mut _9: u64; + let mut _10: u64; + let _11: (); + let mut _12: bool; + let mut _13: u64; + let mut _14: u64; + let _15: (); + let mut _16: bool; + let mut _17: u64; + let mut _18: u64; + + bb0: { + StorageLive(_3); + StorageLive(_4); + StorageLive(_5); + _5 = _1; + StorageLive(_6); + _6 = _1; +- _4 = Eq(move _5, move _6); ++ _4 = Eq(_1, _1); + StorageDead(_6); + StorageDead(_5); + _3 = opaque::(move _4) -> [return: bb1, unwind unreachable]; + } + + bb1: { + StorageDead(_4); + StorageDead(_3); + StorageLive(_7); + StorageLive(_8); + StorageLive(_9); + _9 = _1; + StorageLive(_10); + _10 = _1; +- _8 = Ne(move _9, move _10); ++ _8 = Ne(_1, _1); + StorageDead(_10); + StorageDead(_9); + _7 = opaque::(move _8) -> [return: bb2, unwind unreachable]; + } + + bb2: { + StorageDead(_8); + StorageDead(_7); + StorageLive(_11); + StorageLive(_12); + StorageLive(_13); + _13 = _1; + StorageLive(_14); + _14 = _2; +- _12 = Eq(move _13, move _14); ++ _12 = Eq(_1, _2); + StorageDead(_14); + StorageDead(_13); + _11 = opaque::(move _12) -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_12); + StorageDead(_11); + StorageLive(_15); + StorageLive(_16); + StorageLive(_17); + _17 = _1; + StorageLive(_18); + _18 = _2; +- _16 = Ne(move _17, move _18); ++ _16 = Ne(_1, _2); + StorageDead(_18); + StorageDead(_17); + _15 = opaque::(move _16) -> [return: bb4, unwind unreachable]; + } + + bb4: { + StorageDead(_16); + StorageDead(_15); + _0 = const (); + return; + } + } + diff --git a/tests/mir-opt/gvn.comparison.GVN.panic-unwind.diff b/tests/mir-opt/gvn.comparison.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..a1408fe3434cb --- /dev/null +++ b/tests/mir-opt/gvn.comparison.GVN.panic-unwind.diff @@ -0,0 +1,94 @@ +- // MIR for `comparison` before GVN ++ // MIR for `comparison` after GVN + + fn comparison(_1: u64, _2: u64) -> () { + debug x => _1; + debug y => _2; + let mut _0: (); + let _3: (); + let mut _4: bool; + let mut _5: u64; + let mut _6: u64; + let _7: (); + let mut _8: bool; + let mut _9: u64; + let mut _10: u64; + let _11: (); + let mut _12: bool; + let mut _13: u64; + let mut _14: u64; + let _15: (); + let mut _16: bool; + let mut _17: u64; + let mut _18: u64; + + bb0: { + StorageLive(_3); + StorageLive(_4); + StorageLive(_5); + _5 = _1; + StorageLive(_6); + _6 = _1; +- _4 = Eq(move _5, move _6); ++ _4 = Eq(_1, _1); + StorageDead(_6); + StorageDead(_5); + _3 = opaque::(move _4) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageDead(_4); + StorageDead(_3); + StorageLive(_7); + StorageLive(_8); + StorageLive(_9); + _9 = _1; + StorageLive(_10); + _10 = _1; +- _8 = Ne(move _9, move _10); ++ _8 = Ne(_1, _1); + StorageDead(_10); + StorageDead(_9); + _7 = opaque::(move _8) -> [return: bb2, unwind continue]; + } + + bb2: { + StorageDead(_8); + StorageDead(_7); + StorageLive(_11); + StorageLive(_12); + StorageLive(_13); + _13 = _1; + StorageLive(_14); + _14 = _2; +- _12 = Eq(move _13, move _14); ++ _12 = Eq(_1, _2); + StorageDead(_14); + StorageDead(_13); + _11 = opaque::(move _12) -> [return: bb3, unwind continue]; + } + + bb3: { + StorageDead(_12); + StorageDead(_11); + StorageLive(_15); + StorageLive(_16); + StorageLive(_17); + _17 = _1; + StorageLive(_18); + _18 = _2; +- _16 = Ne(move _17, move _18); ++ _16 = Ne(_1, _2); + StorageDead(_18); + StorageDead(_17); + _15 = opaque::(move _16) -> [return: bb4, unwind continue]; + } + + bb4: { + StorageDead(_16); + StorageDead(_15); + _0 = const (); + 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..a587b1e6b1de4 100644 --- a/tests/mir-opt/gvn.dereferences.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.dereferences.GVN.panic-abort.diff @@ -72,7 +72,8 @@ bb2: { StorageDead(_7); StorageDead(_6); - StorageLive(_8); +- StorageLive(_8); ++ nop; _8 = &raw const (*_1); StorageLive(_9); StorageLive(_10); @@ -92,7 +93,8 @@ bb4: { StorageDead(_12); StorageDead(_11); - StorageLive(_13); +- StorageLive(_13); ++ nop; _13 = &raw mut (*_1); StorageLive(_14); StorageLive(_15); @@ -112,10 +114,12 @@ bb6: { StorageDead(_17); StorageDead(_16); - StorageLive(_18); +- StorageLive(_18); ++ nop; _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 +127,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 +169,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,21 +177,26 @@ 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); - StorageDead(_13); - StorageDead(_8); +- StorageDead(_18); +- StorageDead(_13); +- StorageDead(_8); ++ nop; ++ nop; ++ nop; return; } } diff --git a/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff b/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff index f627b4d59887a..6fdda5e998875 100644 --- a/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff @@ -72,7 +72,8 @@ bb2: { StorageDead(_7); StorageDead(_6); - StorageLive(_8); +- StorageLive(_8); ++ nop; _8 = &raw const (*_1); StorageLive(_9); StorageLive(_10); @@ -92,7 +93,8 @@ bb4: { StorageDead(_12); StorageDead(_11); - StorageLive(_13); +- StorageLive(_13); ++ nop; _13 = &raw mut (*_1); StorageLive(_14); StorageLive(_15); @@ -112,10 +114,12 @@ bb6: { StorageDead(_17); StorageDead(_16); - StorageLive(_18); +- StorageLive(_18); ++ nop; _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 +127,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 +169,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,21 +177,26 @@ 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); - StorageDead(_13); - StorageDead(_8); +- StorageDead(_18); +- StorageDead(_13); +- StorageDead(_8); ++ nop; ++ nop; ++ nop; return; } } diff --git a/tests/mir-opt/gvn.duplicate_slice.GVN.panic-abort.diff b/tests/mir-opt/gvn.duplicate_slice.GVN.panic-abort.diff new file mode 100644 index 0000000000000..7ae1fae68e887 --- /dev/null +++ b/tests/mir-opt/gvn.duplicate_slice.GVN.panic-abort.diff @@ -0,0 +1,38 @@ +- // MIR for `duplicate_slice` before GVN ++ // MIR for `duplicate_slice` after GVN + + fn duplicate_slice() -> (bool, bool) { + let mut _0: (bool, bool); + let mut _1: u128; + let mut _2: u128; + let mut _3: u128; + let mut _4: u128; + let mut _5: &str; + let mut _6: &str; + let mut _7: (&str,); + let mut _8: &str; + let mut _9: bool; + let mut _10: bool; + + bb0: { + _7 = (const "a",); + _1 = (_7.0: &str) as u128 (Transmute); + _5 = identity::<&str>((_7.0: &str)) -> [return: bb1, unwind unreachable]; + } + + bb1: { + _3 = _5 as u128 (Transmute); + _8 = const "a"; + _2 = _8 as u128 (Transmute); + _6 = identity::<&str>(_8) -> [return: bb2, unwind unreachable]; + } + + bb2: { + _4 = _6 as u128 (Transmute); + _9 = Eq(_1, _2); + _10 = Eq(_3, _4); + _0 = (_9, _10); + return; + } + } + diff --git a/tests/mir-opt/gvn.duplicate_slice.GVN.panic-unwind.diff b/tests/mir-opt/gvn.duplicate_slice.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..8c96edaa280ea --- /dev/null +++ b/tests/mir-opt/gvn.duplicate_slice.GVN.panic-unwind.diff @@ -0,0 +1,38 @@ +- // MIR for `duplicate_slice` before GVN ++ // MIR for `duplicate_slice` after GVN + + fn duplicate_slice() -> (bool, bool) { + let mut _0: (bool, bool); + let mut _1: u128; + let mut _2: u128; + let mut _3: u128; + let mut _4: u128; + let mut _5: &str; + let mut _6: &str; + let mut _7: (&str,); + let mut _8: &str; + let mut _9: bool; + let mut _10: bool; + + bb0: { + _7 = (const "a",); + _1 = (_7.0: &str) as u128 (Transmute); + _5 = identity::<&str>((_7.0: &str)) -> [return: bb1, unwind continue]; + } + + bb1: { + _3 = _5 as u128 (Transmute); + _8 = const "a"; + _2 = _8 as u128 (Transmute); + _6 = identity::<&str>(_8) -> [return: bb2, unwind continue]; + } + + bb2: { + _4 = _6 as u128 (Transmute); + _9 = Eq(_1, _2); + _10 = Eq(_3, _4); + _0 = (_9, _10); + return; + } + } + diff --git a/tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff b/tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff new file mode 100644 index 0000000000000..d8248d22d38b9 --- /dev/null +++ b/tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff @@ -0,0 +1,118 @@ +- // MIR for `fn_pointers` before GVN ++ // MIR for `fn_pointers` after GVN + + fn fn_pointers() -> () { + let mut _0: (); + let _1: fn(u8) -> u8; + let _2: (); + let mut _3: fn(u8) -> u8; + let _5: (); + let mut _6: fn(u8) -> u8; + let mut _9: {closure@$DIR/gvn.rs:591:19: 591:21}; + let _10: (); + let mut _11: fn(); + let mut _13: {closure@$DIR/gvn.rs:591:19: 591:21}; + let _14: (); + let mut _15: fn(); + scope 1 { + debug f => _1; + let _4: fn(u8) -> u8; + scope 2 { + debug g => _4; + let _7: {closure@$DIR/gvn.rs:591:19: 591:21}; + scope 3 { + debug closure => _7; + let _8: fn(); + scope 4 { + debug cf => _8; + let _12: fn(); + scope 5 { + debug cg => _12; + } + } + } + } + } + + bb0: { +- StorageLive(_1); ++ nop; + _1 = identity:: as fn(u8) -> u8 (PointerCoercion(ReifyFnPointer)); + StorageLive(_2); + StorageLive(_3); + _3 = _1; +- _2 = opaque:: u8>(move _3) -> [return: bb1, unwind unreachable]; ++ _2 = opaque:: u8>(_1) -> [return: bb1, unwind unreachable]; + } + + bb1: { + StorageDead(_3); + StorageDead(_2); +- StorageLive(_4); ++ nop; + _4 = identity:: as fn(u8) -> u8 (PointerCoercion(ReifyFnPointer)); + StorageLive(_5); + StorageLive(_6); + _6 = _4; +- _5 = opaque:: u8>(move _6) -> [return: bb2, unwind unreachable]; ++ _5 = opaque:: u8>(_4) -> [return: bb2, unwind unreachable]; + } + + bb2: { + StorageDead(_6); + StorageDead(_5); +- StorageLive(_7); +- _7 = {closure@$DIR/gvn.rs:591:19: 591:21}; +- StorageLive(_8); ++ nop; ++ _7 = const ZeroSized: {closure@$DIR/gvn.rs:591:19: 591:21}; ++ nop; + StorageLive(_9); +- _9 = _7; +- _8 = move _9 as fn() (PointerCoercion(ClosureFnPointer(Normal))); ++ _9 = const ZeroSized: {closure@$DIR/gvn.rs:591:19: 591:21}; ++ _8 = const ZeroSized: {closure@$DIR/gvn.rs:591:19: 591:21} as fn() (PointerCoercion(ClosureFnPointer(Normal))); + StorageDead(_9); + StorageLive(_10); + StorageLive(_11); + _11 = _8; +- _10 = opaque::(move _11) -> [return: bb3, unwind unreachable]; ++ _10 = opaque::(_8) -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_11); + StorageDead(_10); +- StorageLive(_12); ++ nop; + StorageLive(_13); +- _13 = _7; +- _12 = move _13 as fn() (PointerCoercion(ClosureFnPointer(Normal))); ++ _13 = const ZeroSized: {closure@$DIR/gvn.rs:591:19: 591:21}; ++ _12 = const ZeroSized: {closure@$DIR/gvn.rs:591:19: 591:21} as fn() (PointerCoercion(ClosureFnPointer(Normal))); + StorageDead(_13); + StorageLive(_14); + StorageLive(_15); + _15 = _12; +- _14 = opaque::(move _15) -> [return: bb4, unwind unreachable]; ++ _14 = opaque::(_12) -> [return: bb4, unwind unreachable]; + } + + bb4: { + StorageDead(_15); + StorageDead(_14); + _0 = const (); +- StorageDead(_12); +- StorageDead(_8); +- StorageDead(_7); +- StorageDead(_4); +- StorageDead(_1); ++ nop; ++ nop; ++ nop; ++ nop; ++ nop; + return; + } + } + diff --git a/tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff b/tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..e38a3d8520927 --- /dev/null +++ b/tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff @@ -0,0 +1,118 @@ +- // MIR for `fn_pointers` before GVN ++ // MIR for `fn_pointers` after GVN + + fn fn_pointers() -> () { + let mut _0: (); + let _1: fn(u8) -> u8; + let _2: (); + let mut _3: fn(u8) -> u8; + let _5: (); + let mut _6: fn(u8) -> u8; + let mut _9: {closure@$DIR/gvn.rs:591:19: 591:21}; + let _10: (); + let mut _11: fn(); + let mut _13: {closure@$DIR/gvn.rs:591:19: 591:21}; + let _14: (); + let mut _15: fn(); + scope 1 { + debug f => _1; + let _4: fn(u8) -> u8; + scope 2 { + debug g => _4; + let _7: {closure@$DIR/gvn.rs:591:19: 591:21}; + scope 3 { + debug closure => _7; + let _8: fn(); + scope 4 { + debug cf => _8; + let _12: fn(); + scope 5 { + debug cg => _12; + } + } + } + } + } + + bb0: { +- StorageLive(_1); ++ nop; + _1 = identity:: as fn(u8) -> u8 (PointerCoercion(ReifyFnPointer)); + StorageLive(_2); + StorageLive(_3); + _3 = _1; +- _2 = opaque:: u8>(move _3) -> [return: bb1, unwind continue]; ++ _2 = opaque:: u8>(_1) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageDead(_3); + StorageDead(_2); +- StorageLive(_4); ++ nop; + _4 = identity:: as fn(u8) -> u8 (PointerCoercion(ReifyFnPointer)); + StorageLive(_5); + StorageLive(_6); + _6 = _4; +- _5 = opaque:: u8>(move _6) -> [return: bb2, unwind continue]; ++ _5 = opaque:: u8>(_4) -> [return: bb2, unwind continue]; + } + + bb2: { + StorageDead(_6); + StorageDead(_5); +- StorageLive(_7); +- _7 = {closure@$DIR/gvn.rs:591:19: 591:21}; +- StorageLive(_8); ++ nop; ++ _7 = const ZeroSized: {closure@$DIR/gvn.rs:591:19: 591:21}; ++ nop; + StorageLive(_9); +- _9 = _7; +- _8 = move _9 as fn() (PointerCoercion(ClosureFnPointer(Normal))); ++ _9 = const ZeroSized: {closure@$DIR/gvn.rs:591:19: 591:21}; ++ _8 = const ZeroSized: {closure@$DIR/gvn.rs:591:19: 591:21} as fn() (PointerCoercion(ClosureFnPointer(Normal))); + StorageDead(_9); + StorageLive(_10); + StorageLive(_11); + _11 = _8; +- _10 = opaque::(move _11) -> [return: bb3, unwind continue]; ++ _10 = opaque::(_8) -> [return: bb3, unwind continue]; + } + + bb3: { + StorageDead(_11); + StorageDead(_10); +- StorageLive(_12); ++ nop; + StorageLive(_13); +- _13 = _7; +- _12 = move _13 as fn() (PointerCoercion(ClosureFnPointer(Normal))); ++ _13 = const ZeroSized: {closure@$DIR/gvn.rs:591:19: 591:21}; ++ _12 = const ZeroSized: {closure@$DIR/gvn.rs:591:19: 591:21} as fn() (PointerCoercion(ClosureFnPointer(Normal))); + StorageDead(_13); + StorageLive(_14); + StorageLive(_15); + _15 = _12; +- _14 = opaque::(move _15) -> [return: bb4, unwind continue]; ++ _14 = opaque::(_12) -> [return: bb4, unwind continue]; + } + + bb4: { + StorageDead(_15); + StorageDead(_14); + _0 = const (); +- StorageDead(_12); +- StorageDead(_8); +- StorageDead(_7); +- StorageDead(_4); +- StorageDead(_1); ++ nop; ++ nop; ++ nop; ++ nop; ++ nop; + return; + } + } + diff --git a/tests/mir-opt/gvn.indirect_static.GVN.panic-abort.diff b/tests/mir-opt/gvn.indirect_static.GVN.panic-abort.diff new file mode 100644 index 0000000000000..f853942bbb664 --- /dev/null +++ b/tests/mir-opt/gvn.indirect_static.GVN.panic-abort.diff @@ -0,0 +1,19 @@ +- // MIR for `indirect_static` before GVN ++ // MIR for `indirect_static` after GVN + + fn indirect_static() -> () { + let mut _0: (); + let mut _1: &std::option::Option; + let mut _2: u8; + + bb0: { + _1 = const {ALLOC0: &Option}; + _2 = (((*_1) as variant#1).0: u8); + return; + } + } + + ALLOC0 (static: A, size: 2, align: 1) { + 00 __ │ .░ + } + diff --git a/tests/mir-opt/gvn.indirect_static.GVN.panic-unwind.diff b/tests/mir-opt/gvn.indirect_static.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..f853942bbb664 --- /dev/null +++ b/tests/mir-opt/gvn.indirect_static.GVN.panic-unwind.diff @@ -0,0 +1,19 @@ +- // MIR for `indirect_static` before GVN ++ // MIR for `indirect_static` after GVN + + fn indirect_static() -> () { + let mut _0: (); + let mut _1: &std::option::Option; + let mut _2: u8; + + bb0: { + _1 = const {ALLOC0: &Option}; + _2 = (((*_1) as variant#1).0: u8); + return; + } + } + + ALLOC0 (static: A, size: 2, align: 1) { + 00 __ │ .░ + } + 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.references.GVN.panic-abort.diff b/tests/mir-opt/gvn.references.GVN.panic-abort.diff index b7ad4ab1fd3d8..7799c61144526 100644 --- a/tests/mir-opt/gvn.references.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.references.GVN.panic-abort.diff @@ -20,6 +20,24 @@ let mut _15: *mut impl Sized; let _16: (); let mut _17: *mut impl Sized; + let _18: &mut impl Sized; + let mut _20: S<&mut impl Sized>; + let mut _21: &mut impl Sized; + let _22: (); + let mut _23: &impl Sized; + let _24: (); + let mut _25: &mut impl Sized; + let _26: (); + let mut _27: *const impl Sized; + let _28: (); + let mut _29: *mut impl Sized; + scope 1 { + debug r => _18; + let _19: &mut impl Sized; + scope 2 { + debug s => _19; + } + } bb0: { StorageLive(_2); @@ -94,11 +112,68 @@ bb8: { StorageDead(_17); StorageDead(_16); - _0 = const (); - drop(_1) -> [return: bb9, unwind unreachable]; +- StorageLive(_18); ++ nop; + _18 = &mut _1; + StorageLive(_19); + StorageLive(_20); + StorageLive(_21); +- _21 = move _18; +- _20 = S::<&mut impl Sized>(move _21); ++ _21 = _18; ++ _20 = S::<&mut impl Sized>(_18); + StorageDead(_21); +- _19 = move (_20.0: &mut impl Sized); ++ _19 = _18; + StorageDead(_20); + StorageLive(_22); + StorageLive(_23); +- _23 = &(*_19); ++ _23 = &(*_18); + _22 = opaque::<&impl Sized>(move _23) -> [return: bb9, unwind unreachable]; } bb9: { + StorageDead(_23); + StorageDead(_22); + StorageLive(_24); + StorageLive(_25); +- _25 = &mut (*_19); ++ _25 = &mut (*_18); + _24 = opaque::<&mut impl Sized>(move _25) -> [return: bb10, unwind unreachable]; + } + + bb10: { + StorageDead(_25); + StorageDead(_24); + StorageLive(_26); + StorageLive(_27); +- _27 = &raw const (*_19); ++ _27 = &raw const (*_18); + _26 = opaque::<*const impl Sized>(move _27) -> [return: bb11, unwind unreachable]; + } + + bb11: { + StorageDead(_27); + StorageDead(_26); + StorageLive(_28); + StorageLive(_29); +- _29 = &raw mut (*_19); ++ _29 = &raw mut (*_18); + _28 = opaque::<*mut impl Sized>(move _29) -> [return: bb12, unwind unreachable]; + } + + bb12: { + StorageDead(_29); + StorageDead(_28); + _0 = const (); + StorageDead(_19); +- StorageDead(_18); ++ nop; + drop(_1) -> [return: bb13, unwind unreachable]; + } + + bb13: { return; } } diff --git a/tests/mir-opt/gvn.references.GVN.panic-unwind.diff b/tests/mir-opt/gvn.references.GVN.panic-unwind.diff index 08ed4c629a6dd..880e7913fa94c 100644 --- a/tests/mir-opt/gvn.references.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.references.GVN.panic-unwind.diff @@ -20,12 +20,30 @@ let mut _15: *mut impl Sized; let _16: (); let mut _17: *mut impl Sized; + let _18: &mut impl Sized; + let mut _20: S<&mut impl Sized>; + let mut _21: &mut impl Sized; + let _22: (); + let mut _23: &impl Sized; + let _24: (); + let mut _25: &mut impl Sized; + let _26: (); + let mut _27: *const impl Sized; + let _28: (); + let mut _29: *mut impl Sized; + scope 1 { + debug r => _18; + let _19: &mut impl Sized; + scope 2 { + debug s => _19; + } + } bb0: { StorageLive(_2); StorageLive(_3); _3 = &_1; - _2 = opaque::<&impl Sized>(move _3) -> [return: bb1, unwind: bb10]; + _2 = opaque::<&impl Sized>(move _3) -> [return: bb1, unwind: bb14]; } bb1: { @@ -34,7 +52,7 @@ StorageLive(_4); StorageLive(_5); _5 = &_1; - _4 = opaque::<&impl Sized>(move _5) -> [return: bb2, unwind: bb10]; + _4 = opaque::<&impl Sized>(move _5) -> [return: bb2, unwind: bb14]; } bb2: { @@ -43,7 +61,7 @@ StorageLive(_6); StorageLive(_7); _7 = &mut _1; - _6 = opaque::<&mut impl Sized>(move _7) -> [return: bb3, unwind: bb10]; + _6 = opaque::<&mut impl Sized>(move _7) -> [return: bb3, unwind: bb14]; } bb3: { @@ -52,7 +70,7 @@ StorageLive(_8); StorageLive(_9); _9 = &mut _1; - _8 = opaque::<&mut impl Sized>(move _9) -> [return: bb4, unwind: bb10]; + _8 = opaque::<&mut impl Sized>(move _9) -> [return: bb4, unwind: bb14]; } bb4: { @@ -61,7 +79,7 @@ StorageLive(_10); StorageLive(_11); _11 = &raw const _1; - _10 = opaque::<*const impl Sized>(move _11) -> [return: bb5, unwind: bb10]; + _10 = opaque::<*const impl Sized>(move _11) -> [return: bb5, unwind: bb14]; } bb5: { @@ -70,7 +88,7 @@ StorageLive(_12); StorageLive(_13); _13 = &raw const _1; - _12 = opaque::<*const impl Sized>(move _13) -> [return: bb6, unwind: bb10]; + _12 = opaque::<*const impl Sized>(move _13) -> [return: bb6, unwind: bb14]; } bb6: { @@ -79,7 +97,7 @@ StorageLive(_14); StorageLive(_15); _15 = &raw mut _1; - _14 = opaque::<*mut impl Sized>(move _15) -> [return: bb7, unwind: bb10]; + _14 = opaque::<*mut impl Sized>(move _15) -> [return: bb7, unwind: bb14]; } bb7: { @@ -88,25 +106,82 @@ StorageLive(_16); StorageLive(_17); _17 = &raw mut _1; - _16 = opaque::<*mut impl Sized>(move _17) -> [return: bb8, unwind: bb10]; + _16 = opaque::<*mut impl Sized>(move _17) -> [return: bb8, unwind: bb14]; } bb8: { StorageDead(_17); StorageDead(_16); - _0 = const (); - drop(_1) -> [return: bb9, unwind: bb11]; +- StorageLive(_18); ++ nop; + _18 = &mut _1; + StorageLive(_19); + StorageLive(_20); + StorageLive(_21); +- _21 = move _18; +- _20 = S::<&mut impl Sized>(move _21); ++ _21 = _18; ++ _20 = S::<&mut impl Sized>(_18); + StorageDead(_21); +- _19 = move (_20.0: &mut impl Sized); ++ _19 = _18; + StorageDead(_20); + StorageLive(_22); + StorageLive(_23); +- _23 = &(*_19); ++ _23 = &(*_18); + _22 = opaque::<&impl Sized>(move _23) -> [return: bb9, unwind: bb14]; } bb9: { + StorageDead(_23); + StorageDead(_22); + StorageLive(_24); + StorageLive(_25); +- _25 = &mut (*_19); ++ _25 = &mut (*_18); + _24 = opaque::<&mut impl Sized>(move _25) -> [return: bb10, unwind: bb14]; + } + + bb10: { + StorageDead(_25); + StorageDead(_24); + StorageLive(_26); + StorageLive(_27); +- _27 = &raw const (*_19); ++ _27 = &raw const (*_18); + _26 = opaque::<*const impl Sized>(move _27) -> [return: bb11, unwind: bb14]; + } + + bb11: { + StorageDead(_27); + StorageDead(_26); + StorageLive(_28); + StorageLive(_29); +- _29 = &raw mut (*_19); ++ _29 = &raw mut (*_18); + _28 = opaque::<*mut impl Sized>(move _29) -> [return: bb12, unwind: bb14]; + } + + bb12: { + StorageDead(_29); + StorageDead(_28); + _0 = const (); + StorageDead(_19); +- StorageDead(_18); ++ nop; + drop(_1) -> [return: bb13, unwind: bb15]; + } + + bb13: { return; } - bb10 (cleanup): { - drop(_1) -> [return: bb11, unwind terminate(cleanup)]; + bb14 (cleanup): { + drop(_1) -> [return: bb15, unwind terminate(cleanup)]; } - bb11 (cleanup): { + bb15 (cleanup): { resume; } } diff --git a/tests/mir-opt/gvn.repeat.GVN.panic-abort.diff b/tests/mir-opt/gvn.repeat.GVN.panic-abort.diff new file mode 100644 index 0000000000000..37915f8578d21 --- /dev/null +++ b/tests/mir-opt/gvn.repeat.GVN.panic-abort.diff @@ -0,0 +1,79 @@ +- // MIR for `repeat` before GVN ++ // MIR for `repeat` after GVN + + fn repeat() -> () { + let mut _0: (); + let _1: i32; + let mut _3: i32; + let mut _4: i32; + let mut _5: i32; + let mut _6: i32; + let mut _7: i32; + let mut _8: i32; + let mut _9: i32; + let mut _10: i32; + let mut _11: i32; + let mut _12: i32; + scope 1 { + debug val => _1; + let _2: [i32; 10]; + scope 2 { + debug array => _2; + } + } + + bb0: { +- StorageLive(_1); ++ nop; + _1 = const 5_i32; + StorageLive(_2); + StorageLive(_3); +- _3 = _1; ++ _3 = const 5_i32; + StorageLive(_4); +- _4 = _1; ++ _4 = const 5_i32; + StorageLive(_5); +- _5 = _1; ++ _5 = const 5_i32; + StorageLive(_6); +- _6 = _1; ++ _6 = const 5_i32; + StorageLive(_7); +- _7 = _1; ++ _7 = const 5_i32; + StorageLive(_8); +- _8 = _1; ++ _8 = const 5_i32; + StorageLive(_9); +- _9 = _1; ++ _9 = const 5_i32; + StorageLive(_10); +- _10 = _1; ++ _10 = const 5_i32; + StorageLive(_11); +- _11 = _1; ++ _11 = const 5_i32; + StorageLive(_12); +- _12 = _1; +- _2 = [move _3, move _4, move _5, move _6, move _7, move _8, move _9, move _10, move _11, move _12]; ++ _12 = const 5_i32; ++ _2 = [const 5_i32; 10]; + StorageDead(_12); + StorageDead(_11); + StorageDead(_10); + StorageDead(_9); + StorageDead(_8); + StorageDead(_7); + StorageDead(_6); + StorageDead(_5); + StorageDead(_4); + StorageDead(_3); + _0 = const (); + StorageDead(_2); +- StorageDead(_1); ++ nop; + return; + } + } + diff --git a/tests/mir-opt/gvn.repeat.GVN.panic-unwind.diff b/tests/mir-opt/gvn.repeat.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..37915f8578d21 --- /dev/null +++ b/tests/mir-opt/gvn.repeat.GVN.panic-unwind.diff @@ -0,0 +1,79 @@ +- // MIR for `repeat` before GVN ++ // MIR for `repeat` after GVN + + fn repeat() -> () { + let mut _0: (); + let _1: i32; + let mut _3: i32; + let mut _4: i32; + let mut _5: i32; + let mut _6: i32; + let mut _7: i32; + let mut _8: i32; + let mut _9: i32; + let mut _10: i32; + let mut _11: i32; + let mut _12: i32; + scope 1 { + debug val => _1; + let _2: [i32; 10]; + scope 2 { + debug array => _2; + } + } + + bb0: { +- StorageLive(_1); ++ nop; + _1 = const 5_i32; + StorageLive(_2); + StorageLive(_3); +- _3 = _1; ++ _3 = const 5_i32; + StorageLive(_4); +- _4 = _1; ++ _4 = const 5_i32; + StorageLive(_5); +- _5 = _1; ++ _5 = const 5_i32; + StorageLive(_6); +- _6 = _1; ++ _6 = const 5_i32; + StorageLive(_7); +- _7 = _1; ++ _7 = const 5_i32; + StorageLive(_8); +- _8 = _1; ++ _8 = const 5_i32; + StorageLive(_9); +- _9 = _1; ++ _9 = const 5_i32; + StorageLive(_10); +- _10 = _1; ++ _10 = const 5_i32; + StorageLive(_11); +- _11 = _1; ++ _11 = const 5_i32; + StorageLive(_12); +- _12 = _1; +- _2 = [move _3, move _4, move _5, move _6, move _7, move _8, move _9, move _10, move _11, move _12]; ++ _12 = const 5_i32; ++ _2 = [const 5_i32; 10]; + StorageDead(_12); + StorageDead(_11); + StorageDead(_10); + StorageDead(_9); + StorageDead(_8); + StorageDead(_7); + StorageDead(_6); + StorageDead(_5); + StorageDead(_4); + StorageDead(_3); + _0 = const (); + StorageDead(_2); +- StorageDead(_1); ++ nop; + 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..d937902e89138 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); @@ -40,8 +40,10 @@ } bb1: { - _6 = _3[_7]; - _5 = opaque::(move _6) -> [return: bb2, unwind unreachable]; +- _6 = _3[_7]; +- _5 = opaque::(move _6) -> [return: bb2, unwind unreachable]; ++ _6 = _1; ++ _5 = opaque::(_1) -> [return: bb2, unwind unreachable]; } bb2: { @@ -55,13 +57,16 @@ - _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]; } bb3: { - _11 = _3[_12]; - _10 = opaque::(move _11) -> [return: bb4, unwind unreachable]; +- _11 = _3[_12]; +- _10 = opaque::(move _11) -> [return: bb4, unwind unreachable]; ++ _11 = _1; ++ _10 = opaque::(_1) -> [return: bb4, unwind unreachable]; } bb4: { 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..dd4d24b12ea61 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); @@ -40,8 +40,10 @@ } bb1: { - _6 = _3[_7]; - _5 = opaque::(move _6) -> [return: bb2, unwind continue]; +- _6 = _3[_7]; +- _5 = opaque::(move _6) -> [return: bb2, unwind continue]; ++ _6 = _1; ++ _5 = opaque::(_1) -> [return: bb2, unwind continue]; } bb2: { @@ -55,13 +57,16 @@ - _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]; } bb3: { - _11 = _3[_12]; - _10 = opaque::(move _11) -> [return: bb4, unwind continue]; +- _11 = _3[_12]; +- _10 = opaque::(move _11) -> [return: bb4, unwind continue]; ++ _11 = _1; ++ _10 = opaque::(_1) -> [return: bb4, unwind continue]; } bb4: { diff --git a/tests/mir-opt/gvn.rs b/tests/mir-opt/gvn.rs index fd24edc676c4b..10a66ced026e4 100644 --- a/tests/mir-opt/gvn.rs +++ b/tests/mir-opt/gvn.rs @@ -1,56 +1,133 @@ -// skip-filecheck // unit-test: GVN // EMIT_MIR_FOR_EACH_PANIC_STRATEGY +// only-64bit #![feature(raw_ref_op)] #![feature(rustc_attrs)] +#![feature(custom_mir)] +#![feature(core_intrinsics)] #![allow(unconditional_panic)] +use std::intrinsics::mir::*; +use std::mem::transmute; + struct S(T); fn subexpression_elimination(x: u64, y: u64, mut z: u64) { + // CHECK-LABEL: fn subexpression_elimination( + + // CHECK: [[add:_.*]] = Add(_1, _2); + // CHECK: opaque::([[add]]) opaque(x + y); + // CHECK: [[mul:_.*]] = Mul(_1, _2); + // CHECK: opaque::([[mul]]) opaque(x * y); + // CHECK: [[sub:_.*]] = Sub(_1, _2); + // CHECK: opaque::([[sub]]) opaque(x - y); + // CHECK: [[div:_.*]] = Div(_1, _2); + // CHECK: opaque::([[div]]) opaque(x / y); + // CHECK: [[rem:_.*]] = Rem(_1, _2); + // CHECK: opaque::([[rem]]) opaque(x % y); + // CHECK: [[and:_.*]] = BitAnd(_1, _2); + // CHECK: opaque::([[and]]) opaque(x & y); + // CHECK: [[or:_.*]] = BitOr(_1, _2); + // CHECK: opaque::([[or]]) opaque(x | y); + // CHECK: [[xor:_.*]] = BitXor(_1, _2); + // CHECK: opaque::([[xor]]) opaque(x ^ y); + // CHECK: [[shl:_.*]] = Shl(_1, _2); + // CHECK: opaque::([[shl]]) opaque(x << y); + // CHECK: [[shr:_.*]] = Shr(_1, _2); + // CHECK: opaque::([[shr]]) opaque(x >> y); + // CHECK: [[int:_.*]] = _1 as u32 (IntToInt); + // CHECK: opaque::([[int]]) opaque(x as u32); + // CHECK: [[float:_.*]] = _1 as f32 (IntToFloat); + // CHECK: opaque::([[float]]) opaque(x as f32); + // CHECK: [[wrap:_.*]] = S::(_1); + // CHECK: opaque::>([[wrap]]) opaque(S(x)); + // CHECK: opaque::(_1) 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); + // CHECK: opaque::([[add]]) + opaque(x + y); + // CHECK: opaque::([[mul]]) + opaque(x * y); + // CHECK: opaque::([[sub]]) + opaque(x - y); + // CHECK: opaque::([[div]]) + opaque(x / y); + // CHECK: opaque::([[rem]]) + opaque(x % y); + // CHECK: opaque::([[and]]) + opaque(x & y); + // CHECK: opaque::([[or]]) + opaque(x | y); + // CHECK: opaque::([[xor]]) + opaque(x ^ y); + // CHECK: opaque::([[shl]]) + opaque(x << y); + // CHECK: opaque::([[shr]]) + opaque(x >> y); + // CHECK: opaque::([[int]]) + opaque(x as u32); + // CHECK: opaque::([[float]]) + opaque(x as f32); + // CHECK: opaque::>([[wrap]]) opaque(S(x)); + // CHECK: opaque::(_1) opaque(S(x).0); + // We can substitute through a complex expression. + // CHECK: [[compound:_.*]] = Sub([[mul]], _2); + // CHECK: opaque::([[compound]]) + // CHECK: opaque::([[compound]]) + opaque((x * y) - y); + opaque((x * y) - y); + // We can substitute through an immutable reference too. + // CHECK: [[ref:_.*]] = &_3; + // CHECK: [[deref:_.*]] = (*[[ref]]); + // CHECK: [[addref:_.*]] = Add([[deref]], _1); + // CHECK: opaque::([[addref]]) + // CHECK: opaque::([[addref]]) let a = &z; opaque(*a + x); opaque(*a + x); // But not through a mutable reference or a pointer. + // CHECK: [[mut:_.*]] = &mut _3; + // CHECK: [[addmut:_.*]] = Add( + // CHECK: opaque::(move [[addmut]]) + // CHECK: [[addmut2:_.*]] = Add( + // CHECK: opaque::(move [[addmut2]]) let b = &mut z; opaque(*b + x); opaque(*b + x); unsafe { + // CHECK: [[raw:_.*]] = &raw const _3; + // CHECK: [[addraw:_.*]] = Add( + // CHECK: opaque::(move [[addraw]]) + // CHECK: [[addraw2:_.*]] = Add( + // CHECK: opaque::(move [[addraw2]]) let c = &raw const z; opaque(*c + x); opaque(*c + x); + // CHECK: [[ptr:_.*]] = &raw mut _3; + // CHECK: [[addptr:_.*]] = Add( + // CHECK: opaque::(move [[addptr]]) + // CHECK: [[addptr2:_.*]] = Add( + // CHECK: opaque::(move [[addptr2]]) let d = &raw mut z; opaque(*d + x); opaque(*d + x); @@ -58,13 +135,21 @@ fn subexpression_elimination(x: u64, y: u64, mut z: u64) { // We can substitute again, but not with the earlier computations. // Important: `e` is not `a`! + // CHECK: [[ref2:_.*]] = &_3; + // CHECK: [[deref2:_.*]] = (*[[ref2]]); + // CHECK: [[addref2:_.*]] = Add([[deref2]], _1); + // CHECK: opaque::([[addref2]]) + // CHECK: opaque::([[addref2]]) let e = &z; opaque(*e + x); opaque(*e + x); - } fn wrap_unwrap(x: T) -> T { + // CHECK-LABEL: fn wrap_unwrap( + // CHECK: [[some:_.*]] = Option::::Some(_1); + // CHECK: switchInt(const 1_isize) + // CHECK: _0 = _1; match Some(x) { Some(y) => y, None => panic!(), @@ -72,163 +157,464 @@ fn wrap_unwrap(x: T) -> T { } fn repeated_index(x: T, idx: usize) { + // CHECK-LABEL: fn repeated_index( + // CHECK: [[a:_.*]] = [_1; N]; let a = [x; N]; + // CHECK: opaque::(_1) opaque(a[0]); + // CHECK: opaque::(_1) opaque(a[idx]); } +/// Verify symbolic integer arithmetic simplifications. fn arithmetic(x: u64) { + // CHECK-LABEL: fn arithmetic( + // CHECK: [[add:_.*]] = Add(_1, const 0_u64); + // CHECK: opaque::(move [[add]]) opaque(x + 0); + // CHECK: [[sub:_.*]] = Sub(_1, const 0_u64); + // CHECK: opaque::(move [[sub]]) opaque(x - 0); + // CHECK: [[mul0:_.*]] = Mul(_1, const 0_u64); + // CHECK: opaque::(move [[mul0]]) opaque(x * 0); + // CHECK: [[mul1:_.*]] = Mul(_1, const 1_u64); + // CHECK: opaque::(move [[mul1]]) opaque(x * 1); + // CHECK: [[div0:_.*]] = Div(_1, const 0_u64); + // CHECK: opaque::(move [[div0]]) opaque(x / 0); + // CHECK: [[div1:_.*]] = Div(_1, const 1_u64); + // CHECK: opaque::(move [[div1]]) opaque(x / 1); + // CHECK: [[zdiv:_.*]] = Div(const 0_u64, _1); + // CHECK: opaque::(move [[zdiv]]) opaque(0 / x); + // CHECK: [[odiv:_.*]] = Div(const 1_u64, _1); + // CHECK: opaque::(move [[odiv]]) opaque(1 / x); + // CHECK: [[rem0:_.*]] = Rem(_1, const 0_u64); + // CHECK: opaque::(move [[rem0]]) opaque(x % 0); + // CHECK: [[rem1:_.*]] = Rem(_1, const 1_u64); + // CHECK: opaque::(move [[rem1]]) opaque(x % 1); + // CHECK: [[zrem:_.*]] = Rem(const 0_u64, _1); + // CHECK: opaque::(move [[zrem]]) opaque(0 % x); + // CHECK: [[orem:_.*]] = Rem(const 1_u64, _1); + // CHECK: opaque::(move [[orem]]) opaque(1 % x); + // CHECK: [[and:_.*]] = BitAnd(_1, const 0_u64); + // CHECK: opaque::(move [[and]]) opaque(x & 0); + // CHECK: [[or:_.*]] = BitOr(_1, const 0_u64); + // CHECK: opaque::(move [[or]]) opaque(x | 0); + // CHECK: [[xor:_.*]] = BitXor(_1, const 0_u64); + // CHECK: opaque::(move [[xor]]) opaque(x ^ 0); + // CHECK: [[shr:_.*]] = Shr(_1, const 0_i32); + // CHECK: opaque::(move [[shr]]) opaque(x >> 0); + // CHECK: [[shl:_.*]] = Shl(_1, const 0_i32); + // CHECK: opaque::(move [[shl]]) opaque(x << 0); } +fn comparison(x: u64, y: u64) { + // CHECK-LABEL: fn comparison( + // CHECK: [[eqxx:_.*]] = Eq(_1, _1); + // CHECK: opaque::(move [[eqxx]]) + opaque(x == x); + // CHECK: [[nexx:_.*]] = Ne(_1, _1); + // CHECK: opaque::(move [[nexx]]) + opaque(x != x); + // CHECK: [[eqxy:_.*]] = Eq(_1, _2); + // CHECK: opaque::(move [[eqxy]]) + opaque(x == y); + // CHECK: [[nexy:_.*]] = Ne(_1, _2); + // CHECK: opaque::(move [[nexy]]) + opaque(x != y); +} + +/// Verify symbolic integer arithmetic simplifications on checked ops. #[rustc_inherit_overflow_checks] fn arithmetic_checked(x: u64) { + // CHECK-LABEL: fn arithmetic_checked( + // CHECK: [[cadd:_.*]] = CheckedAdd(_1, const 0_u64); + // CHECK: [[add:_.*]] = move ([[cadd]].0: u64); + // CHECK: opaque::(move [[add]]) opaque(x + 0); + // CHECK: [[csub:_.*]] = CheckedSub(_1, const 0_u64); + // CHECK: [[sub:_.*]] = move ([[csub]].0: u64); + // CHECK: opaque::(move [[sub]]) opaque(x - 0); + // CHECK: [[cmul0:_.*]] = CheckedMul(_1, const 0_u64); + // CHECK: [[mul0:_.*]] = move ([[cmul0]].0: u64); + // CHECK: opaque::(move [[mul0]]) opaque(x * 0); + // CHECK: [[cmul1:_.*]] = CheckedMul(_1, const 1_u64); + // CHECK: [[mul1:_.*]] = move ([[cmul1]].0: u64); + // CHECK: opaque::(move [[mul1]]) 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); } +/// Verify that we do not apply arithmetic simplifications on floats. fn arithmetic_float(x: f64) { + // CHECK-LABEL: fn arithmetic_float( + // CHECK: [[add:_.*]] = Add(_1, const 0f64); + // CHECK: opaque::(move [[add]]) opaque(x + 0.); + // CHECK: [[sub:_.*]] = Sub(_1, const 0f64); + // CHECK: opaque::(move [[sub]]) opaque(x - 0.); + // CHECK: [[mul:_.*]] = Mul(_1, const 0f64); + // CHECK: opaque::(move [[mul]]) opaque(x * 0.); + // CHECK: [[div0:_.*]] = Div(_1, const 0f64); + // CHECK: opaque::(move [[div0]]) opaque(x / 0.); + // CHECK: [[zdiv:_.*]] = Div(const 0f64, _1); + // CHECK: opaque::(move [[zdiv]]) opaque(0. / x); + // CHECK: [[rem0:_.*]] = Rem(_1, const 0f64); + // CHECK: opaque::(move [[rem0]]) opaque(x % 0.); + // CHECK: [[zrem:_.*]] = Rem(const 0f64, _1); + // CHECK: opaque::(move [[zrem]]) opaque(0. % x); // Those are not simplifiable to `true`/`false`, thanks to NaNs. + // CHECK: [[eq:_.*]] = Eq(_1, _1); + // CHECK: opaque::(move [[eq]]) opaque(x == x); + // CHECK: [[ne:_.*]] = Ne(_1, _1); + // CHECK: opaque::(move [[ne]]) opaque(x != x); } fn cast() { + // CHECK-LABEL: fn cast( let i = 1_i64; let u = 1_u64; let f = 1_f64; + // CHECK: opaque::(const 1_u8) opaque(i as u8); + // CHECK: opaque::(const 1_u16) opaque(i as u16); + // CHECK: opaque::(const 1_u32) opaque(i as u32); + // CHECK: opaque::(const 1_u64) opaque(i as u64); + // CHECK: opaque::(const 1_i8) opaque(i as i8); + // CHECK: opaque::(const 1_i16) opaque(i as i16); + // CHECK: opaque::(const 1_i32) opaque(i as i32); + // CHECK: opaque::(const 1_i64) opaque(i as i64); + // CHECK: opaque::(const 1f32) opaque(i as f32); + // CHECK: opaque::(const 1f64) opaque(i as f64); + // CHECK: opaque::(const 1_u8) opaque(u as u8); + // CHECK: opaque::(const 1_u16) opaque(u as u16); + // CHECK: opaque::(const 1_u32) opaque(u as u32); + // CHECK: opaque::(const 1_u64) opaque(u as u64); + // CHECK: opaque::(const 1_i8) opaque(u as i8); + // CHECK: opaque::(const 1_i16) opaque(u as i16); + // CHECK: opaque::(const 1_i32) opaque(u as i32); + // CHECK: opaque::(const 1_i64) opaque(u as i64); + // CHECK: opaque::(const 1f32) opaque(u as f32); + // CHECK: opaque::(const 1f64) opaque(u as f64); + // CHECK: opaque::(const 1_u8) opaque(f as u8); + // CHECK: opaque::(const 1_u16) opaque(f as u16); + // CHECK: opaque::(const 1_u32) opaque(f as u32); + // CHECK: opaque::(const 1_u64) opaque(f as u64); + // CHECK: opaque::(const 1_i8) opaque(f as i8); + // CHECK: opaque::(const 1_i16) opaque(f as i16); + // CHECK: opaque::(const 1_i32) opaque(f as i32); + // CHECK: opaque::(const 1_i64) opaque(f as i64); + // CHECK: opaque::(const 1f32) opaque(f as f32); + // CHECK: opaque::(const 1f64) opaque(f as f64); } fn multiple_branches(t: bool, x: u8, y: u8) { + // CHECK-LABEL: fn multiple_branches( + // CHECK: switchInt(_1) -> [0: [[bbf:bb.*]], otherwise: [[bbt:bb.*]]]; if t { - opaque(x + y); // a - opaque(x + y); // should reuse a + // CHECK: [[bbt]]: { + // CHECK: [[a:_.*]] = Add(_2, _3); + // CHECK: opaque::([[a]]) + // CHECK: opaque::([[a]]) + // CHECK: goto -> [[bbc:bb.*]]; + opaque(x + y); + opaque(x + y); } else { - opaque(x + y); // b - opaque(x + y); // shoud reuse b + // CHECK: [[bbf]]: { + // CHECK: [[b:_.*]] = Add(_2, _3); + // CHECK: opaque::([[b]]) + // CHECK: opaque::([[b]]) + // CHECK: goto -> [[bbc:bb.*]]; + opaque(x + y); + opaque(x + y); } - opaque(x + y); // c + // Neither `a` nor `b` dominate `c`, so we cannot reuse any of them. + // CHECK: [[bbc]]: { + // CHECK: [[c:_.*]] = Add(_2, _3); + // CHECK: opaque::([[c]]) + opaque(x + y); + + // `c` dominates both calls, so we can reuse it. if t { - opaque(x + y); // should reuse c + // CHECK: opaque::([[c]]) + opaque(x + y); } else { - opaque(x + y); // should reuse c + // CHECK: opaque::([[c]]) + opaque(x + y); } } +/// Verify that we do not reuse a `&raw? mut?` rvalue. fn references(mut x: impl Sized) { + // CHECK-LABEL: fn references( + // CHECK: [[ref1:_.*]] = &_1; + // CHECK: opaque::<&impl Sized>(move [[ref1]]) opaque(&x); - opaque(&x); // should not reuse a + // CHECK: [[ref2:_.*]] = &_1; + // CHECK: opaque::<&impl Sized>(move [[ref2]]) + opaque(&x); + // CHECK: [[ref3:_.*]] = &mut _1; + // CHECK: opaque::<&mut impl Sized>(move [[ref3]]) + opaque(&mut x); + // CHECK: [[ref4:_.*]] = &mut _1; + // CHECK: opaque::<&mut impl Sized>(move [[ref4]]) opaque(&mut x); - opaque(&mut x); // should not reuse a + // CHECK: [[ref5:_.*]] = &raw const _1; + // CHECK: opaque::<*const impl Sized>(move [[ref5]]) opaque(&raw const x); - opaque(&raw const x); // should not reuse a + // CHECK: [[ref6:_.*]] = &raw const _1; + // CHECK: opaque::<*const impl Sized>(move [[ref6]]) + opaque(&raw const x); + // CHECK: [[ref7:_.*]] = &raw mut _1; + // CHECK: opaque::<*mut impl Sized>(move [[ref7]]) + opaque(&raw mut x); + // CHECK: [[ref8:_.*]] = &raw mut _1; + // CHECK: opaque::<*mut impl Sized>(move [[ref8]]) opaque(&raw mut x); - opaque(&raw mut x); // should not reuse a + + let r = &mut x; + let s = S(r).0; // Obfuscate `r`. Following lines should still reborrow `r`. + // CHECK: [[ref9:_.*]] = &mut _1; + // CHECK: [[ref10:_.*]] = &(*[[ref9]]); + // CHECK: opaque::<&impl Sized>(move [[ref10]]) + opaque(&*s); + // CHECK: [[ref11:_.*]] = &mut (*[[ref9]]); + // CHECK: opaque::<&mut impl Sized>(move [[ref11]]) + opaque(&mut *s); + // CHECK: [[ref12:_.*]] = &raw const (*[[ref9]]); + // CHECK: opaque::<*const impl Sized>(move [[ref12]]) + opaque(&raw const *s); + // CHECK: [[ref12:_.*]] = &raw mut (*[[ref9]]); + // CHECK: opaque::<*mut impl Sized>(move [[ref12]]) + opaque(&raw mut *s); } fn dereferences(t: &mut u32, u: &impl Copy, s: &S) { + // CHECK-LABEL: fn dereferences( + + // Do not reuse dereferences of `&mut`. + // CHECK: [[st1:_.*]] = (*_1); + // CHECK: opaque::(move [[st1]]) + // CHECK: [[st2:_.*]] = (*_1); + // CHECK: opaque::(move [[st2]]) opaque(*t); - opaque(*t); // this cannot reuse a, as x is &mut. + opaque(*t); + + // Do not reuse dereferences of `*const`. + // CHECK: [[raw:_.*]] = &raw const (*_1); + // CHECK: [[st3:_.*]] = (*[[raw]]); + // CHECK: opaque::(move [[st3]]) + // CHECK: [[st4:_.*]] = (*[[raw]]); + // CHECK: opaque::(move [[st4]]) let z = &raw const *t; unsafe { opaque(*z) }; - unsafe { opaque(*z) }; // this cannot reuse a, as x is *const. + unsafe { opaque(*z) }; + + // Do not reuse dereferences of `*mut`. + // CHECK: [[ptr:_.*]] = &raw mut (*_1); + // CHECK: [[st5:_.*]] = (*[[ptr]]); + // CHECK: opaque::(move [[st5]]) + // CHECK: [[st6:_.*]] = (*[[ptr]]); + // CHECK: opaque::(move [[st6]]) let z = &raw mut *t; unsafe { opaque(*z) }; - unsafe { opaque(*z) }; // this cannot reuse a, as x is *mut. + unsafe { opaque(*z) }; + + // We can reuse dereferences of `&Freeze`. + // CHECK: [[ref:_.*]] = &(*_1); + // CHECK: [[st7:_.*]] = (*[[ref]]); + // CHECK: opaque::([[st7]]) + // CHECK: opaque::([[st7]]) 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(*z); + // But not in reborrows. + // CHECK: [[reborrow:_.*]] = &(*[[ref]]); + // CHECK: opaque::<&u32>(move [[reborrow]]) + opaque(&*z); + + // `*u` is not Freeze, so we cannot reuse. + // CHECK: [[st8:_.*]] = (*_2); + // CHECK: opaque::(move [[st8]]) + // CHECK: [[st9:_.*]] = (*_2); + // CHECK: opaque::(move [[st9]]) opaque(*u); - opaque(*u); // this cannot reuse, as `z` is not Freeze. + opaque(*u); + + // `*s` is not Copy, by `(*s).0` is, so we can reuse. + // CHECK: [[st10:_.*]] = ((*_3).0: u32); + // CHECK: opaque::([[st10]]) + // CHECK: opaque::([[st10]]) + opaque(s.0); opaque(s.0); - opaque(s.0); // *s is not Copy, by (*s).0 is, so we can reuse. } fn slices() { + // CHECK-LABEL: fn slices( + // CHECK: {{_.*}} = const " + // CHECK-NOT: {{_.*}} = const " 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) }; + let u = unsafe { transmute::<&str, &[u8]>(s) }; opaque(u); assert_eq!(s.as_ptr(), u.as_ptr()); } +#[custom_mir(dialect = "analysis")] +fn duplicate_slice() -> (bool, bool) { + // CHECK-LABEL: fn duplicate_slice( + mir!( + let au: u128; + let bu: u128; + let cu: u128; + let du: u128; + let c: &str; + let d: &str; + { + // CHECK: [[a:_.*]] = (const "a",); + // CHECK: [[au:_.*]] = ([[a]].0: &str) as u128 (Transmute); + let a = ("a",); + Call(au = transmute::<_, u128>(a.0), bb1) + } + bb1 = { + // CHECK: [[c:_.*]] = identity::<&str>(([[a]].0: &str)) + Call(c = identity(a.0), bb2) + } + bb2 = { + // CHECK: [[cu:_.*]] = [[c]] as u128 (Transmute); + Call(cu = transmute::<_, u128>(c), bb3) + } + bb3 = { + // This slice is different from `a.0`. Hence `bu` is not `au`. + // CHECK: [[b:_.*]] = const "a"; + // CHECK: [[bu:_.*]] = [[b]] as u128 (Transmute); + let b = "a"; + Call(bu = transmute::<_, u128>(b), bb4) + } + bb4 = { + // This returns a copy of `b`, which is not `a`. + // CHECK: [[d:_.*]] = identity::<&str>([[b]]) + Call(d = identity(b), bb5) + } + bb5 = { + // CHECK: [[du:_.*]] = [[d]] as u128 (Transmute); + Call(du = transmute::<_, u128>(d), bb6) + } + bb6 = { + // `direct` must not fold to `true`, as `indirect` will not. + // CHECK: = Eq([[au]], [[bu]]); + // CHECK: = Eq([[cu]], [[du]]); + let direct = au == bu; + let indirect = cu == du; + RET = (direct, indirect); + Return() + } + ) +} + +fn repeat() { + // CHECK-LABEL: fn repeat( + // CHECK: = [const 5_i32; 10]; + let val = 5; + let array = [val, val, val, val, val, val, val, val, val, val]; +} + +/// Verify that we do not merge fn pointers created by casts. +fn fn_pointers() { + // CHECK-LABEL: fn fn_pointers( + // CHECK: [[f:_.*]] = identity:: as fn(u8) -> u8 (PointerCoercion(ReifyFnPointer + // CHECK: opaque:: u8>([[f]]) + let f = identity as fn(u8) -> u8; + opaque(f); + // CHECK: [[g:_.*]] = identity:: as fn(u8) -> u8 (PointerCoercion(ReifyFnPointer + // CHECK: opaque:: u8>([[g]]) + let g = identity as fn(u8) -> u8; + opaque(g); + + // CHECK: [[cf:_.*]] = const {{.*}} as fn() (PointerCoercion(ClosureFnPointer + // CHECK: opaque::([[cf]]) + let closure = || {}; + let cf = closure as fn(); + opaque(cf); + // CHECK: [[cg:_.*]] = const {{.*}} as fn() (PointerCoercion(ClosureFnPointer + // CHECK: opaque::([[cg]]) + let cg = closure as fn(); + opaque(cg); +} + +/// Verify that we do not create a `ConstValue::Indirect` backed by a static's AllocId. +#[custom_mir(dialect = "analysis")] +fn indirect_static() { + static A: Option = None; + + mir!({ + let ptr = Static(A); + let out = Field::(Variant(*ptr, 1), 0); + Return() + }) +} + fn main() { subexpression_elimination(2, 4, 5); wrap_unwrap(5); repeated_index::(5, 3); arithmetic(5); + comparison(5, 6); arithmetic_checked(5); arithmetic_float(5.); cast(); @@ -236,15 +622,26 @@ fn main() { references(5); dereferences(&mut 5, &6, &S(7)); slices(); + let (direct, indirect) = duplicate_slice(); + assert_eq!(direct, indirect); + repeat(); + fn_pointers(); + indirect_static(); } #[inline(never)] fn opaque(_: impl Sized) {} +#[inline(never)] +fn identity(x: T) -> T { + x +} + // 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.comparison.GVN.diff // EMIT_MIR gvn.arithmetic_checked.GVN.diff // EMIT_MIR gvn.arithmetic_float.GVN.diff // EMIT_MIR gvn.cast.GVN.diff @@ -252,3 +649,7 @@ fn opaque(_: impl Sized) {} // EMIT_MIR gvn.references.GVN.diff // EMIT_MIR gvn.dereferences.GVN.diff // EMIT_MIR gvn.slices.GVN.diff +// EMIT_MIR gvn.duplicate_slice.GVN.diff +// EMIT_MIR gvn.repeat.GVN.diff +// EMIT_MIR gvn.fn_pointers.GVN.diff +// EMIT_MIR gvn.indirect_static.GVN.diff diff --git a/tests/mir-opt/gvn.slices.GVN.panic-abort.diff b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff index de3d28d057594..ec44998031249 100644 --- a/tests/mir-opt/gvn.slices.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff @@ -85,32 +85,35 @@ 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(_9); ++ nop; StorageLive(_10); StorageLive(_11); _11 = &(*_1); @@ -120,28 +123,37 @@ bb3: { StorageDead(_11); _9 = &_10; - StorageLive(_12); +- StorageLive(_12); ++ nop; StorageLive(_13); StorageLive(_14); - _14 = &(*_4); +- _14 = &(*_4); ++ _14 = &(*_1); _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); +- _8 = (move _9, move _12); +- StorageDead(_12); +- StorageDead(_9); ++ _8 = (_9, _12); ++ nop; ++ nop; StorageLive(_15); - _15 = (_8.0: &*const u8); +- _15 = (_8.0: &*const u8); ++ _15 = _9; StorageLive(_16); - _16 = (_8.1: &*const u8); +- _16 = (_8.1: &*const u8); ++ _16 = _12; StorageLive(_17); StorageLive(_18); - _18 = (*_15); +- _18 = (*_15); ++ _18 = (*_9); StorageLive(_19); - _19 = (*_16); +- _19 = (*_16); ++ _19 = (*_12); _17 = Eq(move _18, move _19); switchInt(move _17) -> [0: bb6, otherwise: bb5]; } @@ -149,22 +161,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,30 +186,38 @@ StorageDead(_19); StorageDead(_18); - StorageLive(_21); - _21 = core::panicking::AssertKind::Eq; +- _21 = core::panicking::AssertKind::Eq; ++ nop; ++ _21 = const core::panicking::AssertKind::Eq; StorageLive(_22); -- StorageLive(_23); + StorageLive(_23); - _23 = move _21; ++ _23 = const core::panicking::AssertKind::Eq; StorageLive(_24); - StorageLive(_25); - _25 = &(*_15); +- StorageLive(_25); +- _25 = &(*_15); ++ nop; ++ _25 = &(*_9); _24 = &(*_25); StorageLive(_26); - StorageLive(_27); - _27 = &(*_16); +- StorageLive(_27); +- _27 = &(*_16); ++ nop; ++ _27 = &(*_12); _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; +- _22 = assert_failed::<*const u8, *const u8>(move _23, move _24, move _26, move _28) -> unwind unreachable; ++ _22 = assert_failed::<*const u8, *const u8>(const core::panicking::AssertKind::Eq, move _24, move _26, move _28) -> unwind unreachable; } bb7: { -- StorageDead(_32); + StorageDead(_32); StorageDead(_31); -- StorageLive(_33); + StorageLive(_33); StorageLive(_34); - StorageLive(_35); +- StorageLive(_35); ++ nop; StorageLive(_36); StorageLive(_37); _37 = &(*_1); @@ -206,7 +227,8 @@ bb8: { StorageDead(_37); _35 = &_36; - StorageLive(_38); +- StorageLive(_38); ++ nop; StorageLive(_39); StorageLive(_40); _40 = &(*_29); @@ -216,18 +238,25 @@ bb9: { StorageDead(_40); _38 = &_39; - _34 = (move _35, move _38); - StorageDead(_38); - StorageDead(_35); +- _34 = (move _35, move _38); +- StorageDead(_38); +- StorageDead(_35); ++ _34 = (_35, _38); ++ nop; ++ nop; StorageLive(_41); - _41 = (_34.0: &*const u8); +- _41 = (_34.0: &*const u8); ++ _41 = _35; StorageLive(_42); - _42 = (_34.1: &*const u8); +- _42 = (_34.1: &*const u8); ++ _42 = _38; StorageLive(_43); StorageLive(_44); - _44 = (*_41); +- _44 = (*_41); ++ _44 = (*_35); StorageLive(_45); - _45 = (*_42); +- _45 = (*_42); ++ _45 = (*_38); _43 = Eq(move _44, move _45); switchInt(move _43) -> [0: bb11, otherwise: bb10]; } @@ -235,18 +264,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,22 +285,29 @@ StorageDead(_45); StorageDead(_44); - StorageLive(_47); - _47 = core::panicking::AssertKind::Eq; +- _47 = core::panicking::AssertKind::Eq; ++ nop; ++ _47 = const core::panicking::AssertKind::Eq; StorageLive(_48); -- StorageLive(_49); + StorageLive(_49); - _49 = move _47; ++ _49 = const core::panicking::AssertKind::Eq; StorageLive(_50); - StorageLive(_51); - _51 = &(*_41); +- StorageLive(_51); +- _51 = &(*_41); ++ nop; ++ _51 = &(*_35); _50 = &(*_51); StorageLive(_52); - StorageLive(_53); - _53 = &(*_42); +- StorageLive(_53); +- _53 = &(*_42); ++ nop; ++ _53 = &(*_38); _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; +- _48 = assert_failed::<*const u8, *const u8>(move _49, move _50, move _52, move _54) -> unwind unreachable; ++ _48 = 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 f22bb25436f05..56a78ca869461 100644 --- a/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff @@ -85,32 +85,35 @@ 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(_9); ++ nop; StorageLive(_10); StorageLive(_11); _11 = &(*_1); @@ -120,28 +123,37 @@ bb3: { StorageDead(_11); _9 = &_10; - StorageLive(_12); +- StorageLive(_12); ++ nop; StorageLive(_13); StorageLive(_14); - _14 = &(*_4); +- _14 = &(*_4); ++ _14 = &(*_1); _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); +- _8 = (move _9, move _12); +- StorageDead(_12); +- StorageDead(_9); ++ _8 = (_9, _12); ++ nop; ++ nop; StorageLive(_15); - _15 = (_8.0: &*const u8); +- _15 = (_8.0: &*const u8); ++ _15 = _9; StorageLive(_16); - _16 = (_8.1: &*const u8); +- _16 = (_8.1: &*const u8); ++ _16 = _12; StorageLive(_17); StorageLive(_18); - _18 = (*_15); +- _18 = (*_15); ++ _18 = (*_9); StorageLive(_19); - _19 = (*_16); +- _19 = (*_16); ++ _19 = (*_12); _17 = Eq(move _18, move _19); switchInt(move _17) -> [0: bb6, otherwise: bb5]; } @@ -149,22 +161,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,30 +186,38 @@ StorageDead(_19); StorageDead(_18); - StorageLive(_21); - _21 = core::panicking::AssertKind::Eq; +- _21 = core::panicking::AssertKind::Eq; ++ nop; ++ _21 = const core::panicking::AssertKind::Eq; StorageLive(_22); -- StorageLive(_23); + StorageLive(_23); - _23 = move _21; ++ _23 = const core::panicking::AssertKind::Eq; StorageLive(_24); - StorageLive(_25); - _25 = &(*_15); +- StorageLive(_25); +- _25 = &(*_15); ++ nop; ++ _25 = &(*_9); _24 = &(*_25); StorageLive(_26); - StorageLive(_27); - _27 = &(*_16); +- StorageLive(_27); +- _27 = &(*_16); ++ nop; ++ _27 = &(*_12); _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; +- _22 = assert_failed::<*const u8, *const u8>(move _23, move _24, move _26, move _28) -> unwind continue; ++ _22 = assert_failed::<*const u8, *const u8>(const core::panicking::AssertKind::Eq, move _24, move _26, move _28) -> unwind continue; } bb7: { -- StorageDead(_32); + StorageDead(_32); StorageDead(_31); -- StorageLive(_33); + StorageLive(_33); StorageLive(_34); - StorageLive(_35); +- StorageLive(_35); ++ nop; StorageLive(_36); StorageLive(_37); _37 = &(*_1); @@ -206,7 +227,8 @@ bb8: { StorageDead(_37); _35 = &_36; - StorageLive(_38); +- StorageLive(_38); ++ nop; StorageLive(_39); StorageLive(_40); _40 = &(*_29); @@ -216,18 +238,25 @@ bb9: { StorageDead(_40); _38 = &_39; - _34 = (move _35, move _38); - StorageDead(_38); - StorageDead(_35); +- _34 = (move _35, move _38); +- StorageDead(_38); +- StorageDead(_35); ++ _34 = (_35, _38); ++ nop; ++ nop; StorageLive(_41); - _41 = (_34.0: &*const u8); +- _41 = (_34.0: &*const u8); ++ _41 = _35; StorageLive(_42); - _42 = (_34.1: &*const u8); +- _42 = (_34.1: &*const u8); ++ _42 = _38; StorageLive(_43); StorageLive(_44); - _44 = (*_41); +- _44 = (*_41); ++ _44 = (*_35); StorageLive(_45); - _45 = (*_42); +- _45 = (*_42); ++ _45 = (*_38); _43 = Eq(move _44, move _45); switchInt(move _43) -> [0: bb11, otherwise: bb10]; } @@ -235,18 +264,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,22 +285,29 @@ StorageDead(_45); StorageDead(_44); - StorageLive(_47); - _47 = core::panicking::AssertKind::Eq; +- _47 = core::panicking::AssertKind::Eq; ++ nop; ++ _47 = const core::panicking::AssertKind::Eq; StorageLive(_48); -- StorageLive(_49); + StorageLive(_49); - _49 = move _47; ++ _49 = const core::panicking::AssertKind::Eq; StorageLive(_50); - StorageLive(_51); - _51 = &(*_41); +- StorageLive(_51); +- _51 = &(*_41); ++ nop; ++ _51 = &(*_35); _50 = &(*_51); StorageLive(_52); - StorageLive(_53); - _53 = &(*_42); +- StorageLive(_53); +- _53 = &(*_42); ++ nop; ++ _53 = &(*_38); _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; +- _48 = assert_failed::<*const u8, *const u8>(move _49, move _50, move _52, move _54) -> unwind continue; ++ _48 = assert_failed::<*const u8, *const u8>(const core::panicking::AssertKind::Eq, move _50, move _52, move _54) -> unwind continue; } } diff --git a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff index bf866e2f4d22f..0a747d3aef0f5 100644 --- a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff @@ -65,11 +65,11 @@ let mut _60: u64; let mut _61: u64; let mut _62: u64; - let mut _63: u64; + let _63: (); let mut _64: u64; - let _65: (); + let mut _65: u64; let mut _66: u64; - let mut _67: u64; + let _67: (); let mut _68: u64; let mut _69: u64; let mut _70: u64; @@ -77,25 +77,25 @@ let mut _72: u64; let mut _73: u64; let mut _74: u64; - let mut _75: u64; - let mut _76: u64; - let _77: (); + let mut _75: bool; + let _76: (); + let mut _77: u64; let mut _78: u64; let mut _79: u64; - let mut _80: u64; - let mut _81: u64; - let mut _82: bool; + let mut _80: bool; + let _81: (); + let mut _82: u64; let mut _83: u64; - let _84: (); - let mut _85: u64; + let mut _84: u64; + let _85: (); let mut _86: u64; let mut _87: u64; let mut _88: u64; - let mut _89: bool; + let _89: (); let mut _90: u64; - let _91: (); + let mut _91: u64; let mut _92: u64; - let mut _93: u64; + let _93: (); let mut _94: u64; let mut _95: u64; let mut _96: u64; @@ -103,93 +103,91 @@ 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 _101: (); + let mut _102: u32; + let mut _103: u64; + let _104: (); + let mut _105: f32; let mut _106: u64; - let mut _107: u64; - let mut _108: u64; - let _109: (); - let mut _110: u64; + let _107: (); + let mut _108: S; + let mut _109: u64; + let _110: (); let mut _111: u64; - let mut _112: u64; + let mut _112: S; let mut _113: u64; - let mut _114: u64; - let _115: (); + let _114: (); + let mut _115: u64; 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 _120: (); + let mut _121: u64; + let mut _122: u64; let mut _123: u64; - let _124: (); + let mut _124: u64; let mut _125: u64; - let mut _126: S; - let mut _127: u64; - let _128: &u64; - let _129: (); + let _126: &u64; + let _127: (); + let mut _128: u64; + let mut _129: u64; let mut _130: u64; - let mut _131: u64; + let _131: (); let mut _132: u64; - let _133: (); + let mut _133: u64; let mut _134: u64; - let mut _135: u64; - let mut _136: u64; - let _138: (); + let _136: (); + let mut _137: u64; + let mut _138: u64; let mut _139: u64; - let mut _140: u64; + let _140: (); let mut _141: u64; - let _142: (); + let mut _142: u64; let mut _143: u64; - let mut _144: u64; - let mut _145: u64; + let _144: (); let _146: (); - let _148: (); + let mut _147: u64; + let mut _148: u64; let mut _149: u64; - let mut _150: u64; + let _150: (); let mut _151: u64; - let _152: (); + let mut _152: u64; let mut _153: u64; - let mut _154: u64; - let mut _155: u64; - let _157: (); + let _155: (); + let mut _156: u64; + let mut _157: u64; let mut _158: u64; - let mut _159: u64; + let _159: (); let mut _160: u64; - let _161: (); + let mut _161: u64; let mut _162: u64; - let mut _163: u64; - let mut _164: u64; - let _166: (); + let _164: (); + let mut _165: u64; + let mut _166: u64; let mut _167: u64; - let mut _168: u64; + let _168: (); let mut _169: u64; - let _170: (); + let mut _170: u64; let mut _171: u64; - let mut _172: u64; - let mut _173: u64; scope 1 { - debug a => _128; - let _137: &mut u64; + debug a => _126; + let _135: &mut u64; scope 2 { - debug b => _137; - let _165: &u64; + debug b => _135; + let _163: &u64; scope 3 { - let _147: *const u64; + let _145: *const u64; scope 4 { - debug c => _147; - let _156: *mut u64; + debug c => _145; + let _154: *mut u64; scope 5 { - debug d => _156; + debug d => _154; } } } scope 6 { - debug e => _165; + debug e => _163; } } } @@ -197,61 +195,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,623 +265,701 @@ 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(_47); ++ nop; + 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]; + StorageDead(_48); +- _46 = opaque::(move _47) -> [return: bb13, unwind unreachable]; ++ _46 = opaque::(_47) -> [return: bb13, unwind unreachable]; } bb13: { - StorageDead(_47); +- StorageDead(_47); ++ nop; StorageDead(_46); StorageLive(_49); - StorageLive(_50); -- StorageLive(_51); -- _51 = _1; +- StorageLive(_50); ++ nop; + 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]; + StorageDead(_51); +- _49 = opaque::(move _50) -> [return: bb14, unwind unreachable]; ++ _49 = opaque::(_50) -> [return: bb14, unwind unreachable]; } bb14: { - StorageDead(_50); +- StorageDead(_50); ++ nop; 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; + StorageLive(_56); + 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); -+ _55 = opaque::(_56) -> [return: bb16, unwind unreachable]; ++ _56 = _1; ++ _55 = opaque::(_1) -> [return: bb16, unwind unreachable]; } bb16: { -- StorageDead(_56); -- StorageDead(_57); + 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]; + StorageLive(_61); + _61 = _1; + StorageLive(_62); + _62 = _2; +- _60 = Add(move _61, move _62); ++ _60 = _5; + StorageDead(_62); + StorageDead(_61); +- _59 = opaque::(move _60) -> [return: bb17, unwind unreachable]; ++ _59 = opaque::(_5) -> [return: bb17, unwind unreachable]; } bb17: { StorageDead(_60); StorageDead(_59); + StorageLive(_63); + StorageLive(_64); StorageLive(_65); + _65 = _1; StorageLive(_66); -- StorageLive(_67); -- StorageLive(_68); -- _68 = _1; -- StorageLive(_69); -- _69 = _2; -- _67 = Mul(move _68, move _69); -- StorageDead(_69); -- StorageDead(_68); + _66 = _2; +- _64 = Mul(move _65, move _66); ++ _64 = _9; + StorageDead(_66); + StorageDead(_65); +- _63 = opaque::(move _64) -> [return: bb18, unwind unreachable]; ++ _63 = opaque::(_9) -> [return: bb18, unwind unreachable]; + } + + bb18: { + StorageDead(_64); + StorageDead(_63); + StorageLive(_67); + StorageLive(_68); + StorageLive(_69); + _69 = _1; StorageLive(_70); - _70 = _3; -- _66 = Add(move _67, move _70); -+ _66 = Add(_9, move _70); + _70 = _2; +- _68 = Sub(move _69, move _70); ++ _68 = _13; StorageDead(_70); -- StorageDead(_67); - _65 = opaque::(move _66) -> [return: bb18, unwind unreachable]; + StorageDead(_69); +- _67 = opaque::(move _68) -> [return: bb19, unwind unreachable]; ++ _67 = opaque::(_13) -> [return: bb19, unwind unreachable]; } - bb18: { - StorageDead(_66); - StorageDead(_65); + bb19: { + StorageDead(_68); + StorageDead(_67); 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]; + StorageLive(_73); + _73 = _1; + StorageLive(_74); + _74 = _2; +- _75 = Eq(_74, const 0_u64); +- assert(!move _75, "attempt to divide `{}` by zero", _73) -> [success: bb20, unwind unreachable]; ++ _75 = _20; ++ assert(!_20, "attempt to divide `{}` by zero", _1) -> [success: bb20, unwind unreachable]; } - bb19: { + bb20: { +- _72 = Div(move _73, move _74); ++ _72 = _17; + StorageDead(_74); + StorageDead(_73); +- _71 = opaque::(move _72) -> [return: bb21, unwind unreachable]; ++ _71 = opaque::(_17) -> [return: bb21, unwind unreachable]; + } + + bb21: { StorageDead(_72); StorageDead(_71); + StorageLive(_76); 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]; + _78 = _1; + StorageLive(_79); + _79 = _2; +- _80 = Eq(_79, const 0_u64); +- assert(!move _80, "attempt to calculate the remainder of `{}` with a divisor of zero", _78) -> [success: bb22, unwind unreachable]; ++ _80 = _20; ++ assert(!_20, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb22, 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]; + bb22: { +- _77 = Rem(move _78, move _79); ++ _77 = _22; + StorageDead(_79); + StorageDead(_78); +- _76 = opaque::(move _77) -> [return: bb23, unwind unreachable]; ++ _76 = opaque::(_22) -> [return: bb23, unwind unreachable]; } - bb21: { - StorageDead(_78); + bb23: { StorageDead(_77); + StorageDead(_76); + StorageLive(_81); + StorageLive(_82); + StorageLive(_83); + _83 = _1; 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]; + _84 = _2; +- _82 = BitAnd(move _83, move _84); ++ _82 = _27; + StorageDead(_84); + StorageDead(_83); +- _81 = opaque::(move _82) -> [return: bb24, unwind unreachable]; ++ _81 = opaque::(_27) -> [return: bb24, 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]; + bb24: { + StorageDead(_82); + StorageDead(_81); + StorageLive(_85); + StorageLive(_86); + StorageLive(_87); + _87 = _1; + StorageLive(_88); + _88 = _2; +- _86 = BitOr(move _87, move _88); ++ _86 = _31; + StorageDead(_88); + StorageDead(_87); +- _85 = opaque::(move _86) -> [return: bb25, unwind unreachable]; ++ _85 = opaque::(_31) -> [return: bb25, unwind unreachable]; } - bb23: { + bb25: { + StorageDead(_86); StorageDead(_85); - StorageDead(_84); + StorageLive(_89); + StorageLive(_90); StorageLive(_91); + _91 = _1; StorageLive(_92); -- StorageLive(_93); -- StorageLive(_94); -- _94 = _1; -- StorageLive(_95); -- _95 = _2; -- _93 = BitAnd(move _94, move _95); -- StorageDead(_95); -- StorageDead(_94); + _92 = _2; +- _90 = BitXor(move _91, move _92); ++ _90 = _35; + StorageDead(_92); + StorageDead(_91); +- _89 = opaque::(move _90) -> [return: bb26, unwind unreachable]; ++ _89 = opaque::(_35) -> [return: bb26, unwind unreachable]; + } + + bb26: { + StorageDead(_90); + StorageDead(_89); + StorageLive(_93); + StorageLive(_94); + StorageLive(_95); + _95 = _1; StorageLive(_96); - _96 = _3; -- _92 = Add(move _93, move _96); -+ _92 = Add(_27, move _96); + _96 = _2; +- _94 = Shl(move _95, move _96); ++ _94 = _39; StorageDead(_96); -- StorageDead(_93); - _91 = opaque::(move _92) -> [return: bb24, unwind unreachable]; + StorageDead(_95); +- _93 = opaque::(move _94) -> [return: bb27, unwind unreachable]; ++ _93 = opaque::(_39) -> [return: bb27, unwind unreachable]; } - bb24: { - StorageDead(_92); - StorageDead(_91); + bb27: { + StorageDead(_94); + StorageDead(_93); 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]; + StorageLive(_99); + _99 = _1; + StorageLive(_100); + _100 = _2; +- _98 = Shr(move _99, move _100); ++ _98 = _43; + StorageDead(_100); + StorageDead(_99); +- _97 = opaque::(move _98) -> [return: bb28, unwind unreachable]; ++ _97 = opaque::(_43) -> [return: bb28, unwind unreachable]; } - bb25: { + bb28: { StorageDead(_98); StorageDead(_97); + StorageLive(_101); + StorageLive(_102); StorageLive(_103); + _103 = _1; +- _102 = move _103 as u32 (IntToInt); ++ _102 = _47; + StorageDead(_103); +- _101 = opaque::(move _102) -> [return: bb29, unwind unreachable]; ++ _101 = opaque::(_47) -> [return: bb29, unwind unreachable]; + } + + bb29: { + StorageDead(_102); + StorageDead(_101); 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]; + StorageLive(_105); + StorageLive(_106); + _106 = _1; +- _105 = move _106 as f32 (IntToFloat); ++ _105 = _50; + StorageDead(_106); +- _104 = opaque::(move _105) -> [return: bb30, unwind unreachable]; ++ _104 = opaque::(_50) -> [return: bb30, unwind unreachable]; } - bb26: { + bb30: { + StorageDead(_105); StorageDead(_104); - StorageDead(_103); + StorageLive(_107); + StorageLive(_108); StorageLive(_109); + _109 = _1; +- _108 = S::(move _109); ++ _108 = _53; + StorageDead(_109); +- _107 = opaque::>(move _108) -> [return: bb31, unwind unreachable]; ++ _107 = opaque::>(_53) -> [return: bb31, unwind unreachable]; + } + + bb31: { + StorageDead(_108); + StorageDead(_107); 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]; + StorageLive(_111); + StorageLive(_112); + StorageLive(_113); + _113 = _1; +- _112 = S::(move _113); ++ _112 = _53; + StorageDead(_113); +- _111 = (_112.0: u64); +- _110 = opaque::(move _111) -> [return: bb32, unwind unreachable]; ++ _111 = _1; ++ _110 = opaque::(_1) -> [return: bb32, unwind unreachable]; } - bb27: { + bb32: { + StorageDead(_111); + StorageDead(_112); StorageDead(_110); - StorageDead(_109); - StorageLive(_115); + StorageLive(_114); +- StorageLive(_115); ++ nop; 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]; + StorageLive(_117); + _117 = _1; + StorageLive(_118); + _118 = _2; +- _116 = Mul(move _117, move _118); ++ _116 = _9; + StorageDead(_118); + StorageDead(_117); + StorageLive(_119); + _119 = _2; +- _115 = Sub(move _116, move _119); ++ _115 = Sub(_9, _2); + StorageDead(_119); + StorageDead(_116); +- _114 = opaque::(move _115) -> [return: bb33, unwind unreachable]; ++ _114 = opaque::(_115) -> [return: bb33, unwind unreachable]; } - bb28: { - StorageDead(_116); - StorageDead(_115); + bb33: { +- StorageDead(_115); ++ nop; + StorageDead(_114); + StorageLive(_120); StorageLive(_121); -- StorageLive(_122); -- StorageLive(_123); -- _123 = _1; -- _122 = S::(move _123); -- StorageDead(_123); -- _121 = opaque::>(move _122) -> [return: bb29, unwind unreachable]; -+ _121 = opaque::>(_53) -> [return: bb29, unwind unreachable]; + StorageLive(_122); + StorageLive(_123); + _123 = _1; + StorageLive(_124); + _124 = _2; +- _122 = Mul(move _123, move _124); ++ _122 = _9; + StorageDead(_124); + StorageDead(_123); + StorageLive(_125); + _125 = _2; +- _121 = Sub(move _122, move _125); ++ _121 = _115; + StorageDead(_125); + StorageDead(_122); +- _120 = opaque::(move _121) -> [return: bb34, unwind unreachable]; ++ _120 = opaque::(_115) -> [return: bb34, unwind unreachable]; } - bb29: { -- StorageDead(_122); + bb34: { StorageDead(_121); - StorageLive(_124); -- StorageLive(_125); + StorageDead(_120); - 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]; ++ nop; + _126 = &_3; + StorageLive(_127); +- StorageLive(_128); +- StorageLive(_129); ++ nop; ++ nop; + _129 = (*_126); + StorageLive(_130); + _130 = _1; +- _128 = Add(move _129, move _130); ++ _128 = Add(_129, _1); + StorageDead(_130); +- StorageDead(_129); +- _127 = opaque::(move _128) -> [return: bb35, unwind unreachable]; ++ nop; ++ _127 = opaque::(_128) -> [return: bb35, unwind unreachable]; } - bb31: { -- StorageDead(_130); - StorageDead(_129); + bb35: { +- StorageDead(_128); ++ nop; + StorageDead(_127); + StorageLive(_131); + StorageLive(_132); 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]; +- _133 = (*_126); ++ _133 = _129; + StorageLive(_134); + _134 = _1; +- _132 = Add(move _133, move _134); ++ _132 = _128; + StorageDead(_134); + StorageDead(_133); +- _131 = opaque::(move _132) -> [return: bb36, unwind unreachable]; ++ _131 = opaque::(_128) -> [return: bb36, unwind unreachable]; } - bb32: { -- StorageDead(_134); - StorageDead(_133); + bb36: { + StorageDead(_132); + StorageDead(_131); +- StorageLive(_135); ++ nop; + _135 = &mut _3; + StorageLive(_136); StorageLive(_137); - _137 = &mut _3; StorageLive(_138); + _138 = (*_135); 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: { + _139 = _1; +- _137 = Add(move _138, move _139); ++ _137 = Add(move _138, _1); 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]; + _136 = opaque::(move _137) -> [return: bb37, unwind unreachable]; } - bb34: { + bb37: { + StorageDead(_137); + StorageDead(_136); + StorageLive(_140); + StorageLive(_141); + StorageLive(_142); + _142 = (*_135); + StorageLive(_143); + _143 = _1; +- _141 = Add(move _142, move _143); ++ _141 = Add(move _142, _1); StorageDead(_143); StorageDead(_142); -- StorageLive(_146); + _140 = opaque::(move _141) -> [return: bb38, unwind unreachable]; + } + + bb38: { + StorageDead(_141); + StorageDead(_140); + StorageLive(_144); +- StorageLive(_145); ++ nop; + _145 = &raw const _3; + StorageLive(_146); StorageLive(_147); - _147 = &raw const _3; StorageLive(_148); + _148 = (*_145); 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: { + _149 = _1; +- _147 = Add(move _148, move _149); ++ _147 = Add(move _148, _1); 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]; + _146 = opaque::(move _147) -> [return: bb39, unwind unreachable]; } - bb36: { + bb39: { + StorageDead(_147); + StorageDead(_146); + StorageLive(_150); + StorageLive(_151); + StorageLive(_152); + _152 = (*_145); + StorageLive(_153); + _153 = _1; +- _151 = Add(move _152, move _153); ++ _151 = Add(move _152, _1); StorageDead(_153); StorageDead(_152); + _150 = opaque::(move _151) -> [return: bb40, unwind unreachable]; + } + + bb40: { + StorageDead(_151); + StorageDead(_150); +- StorageLive(_154); ++ nop; + _154 = &raw mut _3; + StorageLive(_155); StorageLive(_156); - _156 = &raw mut _3; StorageLive(_157); + _157 = (*_154); 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: { + _158 = _1; +- _156 = Add(move _157, move _158); ++ _156 = Add(move _157, _1); 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]; + _155 = opaque::(move _156) -> [return: bb41, unwind unreachable]; } - bb38: { + bb41: { + StorageDead(_156); + StorageDead(_155); + StorageLive(_159); + StorageLive(_160); + StorageLive(_161); + _161 = (*_154); + StorageLive(_162); + _162 = _1; +- _160 = Add(move _161, move _162); ++ _160 = Add(move _161, _1); 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]; + _159 = opaque::(move _160) -> [return: bb42, unwind unreachable]; } - bb39: { -- StorageDead(_167); - StorageDead(_166); + bb42: { + StorageDead(_160); + StorageDead(_159); + _144 = const (); +- StorageDead(_154); +- StorageDead(_145); ++ nop; ++ nop; + StorageDead(_144); +- StorageLive(_163); ++ nop; + _163 = &_3; + StorageLive(_164); +- StorageLive(_165); +- StorageLive(_166); ++ nop; ++ nop; + _166 = (*_163); + StorageLive(_167); + _167 = _1; +- _165 = Add(move _166, move _167); ++ _165 = Add(_166, _1); + StorageDead(_167); +- StorageDead(_166); +- _164 = opaque::(move _165) -> [return: bb43, unwind unreachable]; ++ nop; ++ _164 = opaque::(_165) -> [return: bb43, unwind unreachable]; + } + + bb43: { +- StorageDead(_165); ++ nop; + StorageDead(_164); + StorageLive(_168); + StorageLive(_169); 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]; +- _170 = (*_163); ++ _170 = _166; + StorageLive(_171); + _171 = _1; +- _169 = Add(move _170, move _171); ++ _169 = _165; + StorageDead(_171); + StorageDead(_170); +- _168 = opaque::(move _169) -> [return: bb44, unwind unreachable]; ++ _168 = opaque::(_165) -> [return: bb44, unwind unreachable]; } - bb40: { -- StorageDead(_171); - StorageDead(_170); + bb44: { + StorageDead(_169); + StorageDead(_168); _0 = const (); - StorageDead(_165); - StorageDead(_137); - StorageDead(_128); +- StorageDead(_163); +- StorageDead(_135); +- StorageDead(_126); ++ nop; ++ nop; ++ nop; 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 index 68b052907192d..119a4d9bbe908 100644 --- a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff @@ -65,11 +65,11 @@ let mut _60: u64; let mut _61: u64; let mut _62: u64; - let mut _63: u64; + let _63: (); let mut _64: u64; - let _65: (); + let mut _65: u64; let mut _66: u64; - let mut _67: u64; + let _67: (); let mut _68: u64; let mut _69: u64; let mut _70: u64; @@ -77,25 +77,25 @@ let mut _72: u64; let mut _73: u64; let mut _74: u64; - let mut _75: u64; - let mut _76: u64; - let _77: (); + let mut _75: bool; + let _76: (); + let mut _77: u64; let mut _78: u64; let mut _79: u64; - let mut _80: u64; - let mut _81: u64; - let mut _82: bool; + let mut _80: bool; + let _81: (); + let mut _82: u64; let mut _83: u64; - let _84: (); - let mut _85: u64; + let mut _84: u64; + let _85: (); let mut _86: u64; let mut _87: u64; let mut _88: u64; - let mut _89: bool; + let _89: (); let mut _90: u64; - let _91: (); + let mut _91: u64; let mut _92: u64; - let mut _93: u64; + let _93: (); let mut _94: u64; let mut _95: u64; let mut _96: u64; @@ -103,93 +103,91 @@ 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 _101: (); + let mut _102: u32; + let mut _103: u64; + let _104: (); + let mut _105: f32; let mut _106: u64; - let mut _107: u64; - let mut _108: u64; - let _109: (); - let mut _110: u64; + let _107: (); + let mut _108: S; + let mut _109: u64; + let _110: (); let mut _111: u64; - let mut _112: u64; + let mut _112: S; let mut _113: u64; - let mut _114: u64; - let _115: (); + let _114: (); + let mut _115: u64; 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 _120: (); + let mut _121: u64; + let mut _122: u64; let mut _123: u64; - let _124: (); + let mut _124: u64; let mut _125: u64; - let mut _126: S; - let mut _127: u64; - let _128: &u64; - let _129: (); + let _126: &u64; + let _127: (); + let mut _128: u64; + let mut _129: u64; let mut _130: u64; - let mut _131: u64; + let _131: (); let mut _132: u64; - let _133: (); + let mut _133: u64; let mut _134: u64; - let mut _135: u64; - let mut _136: u64; - let _138: (); + let _136: (); + let mut _137: u64; + let mut _138: u64; let mut _139: u64; - let mut _140: u64; + let _140: (); let mut _141: u64; - let _142: (); + let mut _142: u64; let mut _143: u64; - let mut _144: u64; - let mut _145: u64; + let _144: (); let _146: (); - let _148: (); + let mut _147: u64; + let mut _148: u64; let mut _149: u64; - let mut _150: u64; + let _150: (); let mut _151: u64; - let _152: (); + let mut _152: u64; let mut _153: u64; - let mut _154: u64; - let mut _155: u64; - let _157: (); + let _155: (); + let mut _156: u64; + let mut _157: u64; let mut _158: u64; - let mut _159: u64; + let _159: (); let mut _160: u64; - let _161: (); + let mut _161: u64; let mut _162: u64; - let mut _163: u64; - let mut _164: u64; - let _166: (); + let _164: (); + let mut _165: u64; + let mut _166: u64; let mut _167: u64; - let mut _168: u64; + let _168: (); let mut _169: u64; - let _170: (); + let mut _170: u64; let mut _171: u64; - let mut _172: u64; - let mut _173: u64; scope 1 { - debug a => _128; - let _137: &mut u64; + debug a => _126; + let _135: &mut u64; scope 2 { - debug b => _137; - let _165: &u64; + debug b => _135; + let _163: &u64; scope 3 { - let _147: *const u64; + let _145: *const u64; scope 4 { - debug c => _147; - let _156: *mut u64; + debug c => _145; + let _154: *mut u64; scope 5 { - debug d => _156; + debug d => _154; } } } scope 6 { - debug e => _165; + debug e => _163; } } } @@ -197,61 +195,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,623 +265,701 @@ 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(_47); ++ nop; + 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]; + StorageDead(_48); +- _46 = opaque::(move _47) -> [return: bb13, unwind continue]; ++ _46 = opaque::(_47) -> [return: bb13, unwind continue]; } bb13: { - StorageDead(_47); +- StorageDead(_47); ++ nop; StorageDead(_46); StorageLive(_49); - StorageLive(_50); -- StorageLive(_51); -- _51 = _1; +- StorageLive(_50); ++ nop; + 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]; + StorageDead(_51); +- _49 = opaque::(move _50) -> [return: bb14, unwind continue]; ++ _49 = opaque::(_50) -> [return: bb14, unwind continue]; } bb14: { - StorageDead(_50); +- StorageDead(_50); ++ nop; 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; + StorageLive(_56); + 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); -+ _55 = opaque::(_56) -> [return: bb16, unwind continue]; ++ _56 = _1; ++ _55 = opaque::(_1) -> [return: bb16, unwind continue]; } bb16: { -- StorageDead(_56); -- StorageDead(_57); + 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]; + StorageLive(_61); + _61 = _1; + StorageLive(_62); + _62 = _2; +- _60 = Add(move _61, move _62); ++ _60 = _5; + StorageDead(_62); + StorageDead(_61); +- _59 = opaque::(move _60) -> [return: bb17, unwind continue]; ++ _59 = opaque::(_5) -> [return: bb17, unwind continue]; } bb17: { StorageDead(_60); StorageDead(_59); + StorageLive(_63); + StorageLive(_64); StorageLive(_65); + _65 = _1; StorageLive(_66); -- StorageLive(_67); -- StorageLive(_68); -- _68 = _1; -- StorageLive(_69); -- _69 = _2; -- _67 = Mul(move _68, move _69); -- StorageDead(_69); -- StorageDead(_68); + _66 = _2; +- _64 = Mul(move _65, move _66); ++ _64 = _9; + StorageDead(_66); + StorageDead(_65); +- _63 = opaque::(move _64) -> [return: bb18, unwind continue]; ++ _63 = opaque::(_9) -> [return: bb18, unwind continue]; + } + + bb18: { + StorageDead(_64); + StorageDead(_63); + StorageLive(_67); + StorageLive(_68); + StorageLive(_69); + _69 = _1; StorageLive(_70); - _70 = _3; -- _66 = Add(move _67, move _70); -+ _66 = Add(_9, move _70); + _70 = _2; +- _68 = Sub(move _69, move _70); ++ _68 = _13; StorageDead(_70); -- StorageDead(_67); - _65 = opaque::(move _66) -> [return: bb18, unwind continue]; + StorageDead(_69); +- _67 = opaque::(move _68) -> [return: bb19, unwind continue]; ++ _67 = opaque::(_13) -> [return: bb19, unwind continue]; } - bb18: { - StorageDead(_66); - StorageDead(_65); + bb19: { + StorageDead(_68); + StorageDead(_67); 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]; + StorageLive(_73); + _73 = _1; + StorageLive(_74); + _74 = _2; +- _75 = Eq(_74, const 0_u64); +- assert(!move _75, "attempt to divide `{}` by zero", _73) -> [success: bb20, unwind continue]; ++ _75 = _20; ++ assert(!_20, "attempt to divide `{}` by zero", _1) -> [success: bb20, unwind continue]; } - bb19: { + bb20: { +- _72 = Div(move _73, move _74); ++ _72 = _17; + StorageDead(_74); + StorageDead(_73); +- _71 = opaque::(move _72) -> [return: bb21, unwind continue]; ++ _71 = opaque::(_17) -> [return: bb21, unwind continue]; + } + + bb21: { StorageDead(_72); StorageDead(_71); + StorageLive(_76); 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]; + _78 = _1; + StorageLive(_79); + _79 = _2; +- _80 = Eq(_79, const 0_u64); +- assert(!move _80, "attempt to calculate the remainder of `{}` with a divisor of zero", _78) -> [success: bb22, unwind continue]; ++ _80 = _20; ++ assert(!_20, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb22, 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]; + bb22: { +- _77 = Rem(move _78, move _79); ++ _77 = _22; + StorageDead(_79); + StorageDead(_78); +- _76 = opaque::(move _77) -> [return: bb23, unwind continue]; ++ _76 = opaque::(_22) -> [return: bb23, unwind continue]; } - bb21: { - StorageDead(_78); + bb23: { StorageDead(_77); + StorageDead(_76); + StorageLive(_81); + StorageLive(_82); + StorageLive(_83); + _83 = _1; 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]; + _84 = _2; +- _82 = BitAnd(move _83, move _84); ++ _82 = _27; + StorageDead(_84); + StorageDead(_83); +- _81 = opaque::(move _82) -> [return: bb24, unwind continue]; ++ _81 = opaque::(_27) -> [return: bb24, 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]; + bb24: { + StorageDead(_82); + StorageDead(_81); + StorageLive(_85); + StorageLive(_86); + StorageLive(_87); + _87 = _1; + StorageLive(_88); + _88 = _2; +- _86 = BitOr(move _87, move _88); ++ _86 = _31; + StorageDead(_88); + StorageDead(_87); +- _85 = opaque::(move _86) -> [return: bb25, unwind continue]; ++ _85 = opaque::(_31) -> [return: bb25, unwind continue]; } - bb23: { + bb25: { + StorageDead(_86); StorageDead(_85); - StorageDead(_84); + StorageLive(_89); + StorageLive(_90); StorageLive(_91); + _91 = _1; StorageLive(_92); -- StorageLive(_93); -- StorageLive(_94); -- _94 = _1; -- StorageLive(_95); -- _95 = _2; -- _93 = BitAnd(move _94, move _95); -- StorageDead(_95); -- StorageDead(_94); + _92 = _2; +- _90 = BitXor(move _91, move _92); ++ _90 = _35; + StorageDead(_92); + StorageDead(_91); +- _89 = opaque::(move _90) -> [return: bb26, unwind continue]; ++ _89 = opaque::(_35) -> [return: bb26, unwind continue]; + } + + bb26: { + StorageDead(_90); + StorageDead(_89); + StorageLive(_93); + StorageLive(_94); + StorageLive(_95); + _95 = _1; StorageLive(_96); - _96 = _3; -- _92 = Add(move _93, move _96); -+ _92 = Add(_27, move _96); + _96 = _2; +- _94 = Shl(move _95, move _96); ++ _94 = _39; StorageDead(_96); -- StorageDead(_93); - _91 = opaque::(move _92) -> [return: bb24, unwind continue]; + StorageDead(_95); +- _93 = opaque::(move _94) -> [return: bb27, unwind continue]; ++ _93 = opaque::(_39) -> [return: bb27, unwind continue]; } - bb24: { - StorageDead(_92); - StorageDead(_91); + bb27: { + StorageDead(_94); + StorageDead(_93); 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]; + StorageLive(_99); + _99 = _1; + StorageLive(_100); + _100 = _2; +- _98 = Shr(move _99, move _100); ++ _98 = _43; + StorageDead(_100); + StorageDead(_99); +- _97 = opaque::(move _98) -> [return: bb28, unwind continue]; ++ _97 = opaque::(_43) -> [return: bb28, unwind continue]; } - bb25: { + bb28: { StorageDead(_98); StorageDead(_97); + StorageLive(_101); + StorageLive(_102); StorageLive(_103); + _103 = _1; +- _102 = move _103 as u32 (IntToInt); ++ _102 = _47; + StorageDead(_103); +- _101 = opaque::(move _102) -> [return: bb29, unwind continue]; ++ _101 = opaque::(_47) -> [return: bb29, unwind continue]; + } + + bb29: { + StorageDead(_102); + StorageDead(_101); 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]; + StorageLive(_105); + StorageLive(_106); + _106 = _1; +- _105 = move _106 as f32 (IntToFloat); ++ _105 = _50; + StorageDead(_106); +- _104 = opaque::(move _105) -> [return: bb30, unwind continue]; ++ _104 = opaque::(_50) -> [return: bb30, unwind continue]; } - bb26: { + bb30: { + StorageDead(_105); StorageDead(_104); - StorageDead(_103); + StorageLive(_107); + StorageLive(_108); StorageLive(_109); + _109 = _1; +- _108 = S::(move _109); ++ _108 = _53; + StorageDead(_109); +- _107 = opaque::>(move _108) -> [return: bb31, unwind continue]; ++ _107 = opaque::>(_53) -> [return: bb31, unwind continue]; + } + + bb31: { + StorageDead(_108); + StorageDead(_107); 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]; + StorageLive(_111); + StorageLive(_112); + StorageLive(_113); + _113 = _1; +- _112 = S::(move _113); ++ _112 = _53; + StorageDead(_113); +- _111 = (_112.0: u64); +- _110 = opaque::(move _111) -> [return: bb32, unwind continue]; ++ _111 = _1; ++ _110 = opaque::(_1) -> [return: bb32, unwind continue]; } - bb27: { + bb32: { + StorageDead(_111); + StorageDead(_112); StorageDead(_110); - StorageDead(_109); - StorageLive(_115); + StorageLive(_114); +- StorageLive(_115); ++ nop; 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]; + StorageLive(_117); + _117 = _1; + StorageLive(_118); + _118 = _2; +- _116 = Mul(move _117, move _118); ++ _116 = _9; + StorageDead(_118); + StorageDead(_117); + StorageLive(_119); + _119 = _2; +- _115 = Sub(move _116, move _119); ++ _115 = Sub(_9, _2); + StorageDead(_119); + StorageDead(_116); +- _114 = opaque::(move _115) -> [return: bb33, unwind continue]; ++ _114 = opaque::(_115) -> [return: bb33, unwind continue]; } - bb28: { - StorageDead(_116); - StorageDead(_115); + bb33: { +- StorageDead(_115); ++ nop; + StorageDead(_114); + StorageLive(_120); StorageLive(_121); -- StorageLive(_122); -- StorageLive(_123); -- _123 = _1; -- _122 = S::(move _123); -- StorageDead(_123); -- _121 = opaque::>(move _122) -> [return: bb29, unwind continue]; -+ _121 = opaque::>(_53) -> [return: bb29, unwind continue]; + StorageLive(_122); + StorageLive(_123); + _123 = _1; + StorageLive(_124); + _124 = _2; +- _122 = Mul(move _123, move _124); ++ _122 = _9; + StorageDead(_124); + StorageDead(_123); + StorageLive(_125); + _125 = _2; +- _121 = Sub(move _122, move _125); ++ _121 = _115; + StorageDead(_125); + StorageDead(_122); +- _120 = opaque::(move _121) -> [return: bb34, unwind continue]; ++ _120 = opaque::(_115) -> [return: bb34, unwind continue]; } - bb29: { -- StorageDead(_122); + bb34: { StorageDead(_121); - StorageLive(_124); -- StorageLive(_125); + StorageDead(_120); - 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]; ++ nop; + _126 = &_3; + StorageLive(_127); +- StorageLive(_128); +- StorageLive(_129); ++ nop; ++ nop; + _129 = (*_126); + StorageLive(_130); + _130 = _1; +- _128 = Add(move _129, move _130); ++ _128 = Add(_129, _1); + StorageDead(_130); +- StorageDead(_129); +- _127 = opaque::(move _128) -> [return: bb35, unwind continue]; ++ nop; ++ _127 = opaque::(_128) -> [return: bb35, unwind continue]; } - bb31: { -- StorageDead(_130); - StorageDead(_129); + bb35: { +- StorageDead(_128); ++ nop; + StorageDead(_127); + StorageLive(_131); + StorageLive(_132); 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]; +- _133 = (*_126); ++ _133 = _129; + StorageLive(_134); + _134 = _1; +- _132 = Add(move _133, move _134); ++ _132 = _128; + StorageDead(_134); + StorageDead(_133); +- _131 = opaque::(move _132) -> [return: bb36, unwind continue]; ++ _131 = opaque::(_128) -> [return: bb36, unwind continue]; } - bb32: { -- StorageDead(_134); - StorageDead(_133); + bb36: { + StorageDead(_132); + StorageDead(_131); +- StorageLive(_135); ++ nop; + _135 = &mut _3; + StorageLive(_136); StorageLive(_137); - _137 = &mut _3; StorageLive(_138); + _138 = (*_135); 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: { + _139 = _1; +- _137 = Add(move _138, move _139); ++ _137 = Add(move _138, _1); 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]; + _136 = opaque::(move _137) -> [return: bb37, unwind continue]; } - bb34: { + bb37: { + StorageDead(_137); + StorageDead(_136); + StorageLive(_140); + StorageLive(_141); + StorageLive(_142); + _142 = (*_135); + StorageLive(_143); + _143 = _1; +- _141 = Add(move _142, move _143); ++ _141 = Add(move _142, _1); StorageDead(_143); StorageDead(_142); -- StorageLive(_146); + _140 = opaque::(move _141) -> [return: bb38, unwind continue]; + } + + bb38: { + StorageDead(_141); + StorageDead(_140); + StorageLive(_144); +- StorageLive(_145); ++ nop; + _145 = &raw const _3; + StorageLive(_146); StorageLive(_147); - _147 = &raw const _3; StorageLive(_148); + _148 = (*_145); 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: { + _149 = _1; +- _147 = Add(move _148, move _149); ++ _147 = Add(move _148, _1); 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]; + _146 = opaque::(move _147) -> [return: bb39, unwind continue]; } - bb36: { + bb39: { + StorageDead(_147); + StorageDead(_146); + StorageLive(_150); + StorageLive(_151); + StorageLive(_152); + _152 = (*_145); + StorageLive(_153); + _153 = _1; +- _151 = Add(move _152, move _153); ++ _151 = Add(move _152, _1); StorageDead(_153); StorageDead(_152); + _150 = opaque::(move _151) -> [return: bb40, unwind continue]; + } + + bb40: { + StorageDead(_151); + StorageDead(_150); +- StorageLive(_154); ++ nop; + _154 = &raw mut _3; + StorageLive(_155); StorageLive(_156); - _156 = &raw mut _3; StorageLive(_157); + _157 = (*_154); 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: { + _158 = _1; +- _156 = Add(move _157, move _158); ++ _156 = Add(move _157, _1); 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]; + _155 = opaque::(move _156) -> [return: bb41, unwind continue]; } - bb38: { + bb41: { + StorageDead(_156); + StorageDead(_155); + StorageLive(_159); + StorageLive(_160); + StorageLive(_161); + _161 = (*_154); + StorageLive(_162); + _162 = _1; +- _160 = Add(move _161, move _162); ++ _160 = Add(move _161, _1); 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]; + _159 = opaque::(move _160) -> [return: bb42, unwind continue]; } - bb39: { -- StorageDead(_167); - StorageDead(_166); + bb42: { + StorageDead(_160); + StorageDead(_159); + _144 = const (); +- StorageDead(_154); +- StorageDead(_145); ++ nop; ++ nop; + StorageDead(_144); +- StorageLive(_163); ++ nop; + _163 = &_3; + StorageLive(_164); +- StorageLive(_165); +- StorageLive(_166); ++ nop; ++ nop; + _166 = (*_163); + StorageLive(_167); + _167 = _1; +- _165 = Add(move _166, move _167); ++ _165 = Add(_166, _1); + StorageDead(_167); +- StorageDead(_166); +- _164 = opaque::(move _165) -> [return: bb43, unwind continue]; ++ nop; ++ _164 = opaque::(_165) -> [return: bb43, unwind continue]; + } + + bb43: { +- StorageDead(_165); ++ nop; + StorageDead(_164); + StorageLive(_168); + StorageLive(_169); 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]; +- _170 = (*_163); ++ _170 = _166; + StorageLive(_171); + _171 = _1; +- _169 = Add(move _170, move _171); ++ _169 = _165; + StorageDead(_171); + StorageDead(_170); +- _168 = opaque::(move _169) -> [return: bb44, unwind continue]; ++ _168 = opaque::(_165) -> [return: bb44, unwind continue]; } - bb40: { -- StorageDead(_171); - StorageDead(_170); + bb44: { + StorageDead(_169); + StorageDead(_168); _0 = const (); - StorageDead(_165); - StorageDead(_137); - StorageDead(_128); +- StorageDead(_163); +- StorageDead(_135); +- StorageDead(_126); ++ nop; ++ nop; ++ nop; 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 index f33845502ad94..62710ba8fbf5f 100644 --- a/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-abort.diff @@ -15,13 +15,15 @@ bb0: { StorageLive(_2); -- StorageLive(_3); -- _3 = _1; + 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]; + StorageDead(_3); +- _4 = discriminant(_2); +- switchInt(move _4) -> [0: bb1, 1: bb3, otherwise: bb2]; ++ _4 = const 1_isize; ++ switchInt(const 1_isize) -> [0: bb1, 1: bb3, otherwise: bb2]; } bb1: { @@ -34,10 +36,12 @@ } bb3: { -- StorageLive(_5); - _5 = ((_2 as Some).0: T); - _0 = _5; -- StorageDead(_5); + StorageLive(_5); +- _5 = ((_2 as Some).0: T); +- _0 = _5; ++ _5 = _1; ++ _0 = _1; + 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 index edc05f99fe2f7..ad46a065b1e3d 100644 --- a/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-unwind.diff @@ -15,13 +15,15 @@ bb0: { StorageLive(_2); -- StorageLive(_3); -- _3 = _1; + 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]; + StorageDead(_3); +- _4 = discriminant(_2); +- switchInt(move _4) -> [0: bb1, 1: bb3, otherwise: bb2]; ++ _4 = const 1_isize; ++ switchInt(const 1_isize) -> [0: bb1, 1: bb3, otherwise: bb2]; } bb1: { @@ -34,10 +36,12 @@ } bb3: { -- StorageLive(_5); - _5 = ((_2 as Some).0: T); - _0 = _5; -- StorageDead(_5); + StorageLive(_5); +- _5 = ((_2 as Some).0: T); +- _0 = _5; ++ _5 = _1; ++ _0 = _1; + StorageDead(_5); 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; } }