diff --git a/compiler/rustc_mir_dataflow/src/value_analysis.rs b/compiler/rustc_mir_dataflow/src/value_analysis.rs index 299bf692307ab..018605469c5c6 100644 --- a/compiler/rustc_mir_dataflow/src/value_analysis.rs +++ b/compiler/rustc_mir_dataflow/src/value_analysis.rs @@ -638,8 +638,13 @@ impl Map { /// /// This is currently the only way to create a [`Map`]. The way in which the tracked places are /// chosen is an implementation detail and may not be relied upon (other than that their type - /// are scalars). - pub fn new<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, value_limit: Option) -> Self { + /// are scalars and pass the filter). + pub fn from_filter<'tcx>( + tcx: TyCtxt<'tcx>, + body: &Body<'tcx>, + filter: impl Fn(Local) -> bool, + value_limit: Option, + ) -> Self { let mut map = Self { locals: IndexVec::new(), projections: FxHashMap::default(), @@ -648,8 +653,7 @@ impl Map { inner_values: IndexVec::new(), inner_values_buffer: Vec::new(), }; - let exclude = excluded_locals(body); - map.register(tcx, body, exclude, value_limit); + map.register(tcx, body, filter, value_limit); debug!("registered {} places ({} nodes in total)", map.value_count, map.places.len()); map } @@ -659,7 +663,7 @@ impl Map { &mut self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>, - exclude: BitSet, + filter: impl Fn(Local) -> bool, value_limit: Option, ) { let mut worklist = VecDeque::with_capacity(value_limit.unwrap_or(body.local_decls.len())); @@ -668,7 +672,7 @@ impl Map { // Start by constructing the places for each bare local. self.locals = IndexVec::from_elem(None, &body.local_decls); for (local, decl) in body.local_decls.iter_enumerated() { - if exclude.contains(local) { + if !filter(local) { continue; } diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 5f135e96980f1..4db9f6c7e3757 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -1,29 +1,31 @@ //! Propagates constants for early reporting of statically known //! assertion failures -use either::Right; - use rustc_const_eval::const_eval::CheckAlignment; -use rustc_const_eval::ReportErrorExt; +use rustc_const_eval::interpret::{ + self, compile_time_machine, AllocId, ConstAllocation, FnArg, Frame, ImmTy, InterpCx, + InterpResult, OpTy, PlaceTy, Pointer, Scalar, +}; use rustc_data_structures::fx::FxHashSet; use rustc_hir::def::DefKind; use rustc_index::bit_set::BitSet; -use rustc_index::{IndexSlice, IndexVec}; +use rustc_index::IndexVec; use rustc_middle::mir::visit::{ MutVisitor, MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor, }; use rustc_middle::mir::*; -use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout}; -use rustc_middle::ty::{self, GenericArgs, Instance, ParamEnv, Ty, TyCtxt, TypeVisitableExt}; -use rustc_span::{def_id::DefId, Span, DUMMY_SP}; -use rustc_target::abi::{self, Align, HasDataLayout, Size, TargetDataLayout}; +use rustc_middle::ty::layout::TyAndLayout; +use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt}; +use rustc_mir_dataflow::lattice::FlatSet; +use rustc_mir_dataflow::value_analysis::{Map, ValueAnalysis, ValueOrPlace}; +use rustc_mir_dataflow::AnalysisDomain; +use rustc_span::def_id::DefId; +use rustc_target::abi::{Align, Size}; use rustc_target::spec::abi::Abi as CallAbi; +use crate::dataflow_const_prop::*; +use crate::ssa::SsaLocals; use crate::MirPass; -use rustc_const_eval::interpret::{ - self, compile_time_machine, AllocId, ConstAllocation, ConstValue, FnArg, Frame, ImmTy, - Immediate, InterpCx, InterpResult, MemoryKind, OpTy, PlaceTy, Pointer, Scalar, StackPopCleanup, -}; /// The maximum number of bytes that we'll allocate space for a local or the return value. /// Needed for #66397, because otherwise we eval into large places and that can cause OOM or just @@ -66,8 +68,10 @@ impl<'tcx> MirPass<'tcx> for ConstProp { sess.mir_opt_level() >= 2 } - #[instrument(skip(self, tcx), level = "debug")] + #[instrument(skip(self, tcx, body), level = "debug")] fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + debug!(def_id = ?body.source.def_id()); + // will be evaluated by miri and produce its errors there if body.source.promoted.is_some() { return; @@ -85,44 +89,69 @@ impl<'tcx> MirPass<'tcx> for ConstProp { return; } - let is_generator = tcx.type_of(def_id.to_def_id()).instantiate_identity().is_generator(); // FIXME(welseywiser) const prop doesn't work on generators because of query cycles // computing their layout. - if is_generator { + if def_kind == DefKind::Generator { trace!("ConstProp skipped for generator {:?}", def_id); return; } - trace!("ConstProp starting for {:?}", def_id); - - let dummy_body = &Body::new( - body.source, - (*body.basic_blocks).to_owned(), - body.source_scopes.clone(), - body.local_decls.clone(), - Default::default(), - body.arg_count, - Default::default(), - body.span, - body.generator_kind(), - body.tainted_by_errors, - ); - - // FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold - // constants, instead of just checking for const-folding succeeding. - // That would require a uniform one-def no-mutation analysis - // and RPO (or recursing when needing the value of a local). - let mut optimization_finder = ConstPropagator::new(body, dummy_body, tcx); - - // Traverse the body in reverse post-order, to ensure that `FullConstProp` locals are - // assigned before being read. - let rpo = body.basic_blocks.reverse_postorder().to_vec(); - for bb in rpo { - let data = &mut body.basic_blocks.as_mut_preserves_cfg()[bb]; - optimization_finder.visit_basic_block_data(bb, data); + // We could have deep projections when seeking scalars. To avoid runaways, we limit the + // number of places to a constant. + let place_limit = if tcx.sess.mir_opt_level() < 4 { Some(PLACE_LIMIT) } else { None }; + + // Decide which places to track during the analysis. + let ssa = SsaLocals::new(body); + let map = Map::from_filter(tcx, body, |local| ssa.is_ssa(local), place_limit); + + // Perform the actual dataflow analysis. + let analysis = ConstAnalysis::new(tcx, body, &map).wrap(); + let mut state = analysis.bottom_value(body); + analysis.initialize_start_block(body, &mut state); + + let reverse_postorder = body.basic_blocks.reverse_postorder(); + assert_eq!(reverse_postorder.first(), Some(&START_BLOCK)); + + let mut collector = CollectAndPatch::new(tcx, &body.local_decls); + for &block in reverse_postorder { + let block_data = &body.basic_blocks[block]; + for (statement_index, statement) in block_data.statements.iter().enumerate() { + let location = Location { block, statement_index }; + OperandCollector { state: &state, visitor: &mut collector, map: &map } + .visit_statement(statement, location); + + if let Some((place, rvalue)) = statement.kind.as_assign() { + let value = if !place.is_indirect_first_projection() && ssa.is_ssa(place.local) + { + // Use `handle_assign` here to handle the case where `place` is not scalar. + analysis.0.handle_assign(*place, rvalue, &mut state); + state.get(place.as_ref(), &map) + } else if place.ty(&body.local_decls, tcx).ty.is_scalar() { + let value = analysis.0.handle_rvalue(rvalue, &mut state); + match value { + ValueOrPlace::Value(value) => value, + ValueOrPlace::Place(place) => state.get_idx(place, &map), + } + } else { + FlatSet::Top + }; + + if let FlatSet::Elem(value) = value { + collector.assignments.insert(location, value); + } + } + } + + let terminator = block_data.terminator(); + let location = Location { block, statement_index: block_data.statements.len() }; + OperandCollector { state: &state, visitor: &mut collector, map: &map } + .visit_terminator(terminator, location); } - trace!("ConstProp done for {:?}", def_id); + // Patch the body afterwards. + for (block, bbdata) in body.basic_blocks.as_mut_preserves_cfg().iter_enumerated_mut() { + collector.visit_basic_block_data(block, bbdata); + } } } @@ -295,318 +324,6 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx> } } -/// Finds optimization opportunities on the MIR. -struct ConstPropagator<'mir, 'tcx> { - ecx: InterpCx<'mir, 'tcx, ConstPropMachine<'mir, 'tcx>>, - tcx: TyCtxt<'tcx>, - param_env: ParamEnv<'tcx>, - local_decls: &'mir IndexSlice>, -} - -impl<'tcx> LayoutOfHelpers<'tcx> for ConstPropagator<'_, 'tcx> { - type LayoutOfResult = Result, LayoutError<'tcx>>; - - #[inline] - fn handle_layout_err(&self, err: LayoutError<'tcx>, _: Span, _: Ty<'tcx>) -> LayoutError<'tcx> { - err - } -} - -impl HasDataLayout for ConstPropagator<'_, '_> { - #[inline] - fn data_layout(&self) -> &TargetDataLayout { - &self.tcx.data_layout - } -} - -impl<'tcx> ty::layout::HasTyCtxt<'tcx> for ConstPropagator<'_, 'tcx> { - #[inline] - fn tcx(&self) -> TyCtxt<'tcx> { - self.tcx - } -} - -impl<'tcx> ty::layout::HasParamEnv<'tcx> for ConstPropagator<'_, 'tcx> { - #[inline] - fn param_env(&self) -> ty::ParamEnv<'tcx> { - self.param_env - } -} - -impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { - fn new( - body: &Body<'tcx>, - dummy_body: &'mir Body<'tcx>, - tcx: TyCtxt<'tcx>, - ) -> ConstPropagator<'mir, 'tcx> { - let def_id = body.source.def_id(); - let args = &GenericArgs::identity_for_item(tcx, def_id); - let param_env = tcx.param_env_reveal_all_normalized(def_id); - - let can_const_prop = CanConstProp::check(tcx, param_env, body); - let mut ecx = InterpCx::new( - tcx, - tcx.def_span(def_id), - param_env, - ConstPropMachine::new(can_const_prop), - ); - - let ret_layout = ecx - .layout_of(body.bound_return_ty().instantiate(tcx, args)) - .ok() - // Don't bother allocating memory for large values. - // I don't know how return types can seem to be unsized but this happens in the - // `type/type-unsatisfiable.rs` test. - .filter(|ret_layout| { - ret_layout.is_sized() && ret_layout.size < Size::from_bytes(MAX_ALLOC_LIMIT) - }) - .unwrap_or_else(|| ecx.layout_of(tcx.types.unit).unwrap()); - - let ret = ecx - .allocate(ret_layout, MemoryKind::Stack) - .expect("couldn't perform small allocation") - .into(); - - ecx.push_stack_frame( - Instance::new(def_id, args), - dummy_body, - &ret, - StackPopCleanup::Root { cleanup: false }, - ) - .expect("failed to push initial stack frame"); - - for local in body.local_decls.indices() { - // Mark everything initially live. - // This is somewhat dicey since some of them might be unsized and it is incoherent to - // mark those as live... We rely on `local_to_place`/`local_to_op` in the interpreter - // stopping us before those unsized immediates can cause issues deeper in the - // interpreter. - ecx.frame_mut().locals[local].make_live_uninit(); - } - - ConstPropagator { ecx, tcx, param_env, local_decls: &dummy_body.local_decls } - } - - fn get_const(&self, place: Place<'tcx>) -> Option> { - let op = match self.ecx.eval_place_to_op(place, None) { - Ok(op) => { - if op - .as_mplace_or_imm() - .right() - .is_some_and(|imm| matches!(*imm, Immediate::Uninit)) - { - // Make sure nobody accidentally uses this value. - return None; - } - op - } - Err(e) => { - trace!("get_const failed: {:?}", e.into_kind().debug()); - return None; - } - }; - - // Try to read the local as an immediate so that if it is representable as a scalar, we can - // handle it as such, but otherwise, just return the value as is. - Some(match self.ecx.read_immediate_raw(&op) { - Ok(Right(imm)) => imm.into(), - _ => op, - }) - } - - /// Remove `local` from the pool of `Locals`. Allows writing to them, - /// but not reading from them anymore. - fn remove_const(ecx: &mut InterpCx<'mir, 'tcx, ConstPropMachine<'mir, 'tcx>>, local: Local) { - ecx.frame_mut().locals[local].make_live_uninit(); - ecx.machine.written_only_inside_own_block_locals.remove(&local); - } - - fn propagate_operand(&mut self, operand: &mut Operand<'tcx>) { - if let Some(place) = operand.place() && let Some(op) = self.replace_with_const(place) { - *operand = op; - } - } - - fn check_rvalue(&mut self, rvalue: &Rvalue<'tcx>) -> Option<()> { - // Perform any special handling for specific Rvalue types. - // Generally, checks here fall into one of two categories: - // 1. Additional checking to provide useful lints to the user - // - In this case, we will do some validation and then fall through to the - // end of the function which evals the assignment. - // 2. Working around bugs in other parts of the compiler - // - In this case, we'll return `None` from this function to stop evaluation. - match rvalue { - // Do not try creating references (#67862) - Rvalue::AddressOf(_, place) | Rvalue::Ref(_, _, place) => { - trace!("skipping AddressOf | Ref for {:?}", place); - - // This may be creating mutable references or immutable references to cells. - // If that happens, the pointed to value could be mutated via that reference. - // Since we aren't tracking references, the const propagator loses track of what - // value the local has right now. - // Thus, all locals that have their reference taken - // must not take part in propagation. - Self::remove_const(&mut self.ecx, place.local); - - return None; - } - Rvalue::ThreadLocalRef(def_id) => { - trace!("skipping ThreadLocalRef({:?})", def_id); - - return None; - } - // There's no other checking to do at this time. - Rvalue::Aggregate(..) - | Rvalue::Use(..) - | Rvalue::CopyForDeref(..) - | Rvalue::Repeat(..) - | Rvalue::Len(..) - | Rvalue::Cast(..) - | Rvalue::ShallowInitBox(..) - | Rvalue::Discriminant(..) - | Rvalue::NullaryOp(..) - | Rvalue::UnaryOp(..) - | Rvalue::BinaryOp(..) - | Rvalue::CheckedBinaryOp(..) => {} - } - - // FIXME we need to revisit this for #67176 - if rvalue.has_param() { - return None; - } - if !rvalue - .ty(&self.ecx.frame().body.local_decls, *self.ecx.tcx) - .is_sized(*self.ecx.tcx, self.param_env) - { - // the interpreter doesn't support unsized locals (only unsized arguments), - // but rustc does (in a kinda broken way), so we have to skip them here - return None; - } - - Some(()) - } - - // Attempt to use algebraic identities to eliminate constant expressions - fn eval_rvalue_with_identities( - &mut self, - rvalue: &Rvalue<'tcx>, - place: Place<'tcx>, - ) -> Option<()> { - match rvalue { - Rvalue::BinaryOp(op, box (left, right)) - | Rvalue::CheckedBinaryOp(op, box (left, right)) => { - let l = self.ecx.eval_operand(left, None).and_then(|x| self.ecx.read_immediate(&x)); - let r = - self.ecx.eval_operand(right, None).and_then(|x| self.ecx.read_immediate(&x)); - - let const_arg = match (l, r) { - (Ok(x), Err(_)) | (Err(_), Ok(x)) => x, // exactly one side is known - (Err(_), Err(_)) => return None, // neither side is known - (Ok(_), Ok(_)) => return self.ecx.eval_rvalue_into_place(rvalue, place).ok(), // both sides are known - }; - - if !matches!(const_arg.layout.abi, abi::Abi::Scalar(..)) { - // We cannot handle Scalar Pair stuff. - // No point in calling `eval_rvalue_into_place`, since only one side is known - return None; - } - - let arg_value = const_arg.to_scalar().to_bits(const_arg.layout.size).ok()?; - let dest = self.ecx.eval_place(place).ok()?; - - match op { - BinOp::BitAnd if arg_value == 0 => { - self.ecx.write_immediate(*const_arg, &dest).ok() - } - BinOp::BitOr - if arg_value == const_arg.layout.size.truncate(u128::MAX) - || (const_arg.layout.ty.is_bool() && arg_value == 1) => - { - self.ecx.write_immediate(*const_arg, &dest).ok() - } - BinOp::Mul if const_arg.layout.ty.is_integral() && arg_value == 0 => { - if let Rvalue::CheckedBinaryOp(_, _) = rvalue { - let val = Immediate::ScalarPair( - const_arg.to_scalar(), - Scalar::from_bool(false), - ); - self.ecx.write_immediate(val, &dest).ok() - } else { - self.ecx.write_immediate(*const_arg, &dest).ok() - } - } - _ => None, - } - } - _ => self.ecx.eval_rvalue_into_place(rvalue, place).ok(), - } - } - - /// Creates a new `Operand::Constant` from a `Scalar` value - fn operand_from_scalar(&self, scalar: Scalar, ty: Ty<'tcx>) -> Operand<'tcx> { - Operand::Constant(Box::new(Constant { - span: DUMMY_SP, - user_ty: None, - literal: ConstantKind::from_scalar(self.tcx, scalar, ty), - })) - } - - fn replace_with_const(&mut self, place: Place<'tcx>) -> Option> { - // This will return None if the above `const_prop` invocation only "wrote" a - // type whose creation requires no write. E.g. a generator whose initial state - // consists solely of uninitialized memory (so it doesn't capture any locals). - let value = self.get_const(place)?; - if !self.tcx.consider_optimizing(|| format!("ConstantPropagation - {value:?}")) { - return None; - } - trace!("replacing {:?} with {:?}", place, value); - - // FIXME> figure out what to do when read_immediate_raw fails - let imm = self.ecx.read_immediate_raw(&value).ok()?; - - let Right(imm) = imm else { return None }; - match *imm { - Immediate::Scalar(scalar) if scalar.try_to_int().is_ok() => { - Some(self.operand_from_scalar(scalar, value.layout.ty)) - } - Immediate::ScalarPair(l, r) if l.try_to_int().is_ok() && r.try_to_int().is_ok() => { - let alloc = self - .ecx - .intern_with_temp_alloc(value.layout, |ecx, dest| { - ecx.write_immediate(*imm, dest) - }) - .ok()?; - - let literal = ConstantKind::Val( - ConstValue::ByRef { alloc, offset: Size::ZERO }, - value.layout.ty, - ); - Some(Operand::Constant(Box::new(Constant { - span: DUMMY_SP, - user_ty: None, - literal, - }))) - } - // Scalars or scalar pairs that contain undef values are assumed to not have - // successfully evaluated and are thus not propagated. - _ => None, - } - } - - fn ensure_not_propagated(&self, local: Local) { - if cfg!(debug_assertions) { - assert!( - self.get_const(local.into()).is_none() - || self - .layout_of(self.local_decls[local].ty) - .map_or(true, |layout| layout.is_zst()), - "failed to remove values for `{local:?}`, value={:?}", - self.get_const(local.into()), - ) - } - } -} - /// The mode that `ConstProp` is allowed to run in for a given `Local`. #[derive(Clone, Copy, Debug, PartialEq)] pub enum ConstPropMode { @@ -726,156 +443,3 @@ impl<'tcx> Visitor<'tcx> for CanConstProp { } } } - -impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> { - fn tcx(&self) -> TyCtxt<'tcx> { - self.tcx - } - - fn visit_operand(&mut self, operand: &mut Operand<'tcx>, location: Location) { - self.super_operand(operand, location); - self.propagate_operand(operand) - } - - fn process_projection_elem( - &mut self, - elem: PlaceElem<'tcx>, - _: Location, - ) -> Option> { - if let PlaceElem::Index(local) = elem - && let Some(value) = self.get_const(local.into()) - && let Some(imm) = value.as_mplace_or_imm().right() - && let Immediate::Scalar(scalar) = *imm - && let Ok(offset) = scalar.to_target_usize(&self.tcx) - && let Some(min_length) = offset.checked_add(1) - { - Some(PlaceElem::ConstantIndex { offset, min_length, from_end: false }) - } else { - None - } - } - - fn visit_assign( - &mut self, - place: &mut Place<'tcx>, - rvalue: &mut Rvalue<'tcx>, - location: Location, - ) { - self.super_assign(place, rvalue, location); - - let Some(()) = self.check_rvalue(rvalue) else { return }; - - match self.ecx.machine.can_const_prop[place.local] { - // Do nothing if the place is indirect. - _ if place.is_indirect() => {} - ConstPropMode::NoPropagation => self.ensure_not_propagated(place.local), - ConstPropMode::OnlyInsideOwnBlock | ConstPropMode::FullConstProp => { - if let Some(()) = self.eval_rvalue_with_identities(rvalue, *place) { - // If this was already an evaluated constant, keep it. - if let Rvalue::Use(Operand::Constant(c)) = rvalue - && let ConstantKind::Val(..) = c.literal - { - trace!("skipping replace of Rvalue::Use({:?} because it is already a const", c); - } else if let Some(operand) = self.replace_with_const(*place) { - *rvalue = Rvalue::Use(operand); - } - } else { - // Const prop failed, so erase the destination, ensuring that whatever happens - // from here on, does not know about the previous value. - // This is important in case we have - // ```rust - // let mut x = 42; - // x = SOME_MUTABLE_STATIC; - // // x must now be uninit - // ``` - // FIXME: we overzealously erase the entire local, because that's easier to - // implement. - trace!( - "propagation into {:?} failed. - Nuking the entire site from orbit, it's the only way to be sure", - place, - ); - Self::remove_const(&mut self.ecx, place.local); - } - } - } - } - - fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) { - trace!("visit_statement: {:?}", statement); - - // We want to evaluate operands before any change to the assigned-to value, - // so we recurse first. - self.super_statement(statement, location); - - match statement.kind { - StatementKind::SetDiscriminant { ref place, .. } => { - match self.ecx.machine.can_const_prop[place.local] { - // Do nothing if the place is indirect. - _ if place.is_indirect() => {} - ConstPropMode::NoPropagation => self.ensure_not_propagated(place.local), - ConstPropMode::FullConstProp | ConstPropMode::OnlyInsideOwnBlock => { - if self.ecx.statement(statement).is_ok() { - trace!("propped discriminant into {:?}", place); - } else { - Self::remove_const(&mut self.ecx, place.local); - } - } - } - } - StatementKind::StorageLive(local) => { - Self::remove_const(&mut self.ecx, local); - } - // We do not need to mark dead locals as such. For `FullConstProp` locals, - // this allows to propagate the single assigned value in this case: - // ``` - // let x = SOME_CONST; - // if a { - // f(copy x); - // StorageDead(x); - // } else { - // g(copy x); - // StorageDead(x); - // } - // ``` - // - // This may propagate a constant where the local would be uninit or dead. - // In both cases, this does not matter, as those reads would be UB anyway. - _ => {} - } - } - - fn visit_basic_block_data(&mut self, block: BasicBlock, data: &mut BasicBlockData<'tcx>) { - self.super_basic_block_data(block, data); - - // We remove all Locals which are restricted in propagation to their containing blocks and - // which were modified in the current block. - // Take it out of the ecx so we can get a mutable reference to the ecx for `remove_const`. - let mut written_only_inside_own_block_locals = - std::mem::take(&mut self.ecx.machine.written_only_inside_own_block_locals); - - // This loop can get very hot for some bodies: it check each local in each bb. - // To avoid this quadratic behaviour, we only clear the locals that were modified inside - // the current block. - for local in written_only_inside_own_block_locals.drain() { - debug_assert_eq!( - self.ecx.machine.can_const_prop[local], - ConstPropMode::OnlyInsideOwnBlock - ); - Self::remove_const(&mut self.ecx, local); - } - self.ecx.machine.written_only_inside_own_block_locals = - written_only_inside_own_block_locals; - - if cfg!(debug_assertions) { - for (local, &mode) in self.ecx.machine.can_const_prop.iter_enumerated() { - match mode { - ConstPropMode::FullConstProp => {} - ConstPropMode::NoPropagation | ConstPropMode::OnlyInsideOwnBlock => { - self.ensure_not_propagated(local); - } - } - } - } - } -} diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index 333a14be996b0..4e416852f2d5c 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -11,7 +11,7 @@ use rustc_middle::mir::*; use rustc_middle::ty::layout::TyAndLayout; use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt}; use rustc_mir_dataflow::value_analysis::{ - Map, State, TrackElem, ValueAnalysis, ValueAnalysisWrapper, ValueOrPlace, + excluded_locals, Map, State, TrackElem, ValueAnalysis, ValueAnalysisWrapper, ValueOrPlace, }; use rustc_mir_dataflow::{lattice::FlatSet, Analysis, Results, ResultsVisitor}; use rustc_span::DUMMY_SP; @@ -22,9 +22,9 @@ use crate::MirPass; // These constants are somewhat random guesses and have not been optimized. // If `tcx.sess.mir_opt_level() >= 4`, we ignore the limits (this can become very expensive). const BLOCK_LIMIT: usize = 100; -const PLACE_LIMIT: usize = 100; +pub(crate) const PLACE_LIMIT: usize = 100; -pub struct DataflowConstProp; +pub(crate) struct DataflowConstProp; impl<'tcx> MirPass<'tcx> for DataflowConstProp { fn is_enabled(&self, sess: &rustc_session::Session) -> bool { @@ -50,10 +50,11 @@ impl<'tcx> MirPass<'tcx> for DataflowConstProp { let place_limit = if tcx.sess.mir_opt_level() < 4 { Some(PLACE_LIMIT) } else { None }; // Decide which places to track during the analysis. - let map = Map::new(tcx, body, place_limit); + let exclude = excluded_locals(body); + let map = Map::from_filter(tcx, body, |local| !exclude.contains(local), place_limit); // Perform the actual dataflow analysis. - let analysis = ConstAnalysis::new(tcx, body, map); + let analysis = ConstAnalysis::new(tcx, body, &map); let mut results = debug_span!("analyze") .in_scope(|| analysis.wrap().into_engine(tcx, body).iterate_to_fixpoint()); @@ -68,15 +69,15 @@ impl<'tcx> MirPass<'tcx> for DataflowConstProp { } } -struct ConstAnalysis<'a, 'tcx> { - map: Map, +pub(crate) struct ConstAnalysis<'a, 'm, 'tcx> { + map: &'m Map, tcx: TyCtxt<'tcx>, local_decls: &'a LocalDecls<'tcx>, ecx: InterpCx<'tcx, 'tcx, DummyMachine>, param_env: ty::ParamEnv<'tcx>, } -impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> { +impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, '_, 'tcx> { type Value = FlatSet; const NAME: &'static str = "ConstAnalysis"; @@ -318,8 +319,8 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> { } } -impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> { - pub fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, map: Map) -> Self { +impl<'a, 'm, 'tcx> ConstAnalysis<'a, 'm, 'tcx> { + pub fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, map: &'m Map) -> Self { let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id()); Self { map, @@ -428,7 +429,7 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> { } } -struct CollectAndPatch<'tcx, 'locals> { +pub(crate) struct CollectAndPatch<'tcx, 'locals> { tcx: TyCtxt<'tcx>, local_decls: &'locals LocalDecls<'tcx>, @@ -438,11 +439,11 @@ struct CollectAndPatch<'tcx, 'locals> { before_effect: FxHashMap<(Location, Place<'tcx>), ScalarInt>, /// Stores the assigned values for assignments where the Rvalue is constant. - assignments: FxHashMap, + pub(crate) assignments: FxHashMap, } impl<'tcx, 'locals> CollectAndPatch<'tcx, 'locals> { - fn new(tcx: TyCtxt<'tcx>, local_decls: &'locals LocalDecls<'tcx>) -> Self { + pub fn new(tcx: TyCtxt<'tcx>, local_decls: &'locals LocalDecls<'tcx>) -> Self { Self { tcx, local_decls, @@ -461,14 +462,14 @@ impl<'tcx, 'locals> CollectAndPatch<'tcx, 'locals> { } impl<'mir, 'tcx> - ResultsVisitor<'mir, 'tcx, Results<'tcx, ValueAnalysisWrapper>>> + ResultsVisitor<'mir, 'tcx, Results<'tcx, ValueAnalysisWrapper>>> for CollectAndPatch<'tcx, '_> { type FlowState = State>; fn visit_statement_before_primary_effect( &mut self, - results: &mut Results<'tcx, ValueAnalysisWrapper>>, + results: &mut Results<'tcx, ValueAnalysisWrapper>>, state: &Self::FlowState, statement: &'mir Statement<'tcx>, location: Location, @@ -484,7 +485,7 @@ impl<'mir, 'tcx> fn visit_statement_after_primary_effect( &mut self, - results: &mut Results<'tcx, ValueAnalysisWrapper>>, + results: &mut Results<'tcx, ValueAnalysisWrapper>>, state: &Self::FlowState, statement: &'mir Statement<'tcx>, location: Location, @@ -510,7 +511,7 @@ impl<'mir, 'tcx> fn visit_terminator_before_primary_effect( &mut self, - results: &mut Results<'tcx, ValueAnalysisWrapper>>, + results: &mut Results<'tcx, ValueAnalysisWrapper>>, state: &Self::FlowState, terminator: &'mir Terminator<'tcx>, location: Location, @@ -529,8 +530,11 @@ impl<'tcx> MutVisitor<'tcx> for CollectAndPatch<'tcx, '_> { if let Some(value) = self.assignments.get(&location) { match &mut statement.kind { StatementKind::Assign(box (_, rvalue)) => { - let ty = rvalue.ty(self.local_decls, self.tcx); - *rvalue = Rvalue::Use(self.make_operand(*value, ty)); + if !matches!(rvalue, Rvalue::Use(Operand::Constant(_))) { + // Don't overwrite the assignment if it already uses a constant (to keep the span). + let ty = rvalue.ty(self.local_decls, self.tcx); + *rvalue = Rvalue::Use(self.make_operand(*value, ty)); + } } _ => bug!("found assignment info for non-assign statement"), } @@ -570,10 +574,10 @@ impl<'tcx> MutVisitor<'tcx> for CollectAndPatch<'tcx, '_> { } } -struct OperandCollector<'tcx, 'map, 'locals, 'a> { - state: &'a State>, - visitor: &'a mut CollectAndPatch<'tcx, 'locals>, - map: &'map Map, +pub(crate) struct OperandCollector<'tcx, 'map, 'locals, 'a> { + pub(crate) state: &'a State>, + pub(crate) visitor: &'a mut CollectAndPatch<'tcx, 'locals>, + pub(crate) map: &'map Map, } impl<'tcx> Visitor<'tcx> for OperandCollector<'tcx, '_, '_, '_> { diff --git a/tests/coverage-map/status-quo/issue-84561.cov-map b/tests/coverage-map/status-quo/issue-84561.cov-map index fe098fd396c27..d8e1cf02d6404 100644 --- a/tests/coverage-map/status-quo/issue-84561.cov-map +++ b/tests/coverage-map/status-quo/issue-84561.cov-map @@ -1,11 +1,10 @@ Function name: ::eq -Raw bytes (14): 0x[01, 01, 00, 02, 01, 04, 0a, 00, 13, 00, 00, 0a, 00, 13] +Raw bytes (9): 0x[01, 01, 00, 01, 01, 04, 0a, 00, 13] Number of files: 1 - file 0 => global file 1 Number of expressions: 0 -Number of file 0 mappings: 2 +Number of file 0 mappings: 1 - Code(Counter(0)) at (prev + 4, 10) to (start + 0, 19) -- Code(Zero) at (prev + 0, 10) to (start + 0, 19) Function name: ::fmt Raw bytes (29): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 89, 01, 09, 00, 25, 05, 00, 25, 00, 26, 02, 01, 09, 00, 0f, 07, 01, 05, 00, 06] @@ -86,75 +85,85 @@ Number of file 0 mappings: 1 - Code(Counter(0)) at (prev + 165, 9) to (start + 2, 10) Function name: issue_84561::test3 -Raw bytes (437): 0x[01, 01, 41, 05, 09, 0d, 11, 15, 19, 12, 1d, 15, 19, 21, 25, 1e, 29, 21, 25, 31, 39, 3d, 41, 2e, 45, 3d, 41, 42, 49, 45, 4d, 3f, 51, 42, 49, 45, 4d, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 59, 92, 01, 55, 51, 59, 8f, 01, 5d, 92, 01, 55, 51, 59, 87, 01, 61, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 59, 82, 01, 65, 87, 01, 61, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 59, 75, f6, 01, fb, 01, 79, 71, fe, 01, 82, 02, 71, 69, 6d, 71, fe, 01, 82, 02, 71, 69, 6d, 69, 6d, 82, 02, 71, 69, 6d, fb, 01, 79, 71, fe, 01, 82, 02, 71, 69, 6d, f3, 01, 7d, 75, f6, 01, fb, 01, 79, 71, fe, 01, 82, 02, 71, 69, 6d, ee, 01, 81, 01, f3, 01, 7d, 75, f6, 01, fb, 01, 79, 71, fe, 01, 82, 02, 71, 69, 6d, 33, 01, 06, 01, 03, 1c, 05, 04, 09, 01, 1c, 02, 02, 05, 04, 1f, 0d, 05, 05, 00, 1f, 06, 01, 05, 00, 1f, 15, 01, 09, 01, 1c, 12, 02, 05, 00, 1f, 0e, 01, 05, 00, 0f, 00, 00, 20, 00, 30, 21, 01, 05, 03, 0f, 00, 03, 20, 00, 30, 00, 00, 33, 00, 41, 00, 00, 4b, 00, 5a, 1e, 01, 05, 00, 0f, 00, 05, 09, 03, 10, 00, 05, 0d, 00, 1b, 00, 02, 0d, 00, 1c, 1a, 04, 09, 05, 06, 31, 06, 05, 03, 06, 22, 04, 05, 03, 06, 3d, 04, 09, 04, 06, 2e, 05, 08, 00, 0f, 45, 01, 09, 03, 0a, 2a, 05, 09, 03, 0a, 3f, 05, 08, 00, 0f, 51, 01, 09, 00, 13, 00, 03, 0d, 00, 1d, 3a, 03, 09, 00, 13, 00, 03, 0d, 00, 1d, 87, 01, 03, 05, 00, 0f, 8f, 01, 01, 0c, 00, 13, 5d, 01, 0d, 00, 13, 8a, 01, 02, 0d, 00, 13, 82, 01, 04, 05, 02, 13, 65, 03, 0d, 00, 13, 7e, 02, 0d, 00, 13, f3, 01, 03, 05, 00, 0f, 69, 01, 0c, 00, 13, 6d, 01, 0d, 03, 0e, 75, 04, 0d, 00, 13, fb, 01, 02, 0d, 00, 17, 82, 02, 01, 14, 00, 1b, 71, 01, 15, 00, 1b, fe, 01, 02, 15, 00, 1b, f6, 01, 04, 0d, 00, 13, 7d, 03, 09, 00, 19, ee, 01, 02, 05, 00, 0f, ea, 01, 03, 09, 00, 22, 00, 02, 05, 00, 0f, 00, 03, 09, 00, 2c, 00, 02, 01, 00, 02] +Raw bytes (463): 0x[01, 01, 4b, 05, 09, 0d, 11, 15, 19, 1e, 1d, 15, 19, 1a, 21, 1e, 1d, 15, 19, 25, 2d, 21, 25, 29, 35, 32, 29, 21, 25, 31, 39, 3d, 41, 42, 45, 3d, 41, 66, 49, 45, 4d, 63, 51, 66, 49, 45, 4d, 5e, 55, 63, 51, 66, 49, 45, 4d, 5d, ae, 01, b3, 01, 5d, b6, 01, 55, 51, 59, b6, 01, 55, 51, 59, b3, 01, 5d, b6, 01, 55, 51, 59, ab, 01, 61, 5d, ae, 01, b3, 01, 5d, b6, 01, 55, 51, 59, a6, 01, 65, ab, 01, 61, 5d, ae, 01, b3, 01, 5d, b6, 01, 55, 51, 59, 75, 9a, 02, 9f, 02, 79, 71, a2, 02, a6, 02, 71, 69, 6d, 71, a2, 02, a6, 02, 71, 69, 6d, 69, 6d, a6, 02, 71, 69, 6d, 9f, 02, 79, 71, a2, 02, a6, 02, 71, 69, 6d, 97, 02, 7d, 75, 9a, 02, 9f, 02, 79, 71, a2, 02, a6, 02, 71, 69, 6d, 92, 02, 81, 01, 97, 02, 7d, 75, 9a, 02, 9f, 02, 79, 71, a2, 02, a6, 02, 71, 69, 6d, 81, 01, 85, 01, 33, 01, 06, 01, 03, 1c, 05, 04, 09, 01, 1c, 02, 02, 05, 04, 1f, 0d, 05, 05, 00, 1f, 06, 01, 05, 00, 1f, 15, 01, 09, 01, 1c, 1e, 02, 05, 00, 1f, 1a, 01, 05, 00, 0f, 16, 00, 20, 00, 30, 21, 01, 05, 03, 0f, 25, 03, 20, 00, 30, 2d, 00, 33, 00, 41, 22, 00, 4b, 00, 5a, 32, 01, 05, 00, 0f, 29, 05, 09, 03, 10, 35, 05, 0d, 00, 1b, 2a, 02, 0d, 00, 1c, 2e, 04, 09, 05, 06, 31, 06, 05, 03, 06, 36, 04, 05, 03, 06, 3d, 04, 09, 04, 06, 42, 05, 08, 00, 0f, 45, 01, 09, 03, 0a, 3e, 05, 09, 03, 0a, 63, 05, 08, 00, 0f, 51, 01, 09, 00, 13, 59, 03, 0d, 00, 1d, 5e, 03, 09, 00, 13, 5a, 03, 0d, 00, 1d, ab, 01, 03, 05, 00, 0f, b3, 01, 01, 0c, 00, 13, 5d, 01, 0d, 00, 13, ae, 01, 02, 0d, 00, 13, a6, 01, 04, 05, 02, 13, 65, 03, 0d, 00, 13, a2, 01, 02, 0d, 00, 13, 97, 02, 03, 05, 00, 0f, 69, 01, 0c, 00, 13, 6d, 01, 0d, 03, 0e, 75, 04, 0d, 00, 13, 9f, 02, 02, 0d, 00, 17, a6, 02, 01, 14, 00, 1b, 71, 01, 15, 00, 1b, a2, 02, 02, 15, 00, 1b, 9a, 02, 04, 0d, 00, 13, 7d, 03, 09, 00, 19, 92, 02, 02, 05, 00, 0f, 8e, 02, 03, 09, 00, 22, 81, 01, 02, 05, 00, 0f, aa, 02, 03, 09, 00, 2c, 85, 01, 02, 01, 00, 02] Number of files: 1 - file 0 => global file 1 -Number of expressions: 65 +Number of expressions: 75 - expression 0 operands: lhs = Counter(1), rhs = Counter(2) - expression 1 operands: lhs = Counter(3), rhs = Counter(4) - expression 2 operands: lhs = Counter(5), rhs = Counter(6) -- expression 3 operands: lhs = Expression(4, Sub), rhs = Counter(7) +- expression 3 operands: lhs = Expression(7, Sub), rhs = Counter(7) - expression 4 operands: lhs = Counter(5), rhs = Counter(6) -- expression 5 operands: lhs = Counter(8), rhs = Counter(9) -- expression 6 operands: lhs = Expression(7, Sub), rhs = Counter(10) -- expression 7 operands: lhs = Counter(8), rhs = Counter(9) -- expression 8 operands: lhs = Counter(12), rhs = Counter(14) -- expression 9 operands: lhs = Counter(15), rhs = Counter(16) -- expression 10 operands: lhs = Expression(11, Sub), rhs = Counter(17) -- expression 11 operands: lhs = Counter(15), rhs = Counter(16) -- expression 12 operands: lhs = Expression(16, Sub), rhs = Counter(18) -- expression 13 operands: lhs = Counter(17), rhs = Counter(19) -- expression 14 operands: lhs = Expression(15, Add), rhs = Counter(20) -- expression 15 operands: lhs = Expression(16, Sub), rhs = Counter(18) -- expression 16 operands: lhs = Counter(17), rhs = Counter(19) -- expression 17 operands: lhs = Counter(23), rhs = Expression(34, Sub) -- expression 18 operands: lhs = Expression(35, Add), rhs = Counter(23) -- expression 19 operands: lhs = Expression(36, Sub), rhs = Counter(21) -- expression 20 operands: lhs = Counter(20), rhs = Counter(22) -- expression 21 operands: lhs = Expression(36, Sub), rhs = Counter(21) -- expression 22 operands: lhs = Counter(20), rhs = Counter(22) -- expression 23 operands: lhs = Expression(35, Add), rhs = Counter(23) -- expression 24 operands: lhs = Expression(36, Sub), rhs = Counter(21) -- expression 25 operands: lhs = Counter(20), rhs = Counter(22) -- expression 26 operands: lhs = Expression(33, Add), rhs = Counter(24) -- expression 27 operands: lhs = Counter(23), rhs = Expression(34, Sub) -- expression 28 operands: lhs = Expression(35, Add), rhs = Counter(23) -- expression 29 operands: lhs = Expression(36, Sub), rhs = Counter(21) -- expression 30 operands: lhs = Counter(20), rhs = Counter(22) -- expression 31 operands: lhs = Expression(32, Sub), rhs = Counter(25) -- expression 32 operands: lhs = Expression(33, Add), rhs = Counter(24) -- expression 33 operands: lhs = Counter(23), rhs = Expression(34, Sub) -- expression 34 operands: lhs = Expression(35, Add), rhs = Counter(23) -- expression 35 operands: lhs = Expression(36, Sub), rhs = Counter(21) -- expression 36 operands: lhs = Counter(20), rhs = Counter(22) -- expression 37 operands: lhs = Counter(29), rhs = Expression(61, Sub) -- expression 38 operands: lhs = Expression(62, Add), rhs = Counter(30) -- expression 39 operands: lhs = Counter(28), rhs = Expression(63, Sub) -- expression 40 operands: lhs = Expression(64, Sub), rhs = Counter(28) -- expression 41 operands: lhs = Counter(26), rhs = Counter(27) -- expression 42 operands: lhs = Counter(28), rhs = Expression(63, Sub) -- expression 43 operands: lhs = Expression(64, Sub), rhs = Counter(28) -- expression 44 operands: lhs = Counter(26), rhs = Counter(27) -- expression 45 operands: lhs = Counter(26), rhs = Counter(27) -- expression 46 operands: lhs = Expression(64, Sub), rhs = Counter(28) -- expression 47 operands: lhs = Counter(26), rhs = Counter(27) -- expression 48 operands: lhs = Expression(62, Add), rhs = Counter(30) -- expression 49 operands: lhs = Counter(28), rhs = Expression(63, Sub) -- expression 50 operands: lhs = Expression(64, Sub), rhs = Counter(28) -- expression 51 operands: lhs = Counter(26), rhs = Counter(27) -- expression 52 operands: lhs = Expression(60, Add), rhs = Counter(31) -- expression 53 operands: lhs = Counter(29), rhs = Expression(61, Sub) -- expression 54 operands: lhs = Expression(62, Add), rhs = Counter(30) -- expression 55 operands: lhs = Counter(28), rhs = Expression(63, Sub) -- expression 56 operands: lhs = Expression(64, Sub), rhs = Counter(28) -- expression 57 operands: lhs = Counter(26), rhs = Counter(27) -- expression 58 operands: lhs = Expression(59, Sub), rhs = Counter(32) -- expression 59 operands: lhs = Expression(60, Add), rhs = Counter(31) -- expression 60 operands: lhs = Counter(29), rhs = Expression(61, Sub) -- expression 61 operands: lhs = Expression(62, Add), rhs = Counter(30) -- expression 62 operands: lhs = Counter(28), rhs = Expression(63, Sub) -- expression 63 operands: lhs = Expression(64, Sub), rhs = Counter(28) -- expression 64 operands: lhs = Counter(26), rhs = Counter(27) +- expression 5 operands: lhs = Expression(6, Sub), rhs = Counter(8) +- expression 6 operands: lhs = Expression(7, Sub), rhs = Counter(7) +- expression 7 operands: lhs = Counter(5), rhs = Counter(6) +- expression 8 operands: lhs = Counter(9), rhs = Counter(11) +- expression 9 operands: lhs = Counter(8), rhs = Counter(9) +- expression 10 operands: lhs = Counter(10), rhs = Counter(13) +- expression 11 operands: lhs = Expression(12, Sub), rhs = Counter(10) +- expression 12 operands: lhs = Counter(8), rhs = Counter(9) +- expression 13 operands: lhs = Counter(12), rhs = Counter(14) +- expression 14 operands: lhs = Counter(15), rhs = Counter(16) +- expression 15 operands: lhs = Expression(16, Sub), rhs = Counter(17) +- expression 16 operands: lhs = Counter(15), rhs = Counter(16) +- expression 17 operands: lhs = Expression(25, Sub), rhs = Counter(18) +- expression 18 operands: lhs = Counter(17), rhs = Counter(19) +- expression 19 operands: lhs = Expression(24, Add), rhs = Counter(20) +- expression 20 operands: lhs = Expression(25, Sub), rhs = Counter(18) +- expression 21 operands: lhs = Counter(17), rhs = Counter(19) +- expression 22 operands: lhs = Expression(23, Sub), rhs = Counter(21) +- expression 23 operands: lhs = Expression(24, Add), rhs = Counter(20) +- expression 24 operands: lhs = Expression(25, Sub), rhs = Counter(18) +- expression 25 operands: lhs = Counter(17), rhs = Counter(19) +- expression 26 operands: lhs = Counter(23), rhs = Expression(43, Sub) +- expression 27 operands: lhs = Expression(44, Add), rhs = Counter(23) +- expression 28 operands: lhs = Expression(45, Sub), rhs = Counter(21) +- expression 29 operands: lhs = Counter(20), rhs = Counter(22) +- expression 30 operands: lhs = Expression(45, Sub), rhs = Counter(21) +- expression 31 operands: lhs = Counter(20), rhs = Counter(22) +- expression 32 operands: lhs = Expression(44, Add), rhs = Counter(23) +- expression 33 operands: lhs = Expression(45, Sub), rhs = Counter(21) +- expression 34 operands: lhs = Counter(20), rhs = Counter(22) +- expression 35 operands: lhs = Expression(42, Add), rhs = Counter(24) +- expression 36 operands: lhs = Counter(23), rhs = Expression(43, Sub) +- expression 37 operands: lhs = Expression(44, Add), rhs = Counter(23) +- expression 38 operands: lhs = Expression(45, Sub), rhs = Counter(21) +- expression 39 operands: lhs = Counter(20), rhs = Counter(22) +- expression 40 operands: lhs = Expression(41, Sub), rhs = Counter(25) +- expression 41 operands: lhs = Expression(42, Add), rhs = Counter(24) +- expression 42 operands: lhs = Counter(23), rhs = Expression(43, Sub) +- expression 43 operands: lhs = Expression(44, Add), rhs = Counter(23) +- expression 44 operands: lhs = Expression(45, Sub), rhs = Counter(21) +- expression 45 operands: lhs = Counter(20), rhs = Counter(22) +- expression 46 operands: lhs = Counter(29), rhs = Expression(70, Sub) +- expression 47 operands: lhs = Expression(71, Add), rhs = Counter(30) +- expression 48 operands: lhs = Counter(28), rhs = Expression(72, Sub) +- expression 49 operands: lhs = Expression(73, Sub), rhs = Counter(28) +- expression 50 operands: lhs = Counter(26), rhs = Counter(27) +- expression 51 operands: lhs = Counter(28), rhs = Expression(72, Sub) +- expression 52 operands: lhs = Expression(73, Sub), rhs = Counter(28) +- expression 53 operands: lhs = Counter(26), rhs = Counter(27) +- expression 54 operands: lhs = Counter(26), rhs = Counter(27) +- expression 55 operands: lhs = Expression(73, Sub), rhs = Counter(28) +- expression 56 operands: lhs = Counter(26), rhs = Counter(27) +- expression 57 operands: lhs = Expression(71, Add), rhs = Counter(30) +- expression 58 operands: lhs = Counter(28), rhs = Expression(72, Sub) +- expression 59 operands: lhs = Expression(73, Sub), rhs = Counter(28) +- expression 60 operands: lhs = Counter(26), rhs = Counter(27) +- expression 61 operands: lhs = Expression(69, Add), rhs = Counter(31) +- expression 62 operands: lhs = Counter(29), rhs = Expression(70, Sub) +- expression 63 operands: lhs = Expression(71, Add), rhs = Counter(30) +- expression 64 operands: lhs = Counter(28), rhs = Expression(72, Sub) +- expression 65 operands: lhs = Expression(73, Sub), rhs = Counter(28) +- expression 66 operands: lhs = Counter(26), rhs = Counter(27) +- expression 67 operands: lhs = Expression(68, Sub), rhs = Counter(32) +- expression 68 operands: lhs = Expression(69, Add), rhs = Counter(31) +- expression 69 operands: lhs = Counter(29), rhs = Expression(70, Sub) +- expression 70 operands: lhs = Expression(71, Add), rhs = Counter(30) +- expression 71 operands: lhs = Counter(28), rhs = Expression(72, Sub) +- expression 72 operands: lhs = Expression(73, Sub), rhs = Counter(28) +- expression 73 operands: lhs = Counter(26), rhs = Counter(27) +- expression 74 operands: lhs = Counter(32), rhs = Counter(33) Number of file 0 mappings: 51 - Code(Counter(0)) at (prev + 6, 1) to (start + 3, 28) - Code(Counter(1)) at (prev + 4, 9) to (start + 1, 28) @@ -164,70 +173,75 @@ Number of file 0 mappings: 51 - Code(Expression(1, Sub)) at (prev + 1, 5) to (start + 0, 31) = (c3 - c4) - Code(Counter(5)) at (prev + 1, 9) to (start + 1, 28) -- Code(Expression(4, Sub)) at (prev + 2, 5) to (start + 0, 31) +- Code(Expression(7, Sub)) at (prev + 2, 5) to (start + 0, 31) = (c5 - c6) -- Code(Expression(3, Sub)) at (prev + 1, 5) to (start + 0, 15) +- Code(Expression(6, Sub)) at (prev + 1, 5) to (start + 0, 15) = ((c5 - c6) - c7) -- Code(Zero) at (prev + 0, 32) to (start + 0, 48) +- Code(Expression(5, Sub)) at (prev + 0, 32) to (start + 0, 48) + = (((c5 - c6) - c7) - c8) - Code(Counter(8)) at (prev + 1, 5) to (start + 3, 15) -- Code(Zero) at (prev + 3, 32) to (start + 0, 48) -- Code(Zero) at (prev + 0, 51) to (start + 0, 65) -- Code(Zero) at (prev + 0, 75) to (start + 0, 90) -- Code(Expression(7, Sub)) at (prev + 1, 5) to (start + 0, 15) +- Code(Counter(9)) at (prev + 3, 32) to (start + 0, 48) +- Code(Counter(11)) at (prev + 0, 51) to (start + 0, 65) +- Code(Expression(8, Sub)) at (prev + 0, 75) to (start + 0, 90) + = (c9 - c11) +- Code(Expression(12, Sub)) at (prev + 1, 5) to (start + 0, 15) = (c8 - c9) -- Code(Zero) at (prev + 5, 9) to (start + 3, 16) -- Code(Zero) at (prev + 5, 13) to (start + 0, 27) -- Code(Zero) at (prev + 2, 13) to (start + 0, 28) -- Code(Expression(6, Sub)) at (prev + 4, 9) to (start + 5, 6) +- Code(Counter(10)) at (prev + 5, 9) to (start + 3, 16) +- Code(Counter(13)) at (prev + 5, 13) to (start + 0, 27) +- Code(Expression(10, Sub)) at (prev + 2, 13) to (start + 0, 28) + = (c10 - c13) +- Code(Expression(11, Sub)) at (prev + 4, 9) to (start + 5, 6) = ((c8 - c9) - c10) - Code(Counter(12)) at (prev + 6, 5) to (start + 3, 6) -- Code(Expression(8, Sub)) at (prev + 4, 5) to (start + 3, 6) +- Code(Expression(13, Sub)) at (prev + 4, 5) to (start + 3, 6) = (c12 - c14) - Code(Counter(15)) at (prev + 4, 9) to (start + 4, 6) -- Code(Expression(11, Sub)) at (prev + 5, 8) to (start + 0, 15) +- Code(Expression(16, Sub)) at (prev + 5, 8) to (start + 0, 15) = (c15 - c16) - Code(Counter(17)) at (prev + 1, 9) to (start + 3, 10) -- Code(Expression(10, Sub)) at (prev + 5, 9) to (start + 3, 10) +- Code(Expression(15, Sub)) at (prev + 5, 9) to (start + 3, 10) = ((c15 - c16) - c17) -- Code(Expression(15, Add)) at (prev + 5, 8) to (start + 0, 15) +- Code(Expression(24, Add)) at (prev + 5, 8) to (start + 0, 15) = ((c17 - c19) + c18) - Code(Counter(20)) at (prev + 1, 9) to (start + 0, 19) -- Code(Zero) at (prev + 3, 13) to (start + 0, 29) -- Code(Expression(14, Sub)) at (prev + 3, 9) to (start + 0, 19) +- Code(Counter(22)) at (prev + 3, 13) to (start + 0, 29) +- Code(Expression(23, Sub)) at (prev + 3, 9) to (start + 0, 19) = (((c17 - c19) + c18) - c20) -- Code(Zero) at (prev + 3, 13) to (start + 0, 29) -- Code(Expression(33, Add)) at (prev + 3, 5) to (start + 0, 15) +- Code(Expression(22, Sub)) at (prev + 3, 13) to (start + 0, 29) + = ((((c17 - c19) + c18) - c20) - c21) +- Code(Expression(42, Add)) at (prev + 3, 5) to (start + 0, 15) = (c23 + (((c20 - c22) + c21) - c23)) -- Code(Expression(35, Add)) at (prev + 1, 12) to (start + 0, 19) +- Code(Expression(44, Add)) at (prev + 1, 12) to (start + 0, 19) = ((c20 - c22) + c21) - Code(Counter(23)) at (prev + 1, 13) to (start + 0, 19) -- Code(Expression(34, Sub)) at (prev + 2, 13) to (start + 0, 19) +- Code(Expression(43, Sub)) at (prev + 2, 13) to (start + 0, 19) = (((c20 - c22) + c21) - c23) -- Code(Expression(32, Sub)) at (prev + 4, 5) to (start + 2, 19) +- Code(Expression(41, Sub)) at (prev + 4, 5) to (start + 2, 19) = ((c23 + (((c20 - c22) + c21) - c23)) - c24) - Code(Counter(25)) at (prev + 3, 13) to (start + 0, 19) -- Code(Expression(31, Sub)) at (prev + 2, 13) to (start + 0, 19) +- Code(Expression(40, Sub)) at (prev + 2, 13) to (start + 0, 19) = (((c23 + (((c20 - c22) + c21) - c23)) - c24) - c25) -- Code(Expression(60, Add)) at (prev + 3, 5) to (start + 0, 15) +- Code(Expression(69, Add)) at (prev + 3, 5) to (start + 0, 15) = (c29 + ((c28 + ((c26 - c27) - c28)) - c30)) - Code(Counter(26)) at (prev + 1, 12) to (start + 0, 19) - Code(Counter(27)) at (prev + 1, 13) to (start + 3, 14) - Code(Counter(29)) at (prev + 4, 13) to (start + 0, 19) -- Code(Expression(62, Add)) at (prev + 2, 13) to (start + 0, 23) +- Code(Expression(71, Add)) at (prev + 2, 13) to (start + 0, 23) = (c28 + ((c26 - c27) - c28)) -- Code(Expression(64, Sub)) at (prev + 1, 20) to (start + 0, 27) +- Code(Expression(73, Sub)) at (prev + 1, 20) to (start + 0, 27) = (c26 - c27) - Code(Counter(28)) at (prev + 1, 21) to (start + 0, 27) -- Code(Expression(63, Sub)) at (prev + 2, 21) to (start + 0, 27) +- Code(Expression(72, Sub)) at (prev + 2, 21) to (start + 0, 27) = ((c26 - c27) - c28) -- Code(Expression(61, Sub)) at (prev + 4, 13) to (start + 0, 19) +- Code(Expression(70, Sub)) at (prev + 4, 13) to (start + 0, 19) = ((c28 + ((c26 - c27) - c28)) - c30) - Code(Counter(31)) at (prev + 3, 9) to (start + 0, 25) -- Code(Expression(59, Sub)) at (prev + 2, 5) to (start + 0, 15) +- Code(Expression(68, Sub)) at (prev + 2, 5) to (start + 0, 15) = ((c29 + ((c28 + ((c26 - c27) - c28)) - c30)) - c31) -- Code(Expression(58, Sub)) at (prev + 3, 9) to (start + 0, 34) +- Code(Expression(67, Sub)) at (prev + 3, 9) to (start + 0, 34) = (((c29 + ((c28 + ((c26 - c27) - c28)) - c30)) - c31) - c32) -- Code(Zero) at (prev + 2, 5) to (start + 0, 15) -- Code(Zero) at (prev + 3, 9) to (start + 0, 44) -- Code(Zero) at (prev + 2, 1) to (start + 0, 2) +- Code(Counter(32)) at (prev + 2, 5) to (start + 0, 15) +- Code(Expression(74, Sub)) at (prev + 3, 9) to (start + 0, 44) + = (c32 - c33) +- Code(Counter(33)) at (prev + 2, 1) to (start + 0, 2) diff --git a/tests/incremental/hashes/enum_constructors.rs b/tests/incremental/hashes/enum_constructors.rs index f685fe46d70d0..db367d07094d7 100644 --- a/tests/incremental/hashes/enum_constructors.rs +++ b/tests/incremental/hashes/enum_constructors.rs @@ -334,9 +334,9 @@ pub fn change_constructor_variant_c_like() { } #[cfg(not(any(cfail1,cfail4)))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes")] #[rustc_clean(cfg="cfail3")] -#[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")] +#[rustc_clean(cfg="cfail5", except="hir_owner_nodes")] #[rustc_clean(cfg="cfail6")] pub fn change_constructor_variant_c_like() { let _x = Clike::C; diff --git a/tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-abort.diff b/tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-abort.diff index b2f58f8f771d7..52aedbcc82014 100644 --- a/tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-abort.diff @@ -28,7 +28,7 @@ bb1: { - _1 = _2[_3]; -+ _1 = const 2_u32; ++ _1 = _2[2 of 3]; StorageDead(_3); StorageDead(_2); _0 = const (); diff --git a/tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-unwind.diff b/tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-unwind.diff index f9e3f8f171ad4..a44c95b918227 100644 --- a/tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-unwind.diff @@ -28,7 +28,7 @@ bb1: { - _1 = _2[_3]; -+ _1 = const 2_u32; ++ _1 = _2[2 of 3]; StorageDead(_3); StorageDead(_2); _0 = const (); diff --git a/tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-abort.diff b/tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-abort.diff index b2f58f8f771d7..52aedbcc82014 100644 --- a/tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-abort.diff @@ -28,7 +28,7 @@ bb1: { - _1 = _2[_3]; -+ _1 = const 2_u32; ++ _1 = _2[2 of 3]; StorageDead(_3); StorageDead(_2); _0 = const (); diff --git a/tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-unwind.diff b/tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-unwind.diff index f9e3f8f171ad4..a44c95b918227 100644 --- a/tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-unwind.diff @@ -28,7 +28,7 @@ bb1: { - _1 = _2[_3]; -+ _1 = const 2_u32; ++ _1 = _2[2 of 3]; StorageDead(_3); StorageDead(_2); _0 = const (); diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-abort.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-abort.diff index e443c8991f9a6..54b9b6cc0d467 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-abort.diff @@ -34,11 +34,12 @@ StorageLive(_5); StorageLive(_6); _6 = const 3_usize; - _7 = Len((*_1)); +- _7 = Len((*_1)); - _8 = Lt(_6, _7); - assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind unreachable]; -+ _8 = Lt(const 3_usize, _7); -+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 3_usize) -> [success: bb1, unwind unreachable]; ++ _7 = const 3_usize; ++ _8 = const false; ++ assert(const false, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 3_usize) -> [success: bb1, unwind unreachable]; } bb1: { diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-unwind.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-unwind.diff index 592f43f473979..483ad8012c29b 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-unwind.diff @@ -34,11 +34,12 @@ StorageLive(_5); StorageLive(_6); _6 = const 3_usize; - _7 = Len((*_1)); +- _7 = Len((*_1)); - _8 = Lt(_6, _7); - assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind continue]; -+ _8 = Lt(const 3_usize, _7); -+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 3_usize) -> [success: bb1, unwind continue]; ++ _7 = const 3_usize; ++ _8 = const false; ++ assert(const false, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 3_usize) -> [success: bb1, unwind continue]; } bb1: { diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-abort.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-abort.diff index e443c8991f9a6..54b9b6cc0d467 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-abort.diff @@ -34,11 +34,12 @@ StorageLive(_5); StorageLive(_6); _6 = const 3_usize; - _7 = Len((*_1)); +- _7 = Len((*_1)); - _8 = Lt(_6, _7); - assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind unreachable]; -+ _8 = Lt(const 3_usize, _7); -+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 3_usize) -> [success: bb1, unwind unreachable]; ++ _7 = const 3_usize; ++ _8 = const false; ++ assert(const false, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 3_usize) -> [success: bb1, unwind unreachable]; } bb1: { diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-unwind.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-unwind.diff index 592f43f473979..483ad8012c29b 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-unwind.diff @@ -34,11 +34,12 @@ StorageLive(_5); StorageLive(_6); _6 = const 3_usize; - _7 = Len((*_1)); +- _7 = Len((*_1)); - _8 = Lt(_6, _7); - assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind continue]; -+ _8 = Lt(const 3_usize, _7); -+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 3_usize) -> [success: bb1, unwind continue]; ++ _7 = const 3_usize; ++ _8 = const false; ++ assert(const false, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 3_usize) -> [success: bb1, unwind continue]; } bb1: { diff --git a/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-abort.diff index 6daef87dd2c73..95e7d81823c35 100644 --- a/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-abort.diff @@ -11,9 +11,8 @@ bb0: { StorageLive(_1); -- _2 = CheckedAdd(const 1_u32, const 1_u32); + _2 = CheckedAdd(const 1_u32, const 1_u32); - assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 1_u32, const 1_u32) -> [success: bb1, unwind unreachable]; -+ _2 = const (2_u32, false); + assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 1_u32, const 1_u32) -> [success: bb1, unwind unreachable]; } diff --git a/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-unwind.diff index 125407bf285a3..f2c334cc6d0dc 100644 --- a/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-unwind.diff @@ -11,9 +11,8 @@ bb0: { StorageLive(_1); -- _2 = CheckedAdd(const 1_u32, const 1_u32); + _2 = CheckedAdd(const 1_u32, const 1_u32); - assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 1_u32, const 1_u32) -> [success: bb1, unwind continue]; -+ _2 = const (2_u32, false); + assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 1_u32, const 1_u32) -> [success: bb1, unwind continue]; } diff --git a/tests/mir-opt/const_prop/control_flow_simplification.hello.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/control_flow_simplification.hello.ConstProp.panic-abort.diff index ba2e89f0a7445..e77c09848b7b8 100644 --- a/tests/mir-opt/const_prop/control_flow_simplification.hello.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/control_flow_simplification.hello.ConstProp.panic-abort.diff @@ -8,9 +8,8 @@ bb0: { StorageLive(_1); -- _1 = const _; + _1 = const _; - switchInt(move _1) -> [0: bb2, otherwise: bb1]; -+ _1 = const false; + switchInt(const false) -> [0: bb2, otherwise: bb1]; } diff --git a/tests/mir-opt/const_prop/control_flow_simplification.hello.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/control_flow_simplification.hello.ConstProp.panic-unwind.diff index e0a610f60a795..7496d25430977 100644 --- a/tests/mir-opt/const_prop/control_flow_simplification.hello.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/control_flow_simplification.hello.ConstProp.panic-unwind.diff @@ -8,9 +8,8 @@ bb0: { StorageLive(_1); -- _1 = const _; + _1 = const _; - switchInt(move _1) -> [0: bb2, otherwise: bb1]; -+ _1 = const false; + switchInt(const false) -> [0: bb2, otherwise: bb1]; } diff --git a/tests/mir-opt/const_prop/discriminant.main.ConstProp.32bit.diff b/tests/mir-opt/const_prop/discriminant.main.ConstProp.32bit.diff index e02e7f320b865..17f1e86f324a8 100644 --- a/tests/mir-opt/const_prop/discriminant.main.ConstProp.32bit.diff +++ b/tests/mir-opt/const_prop/discriminant.main.ConstProp.32bit.diff @@ -17,10 +17,9 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); -- _3 = Option::::Some(const true); + _3 = Option::::Some(const true); - _4 = discriminant(_3); - switchInt(move _4) -> [1: bb1, otherwise: bb3]; -+ _3 = const Option::::Some(true); + _4 = const 1_isize; + switchInt(const 1_isize) -> [1: bb1, otherwise: bb3]; } diff --git a/tests/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff b/tests/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff index e02e7f320b865..17f1e86f324a8 100644 --- a/tests/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff +++ b/tests/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff @@ -17,10 +17,9 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); -- _3 = Option::::Some(const true); + _3 = Option::::Some(const true); - _4 = discriminant(_3); - switchInt(move _4) -> [1: bb1, otherwise: bb3]; -+ _3 = const Option::::Some(true); + _4 = const 1_isize; + switchInt(const 1_isize) -> [1: bb1, otherwise: bb3]; } diff --git a/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-abort.diff index ca0ce2888cd6e..4a2d6797246d0 100644 --- a/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-abort.diff @@ -17,7 +17,7 @@ - _3 = CheckedAdd(_2, const 1_u8); - assert(!move (_3.1: bool), "attempt to compute `{} + {}`, which would overflow", move _2, const 1_u8) -> [success: bb1, unwind unreachable]; + _2 = const 2_u8; -+ _3 = const (3_u8, false); ++ _3 = CheckedAdd(const 2_u8, const 1_u8); + assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_u8, const 1_u8) -> [success: bb1, unwind unreachable]; } diff --git a/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-unwind.diff index d63fb9255a326..8ae437f70e92b 100644 --- a/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-unwind.diff @@ -17,7 +17,7 @@ - _3 = CheckedAdd(_2, const 1_u8); - assert(!move (_3.1: bool), "attempt to compute `{} + {}`, which would overflow", move _2, const 1_u8) -> [success: bb1, unwind continue]; + _2 = const 2_u8; -+ _3 = const (3_u8, false); ++ _3 = CheckedAdd(const 2_u8, const 1_u8); + assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_u8, const 1_u8) -> [success: bb1, unwind continue]; } diff --git a/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-abort.diff index 51e17cf690aca..5fb0f21ecd22d 100644 --- a/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-abort.diff @@ -22,7 +22,7 @@ _3 = const 1_u8; - _4 = CheckedAdd(_2, _3); - assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> [success: bb1, unwind unreachable]; -+ _4 = const (0_u8, true); ++ _4 = CheckedAdd(const u8::MAX, const 1_u8); + assert(!const true, "attempt to compute `{} + {}`, which would overflow", const u8::MAX, const 1_u8) -> [success: bb1, unwind unreachable]; } diff --git a/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-unwind.diff index 5ef201497fbcd..7a6993cf0c6ed 100644 --- a/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-unwind.diff @@ -22,7 +22,7 @@ _3 = const 1_u8; - _4 = CheckedAdd(_2, _3); - assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> [success: bb1, unwind continue]; -+ _4 = const (0_u8, true); ++ _4 = CheckedAdd(const u8::MAX, const 1_u8); + assert(!const true, "attempt to compute `{} + {}`, which would overflow", const u8::MAX, const 1_u8) -> [success: bb1, unwind continue]; } diff --git a/tests/mir-opt/const_prop/invalid_constant.main.ConstProp.diff b/tests/mir-opt/const_prop/invalid_constant.main.ConstProp.diff index 10e978a683acc..90adb07103d0d 100644 --- a/tests/mir-opt/const_prop/invalid_constant.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/invalid_constant.main.ConstProp.diff @@ -35,17 +35,14 @@ StorageLive(_1); StorageLive(_2); _2 = InvalidChar { int: const 1114113_u32 }; -- _1 = (_2.1: char); -+ _1 = const {transmute(0x00110001): char}; + _1 = (_2.1: char); StorageDead(_2); StorageLive(_3); StorageLive(_4); StorageLive(_5); _5 = InvalidTag { int: const 4_u32 }; -- _4 = (_5.1: E); -- _3 = [move _4]; -+ _4 = const Scalar(0x00000004): E; -+ _3 = [const Scalar(0x00000004): E]; + _4 = (_5.1: E); + _3 = [move _4]; StorageDead(_4); StorageDead(_5); nop; diff --git a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff index 170c019782df3..516f13586d3ff 100644 --- a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff @@ -8,10 +8,8 @@ bb0: { StorageLive(_2); -- _2 = (const (), const 0_u8, const 0_u8); -- _1 = encode(move _2) -> [return: bb1, unwind unreachable]; -+ _2 = const ((), 0_u8, 0_u8); -+ _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind unreachable]; + _2 = (const (), const 0_u8, const 0_u8); + _1 = encode(move _2) -> [return: bb1, unwind unreachable]; } bb1: { diff --git a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff index 64227dfd78c2c..5e3443228cd25 100644 --- a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff @@ -8,10 +8,8 @@ bb0: { StorageLive(_2); -- _2 = (const (), const 0_u8, const 0_u8); -- _1 = encode(move _2) -> [return: bb1, unwind continue]; -+ _2 = const ((), 0_u8, 0_u8); -+ _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind continue]; + _2 = (const (), const 0_u8, const 0_u8); + _1 = encode(move _2) -> [return: bb1, unwind continue]; } bb1: { diff --git a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff index e1f3f37b37074..5369217c5b52f 100644 --- a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff @@ -10,13 +10,10 @@ bb0: { StorageLive(_2); StorageLive(_3); -- _3 = (const 1_u8, const 2_u8); -- _2 = (move _3,); -+ _3 = const (1_u8, 2_u8); -+ _2 = const ((1_u8, 2_u8),); + _3 = (const 1_u8, const 2_u8); + _2 = (move _3,); StorageDead(_3); -- _1 = test(move _2) -> [return: bb1, unwind unreachable]; -+ _1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind unreachable]; + _1 = test(move _2) -> [return: bb1, unwind unreachable]; } bb1: { diff --git a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff index aaa376a95cf66..d1d7b00b37f65 100644 --- a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff @@ -10,13 +10,10 @@ bb0: { StorageLive(_2); StorageLive(_3); -- _3 = (const 1_u8, const 2_u8); -- _2 = (move _3,); -+ _3 = const (1_u8, 2_u8); -+ _2 = const ((1_u8, 2_u8),); + _3 = (const 1_u8, const 2_u8); + _2 = (move _3,); StorageDead(_3); -- _1 = test(move _2) -> [return: bb1, unwind continue]; -+ _1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind continue]; + _1 = test(move _2) -> [return: bb1, unwind continue]; } bb1: { diff --git a/tests/mir-opt/const_prop/mutable_variable.main.ConstProp.diff b/tests/mir-opt/const_prop/mutable_variable.main.ConstProp.diff index ad8d9ddb0743f..93f17d60bc75c 100644 --- a/tests/mir-opt/const_prop/mutable_variable.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/mutable_variable.main.ConstProp.diff @@ -17,8 +17,7 @@ _1 = const 42_i32; _1 = const 99_i32; StorageLive(_2); -- _2 = _1; -+ _2 = const 99_i32; + _2 = _1; _0 = const (); StorageDead(_2); StorageDead(_1); diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate.main.ConstProp.diff b/tests/mir-opt/const_prop/mutable_variable_aggregate.main.ConstProp.diff index 0f118c7f59fdf..c95af36182410 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate.main.ConstProp.diff @@ -14,12 +14,10 @@ bb0: { StorageLive(_1); -- _1 = (const 42_i32, const 43_i32); -+ _1 = const (42_i32, 43_i32); + _1 = (const 42_i32, const 43_i32); (_1.1: i32) = const 99_i32; StorageLive(_2); -- _2 = _1; -+ _2 = const (42_i32, 99_i32); + _2 = _1; _0 = const (); StorageDead(_2); StorageDead(_1); diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.ConstProp.panic-abort.diff index 34288c62fee12..fcb6327f50296 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.ConstProp.panic-abort.diff @@ -21,8 +21,7 @@ (_1.1: i32) = const 99_i32; (_1.0: i32) = const 42_i32; StorageLive(_2); -- _2 = (_1.1: i32); -+ _2 = const 99_i32; + _2 = (_1.1: i32); _0 = const (); StorageDead(_2); StorageDead(_1); diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.ConstProp.panic-unwind.diff index 7ba2b483dc3fb..4b2bb7c483d2a 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.main.ConstProp.panic-unwind.diff @@ -21,8 +21,7 @@ (_1.1: i32) = const 99_i32; (_1.0: i32) = const 42_i32; StorageLive(_2); -- _2 = (_1.1: i32); -+ _2 = const 99_i32; + _2 = (_1.1: i32); _0 = const (); StorageDead(_2); StorageDead(_1); diff --git a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-abort.diff index a85dcf9c7edf7..a8d6f979e6212 100644 --- a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-abort.diff @@ -28,8 +28,7 @@ bb1: { StorageLive(_2); -- _2 = (const 1_i32, const 2_i32); -+ _2 = const (1_i32, 2_i32); + _2 = (const 1_i32, const 2_i32); StorageLive(_3); _3 = _1; (_2.1: i32) = move _3; @@ -37,8 +36,7 @@ StorageLive(_4); _4 = (_2.1: i32); StorageLive(_5); -- _5 = (_2.0: i32); -+ _5 = const 1_i32; + _5 = (_2.0: i32); _0 = const (); StorageDead(_5); StorageDead(_4); diff --git a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-unwind.diff index 15ef0fa4dfff7..ac6a2352a2258 100644 --- a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-unwind.diff @@ -28,8 +28,7 @@ bb1: { StorageLive(_2); -- _2 = (const 1_i32, const 2_i32); -+ _2 = const (1_i32, 2_i32); + _2 = (const 1_i32, const 2_i32); StorageLive(_3); _3 = _1; (_2.1: i32) = move _3; @@ -37,8 +36,7 @@ StorageLive(_4); _4 = (_2.1: i32); StorageLive(_5); -- _5 = (_2.0: i32); -+ _5 = const 1_i32; + _5 = (_2.0: i32); _0 = const (); StorageDead(_5); StorageDead(_4); diff --git a/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-abort.diff index 7519331f6d7d4..c622f0d6b6c92 100644 --- a/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-abort.diff @@ -43,16 +43,20 @@ StorageDead(_4); StorageLive(_5); StorageLive(_6); - _6 = OffsetOf(Delta, [1]); - _5 = must_use::(move _6) -> [return: bb3, unwind unreachable]; +- _6 = OffsetOf(Delta, [1]); +- _5 = must_use::(move _6) -> [return: bb3, unwind unreachable]; ++ _6 = const 0_usize; ++ _5 = must_use::(const 0_usize) -> [return: bb3, unwind unreachable]; } bb3: { StorageDead(_6); StorageLive(_7); StorageLive(_8); - _8 = OffsetOf(Delta, [2]); - _7 = must_use::(move _8) -> [return: bb4, unwind unreachable]; +- _8 = OffsetOf(Delta, [2]); +- _7 = must_use::(move _8) -> [return: bb4, unwind unreachable]; ++ _8 = const 2_usize; ++ _7 = must_use::(const 2_usize) -> [return: bb4, unwind unreachable]; } bb4: { diff --git a/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-unwind.diff index fd5206e460c6d..f996b7f8e2c68 100644 --- a/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-unwind.diff @@ -43,16 +43,20 @@ StorageDead(_4); StorageLive(_5); StorageLive(_6); - _6 = OffsetOf(Delta, [1]); - _5 = must_use::(move _6) -> [return: bb3, unwind continue]; +- _6 = OffsetOf(Delta, [1]); +- _5 = must_use::(move _6) -> [return: bb3, unwind continue]; ++ _6 = const 0_usize; ++ _5 = must_use::(const 0_usize) -> [return: bb3, unwind continue]; } bb3: { StorageDead(_6); StorageLive(_7); StorageLive(_8); - _8 = OffsetOf(Delta, [2]); - _7 = must_use::(move _8) -> [return: bb4, unwind continue]; +- _8 = OffsetOf(Delta, [2]); +- _7 = must_use::(move _8) -> [return: bb4, unwind continue]; ++ _8 = const 2_usize; ++ _7 = must_use::(const 2_usize) -> [return: bb4, unwind continue]; } bb4: { diff --git a/tests/mir-opt/const_prop/read_immutable_static.main.ConstProp.diff b/tests/mir-opt/const_prop/read_immutable_static.main.ConstProp.diff index 29c455f35b35a..b53fb01b8e95a 100644 --- a/tests/mir-opt/const_prop/read_immutable_static.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/read_immutable_static.main.ConstProp.diff @@ -17,15 +17,12 @@ StorageLive(_2); StorageLive(_3); _3 = const {alloc1: &u8}; -- _2 = (*_3); -+ _2 = const 2_u8; + _2 = (*_3); StorageLive(_4); StorageLive(_5); _5 = const {alloc1: &u8}; -- _4 = (*_5); -- _1 = Add(move _2, move _4); -+ _4 = const 2_u8; -+ _1 = const 4_u8; + _4 = (*_5); + _1 = Add(move _2, move _4); StorageDead(_4); StorageDead(_2); StorageDead(_5); diff --git a/tests/mir-opt/const_prop/repeat.main.ConstProp.32bit.panic-abort.diff b/tests/mir-opt/const_prop/repeat.main.ConstProp.32bit.panic-abort.diff index a55bd029e99ab..9278b6edcf4df 100644 --- a/tests/mir-opt/const_prop/repeat.main.ConstProp.32bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/repeat.main.ConstProp.32bit.panic-abort.diff @@ -30,9 +30,8 @@ bb1: { - _2 = _3[_4]; -- _1 = Add(move _2, const 0_u32); -+ _2 = const 42_u32; -+ _1 = const 42_u32; ++ _2 = _3[2 of 3]; + _1 = Add(move _2, const 0_u32); StorageDead(_2); StorageDead(_4); StorageDead(_3); diff --git a/tests/mir-opt/const_prop/repeat.main.ConstProp.32bit.panic-unwind.diff b/tests/mir-opt/const_prop/repeat.main.ConstProp.32bit.panic-unwind.diff index d49ef2e0179f8..72e5bfaa543a5 100644 --- a/tests/mir-opt/const_prop/repeat.main.ConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/repeat.main.ConstProp.32bit.panic-unwind.diff @@ -30,9 +30,8 @@ bb1: { - _2 = _3[_4]; -- _1 = Add(move _2, const 0_u32); -+ _2 = const 42_u32; -+ _1 = const 42_u32; ++ _2 = _3[2 of 3]; + _1 = Add(move _2, const 0_u32); StorageDead(_2); StorageDead(_4); StorageDead(_3); diff --git a/tests/mir-opt/const_prop/repeat.main.ConstProp.64bit.panic-abort.diff b/tests/mir-opt/const_prop/repeat.main.ConstProp.64bit.panic-abort.diff index a55bd029e99ab..9278b6edcf4df 100644 --- a/tests/mir-opt/const_prop/repeat.main.ConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/repeat.main.ConstProp.64bit.panic-abort.diff @@ -30,9 +30,8 @@ bb1: { - _2 = _3[_4]; -- _1 = Add(move _2, const 0_u32); -+ _2 = const 42_u32; -+ _1 = const 42_u32; ++ _2 = _3[2 of 3]; + _1 = Add(move _2, const 0_u32); StorageDead(_2); StorageDead(_4); StorageDead(_3); diff --git a/tests/mir-opt/const_prop/repeat.main.ConstProp.64bit.panic-unwind.diff b/tests/mir-opt/const_prop/repeat.main.ConstProp.64bit.panic-unwind.diff index d49ef2e0179f8..72e5bfaa543a5 100644 --- a/tests/mir-opt/const_prop/repeat.main.ConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/repeat.main.ConstProp.64bit.panic-unwind.diff @@ -30,9 +30,8 @@ bb1: { - _2 = _3[_4]; -- _1 = Add(move _2, const 0_u32); -+ _2 = const 42_u32; -+ _1 = const 42_u32; ++ _2 = _3[2 of 3]; + _1 = Add(move _2, const 0_u32); StorageDead(_2); StorageDead(_4); StorageDead(_3); diff --git a/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-abort.diff index f3b30e0dcde46..99bcb79098cf4 100644 --- a/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-abort.diff @@ -6,9 +6,8 @@ let mut _1: (u32, bool); bb0: { -- _1 = CheckedAdd(const 2_u32, const 2_u32); + _1 = CheckedAdd(const 2_u32, const 2_u32); - assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_u32, const 2_u32) -> [success: bb1, unwind unreachable]; -+ _1 = const (4_u32, false); + assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_u32, const 2_u32) -> [success: bb1, unwind unreachable]; } diff --git a/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-unwind.diff index 79f85fcef110e..2194d0fd4e7b7 100644 --- a/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-unwind.diff @@ -6,9 +6,8 @@ let mut _1: (u32, bool); bb0: { -- _1 = CheckedAdd(const 2_u32, const 2_u32); + _1 = CheckedAdd(const 2_u32, const 2_u32); - assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_u32, const 2_u32) -> [success: bb1, unwind continue]; -+ _1 = const (4_u32, false); + assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_u32, const 2_u32) -> [success: bb1, unwind continue]; } diff --git a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir index c8f3f641a6d75..b6d1feae23f7d 100644 --- a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir +++ b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir @@ -5,7 +5,7 @@ fn add() -> u32 { let mut _1: (u32, bool); bb0: { - _1 = const (4_u32, false); + _1 = CheckedAdd(const 2_u32, const 2_u32); assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_u32, const 2_u32) -> [success: bb1, unwind unreachable]; } diff --git a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir index 9a06469746361..edcc782c7ad5c 100644 --- a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir +++ b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir @@ -5,7 +5,7 @@ fn add() -> u32 { let mut _1: (u32, bool); bb0: { - _1 = const (4_u32, false); + _1 = CheckedAdd(const 2_u32, const 2_u32); assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_u32, const 2_u32) -> [success: bb1, unwind continue]; } diff --git a/tests/mir-opt/const_prop/slice_len.main.ConstProp.32bit.panic-abort.diff b/tests/mir-opt/const_prop/slice_len.main.ConstProp.32bit.panic-abort.diff index c2e1288b41e44..4288f57be43c1 100644 --- a/tests/mir-opt/const_prop/slice_len.main.ConstProp.32bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/slice_len.main.ConstProp.32bit.panic-abort.diff @@ -35,7 +35,7 @@ bb1: { - _1 = (*_2)[_6]; -+ _1 = const 2_u32; ++ _1 = (*_2)[1 of 2]; StorageDead(_6); StorageDead(_4); StorageDead(_2); diff --git a/tests/mir-opt/const_prop/slice_len.main.ConstProp.32bit.panic-unwind.diff b/tests/mir-opt/const_prop/slice_len.main.ConstProp.32bit.panic-unwind.diff index 23646c3c9762c..d9e745345c69d 100644 --- a/tests/mir-opt/const_prop/slice_len.main.ConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/slice_len.main.ConstProp.32bit.panic-unwind.diff @@ -35,7 +35,7 @@ bb1: { - _1 = (*_2)[_6]; -+ _1 = const 2_u32; ++ _1 = (*_2)[1 of 2]; StorageDead(_6); StorageDead(_4); StorageDead(_2); diff --git a/tests/mir-opt/const_prop/slice_len.main.ConstProp.64bit.panic-abort.diff b/tests/mir-opt/const_prop/slice_len.main.ConstProp.64bit.panic-abort.diff index c2e1288b41e44..4288f57be43c1 100644 --- a/tests/mir-opt/const_prop/slice_len.main.ConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/slice_len.main.ConstProp.64bit.panic-abort.diff @@ -35,7 +35,7 @@ bb1: { - _1 = (*_2)[_6]; -+ _1 = const 2_u32; ++ _1 = (*_2)[1 of 2]; StorageDead(_6); StorageDead(_4); StorageDead(_2); diff --git a/tests/mir-opt/const_prop/slice_len.main.ConstProp.64bit.panic-unwind.diff b/tests/mir-opt/const_prop/slice_len.main.ConstProp.64bit.panic-unwind.diff index 23646c3c9762c..d9e745345c69d 100644 --- a/tests/mir-opt/const_prop/slice_len.main.ConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/slice_len.main.ConstProp.64bit.panic-unwind.diff @@ -35,7 +35,7 @@ bb1: { - _1 = (*_2)[_6]; -+ _1 = const 2_u32; ++ _1 = (*_2)[1 of 2]; StorageDead(_6); StorageDead(_4); StorageDead(_2); diff --git a/tests/mir-opt/const_prop/transmute.less_as_i8.ConstProp.32bit.diff b/tests/mir-opt/const_prop/transmute.less_as_i8.ConstProp.32bit.diff index 7ac7bed8a5f70..077d3adf62b5c 100644 --- a/tests/mir-opt/const_prop/transmute.less_as_i8.ConstProp.32bit.diff +++ b/tests/mir-opt/const_prop/transmute.less_as_i8.ConstProp.32bit.diff @@ -9,10 +9,8 @@ bb0: { StorageLive(_1); -- _1 = Less; -- _0 = move _1 as i8 (Transmute); -+ _1 = const Less; -+ _0 = const -1_i8; + _1 = Less; + _0 = move _1 as i8 (Transmute); StorageDead(_1); return; } diff --git a/tests/mir-opt/const_prop/transmute.less_as_i8.ConstProp.64bit.diff b/tests/mir-opt/const_prop/transmute.less_as_i8.ConstProp.64bit.diff index 7ac7bed8a5f70..077d3adf62b5c 100644 --- a/tests/mir-opt/const_prop/transmute.less_as_i8.ConstProp.64bit.diff +++ b/tests/mir-opt/const_prop/transmute.less_as_i8.ConstProp.64bit.diff @@ -9,10 +9,8 @@ bb0: { StorageLive(_1); -- _1 = Less; -- _0 = move _1 as i8 (Transmute); -+ _1 = const Less; -+ _0 = const -1_i8; + _1 = Less; + _0 = move _1 as i8 (Transmute); StorageDead(_1); return; } diff --git a/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-abort.diff index 9e705695ac0cd..08f4c8ba19044 100644 --- a/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-abort.diff @@ -12,14 +12,11 @@ bb0: { StorageLive(_1); -- _1 = (const 1_u32, const 2_u32); -+ _1 = const (1_u32, 2_u32); + _1 = (const 1_u32, const 2_u32); StorageLive(_2); StorageLive(_3); -- _3 = _1; -- _2 = consume(move _3) -> [return: bb1, unwind unreachable]; -+ _3 = const (1_u32, 2_u32); -+ _2 = consume(const (1_u32, 2_u32)) -> [return: bb1, unwind unreachable]; + _3 = _1; + _2 = consume(move _3) -> [return: bb1, unwind unreachable]; } bb1: { diff --git a/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-unwind.diff index 882dd97cc16b8..e46c8bcd7e35f 100644 --- a/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-unwind.diff @@ -12,14 +12,11 @@ bb0: { StorageLive(_1); -- _1 = (const 1_u32, const 2_u32); -+ _1 = const (1_u32, 2_u32); + _1 = (const 1_u32, const 2_u32); StorageLive(_2); StorageLive(_3); -- _3 = _1; -- _2 = consume(move _3) -> [return: bb1, unwind continue]; -+ _3 = const (1_u32, 2_u32); -+ _2 = consume(const (1_u32, 2_u32)) -> [return: bb1, unwind continue]; + _3 = _1; + _2 = consume(move _3) -> [return: bb1, unwind continue]; } bb1: { diff --git a/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-abort.diff b/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-abort.diff index a538756ba2d04..c94b3c178aaea 100644 --- a/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-abort.diff +++ b/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-abort.diff @@ -48,14 +48,12 @@ } bb2: { -- _6 = MinusPlus; -+ _6 = const MinusPlus; + _6 = MinusPlus; goto -> bb4; } bb3: { -- _6 = Minus; -+ _6 = const Minus; + _6 = Minus; goto -> bb4; } diff --git a/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-unwind.diff b/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-unwind.diff index 8a3dcfab44bd2..cf54a494ead72 100644 --- a/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-unwind.diff @@ -48,14 +48,12 @@ } bb2: { -- _6 = MinusPlus; -+ _6 = const MinusPlus; + _6 = MinusPlus; goto -> bb4; } bb3: { -- _6 = Minus; -+ _6 = const Minus; + _6 = Minus; goto -> bb4; } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-abort.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-abort.diff index 2c607b4c055fa..40ca630d9a07a 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-abort.diff +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-abort.diff @@ -24,9 +24,8 @@ bb0: { StorageLive(_1); -- _2 = CheckedAdd(const 2_i32, const 2_i32); + _2 = CheckedAdd(const 2_i32, const 2_i32); - assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind unreachable]; -+ _2 = const (4_i32, false); + assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind unreachable]; } @@ -47,7 +46,7 @@ bb2: { - _3 = _4[_5]; -+ _3 = const 3_i32; ++ _3 = _4[3 of 4]; StorageDead(_5); StorageDead(_4); _9 = const 42_u32; diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-unwind.diff index b6929f3f93c6c..1ea74e699bf52 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-unwind.diff @@ -24,9 +24,8 @@ bb0: { StorageLive(_1); -- _2 = CheckedAdd(const 2_i32, const 2_i32); + _2 = CheckedAdd(const 2_i32, const 2_i32); - assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind continue]; -+ _2 = const (4_i32, false); + assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind continue]; } @@ -47,7 +46,7 @@ bb2: { - _3 = _4[_5]; -+ _3 = const 3_i32; ++ _3 = _4[3 of 4]; StorageDead(_5); StorageDead(_4); _9 = const 42_u32; diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-abort.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-abort.diff index 2c607b4c055fa..40ca630d9a07a 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-abort.diff @@ -24,9 +24,8 @@ bb0: { StorageLive(_1); -- _2 = CheckedAdd(const 2_i32, const 2_i32); + _2 = CheckedAdd(const 2_i32, const 2_i32); - assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind unreachable]; -+ _2 = const (4_i32, false); + assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind unreachable]; } @@ -47,7 +46,7 @@ bb2: { - _3 = _4[_5]; -+ _3 = const 3_i32; ++ _3 = _4[3 of 4]; StorageDead(_5); StorageDead(_4); _9 = const 42_u32; diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-unwind.diff index b6929f3f93c6c..1ea74e699bf52 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-unwind.diff @@ -24,9 +24,8 @@ bb0: { StorageLive(_1); -- _2 = CheckedAdd(const 2_i32, const 2_i32); + _2 = CheckedAdd(const 2_i32, const 2_i32); - assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind continue]; -+ _2 = const (4_i32, false); + assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> [success: bb1, unwind continue]; } @@ -47,7 +46,7 @@ bb2: { - _3 = _4[_5]; -+ _3 = const 3_i32; ++ _3 = _4[3 of 4]; StorageDead(_5); StorageDead(_4); _9 = const 42_u32; diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-abort.mir b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-abort.mir index 681dadff302b9..e98b6b720230b 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-abort.mir @@ -4,8 +4,9 @@ fn main() -> () { let mut _0: (); scope 1 { debug x => const 4_i32; + let _1: i32; scope 2 { - debug y => const 3_i32; + debug y => _1; scope 3 { debug z => const 42_u32; } @@ -13,6 +14,8 @@ fn main() -> () { } bb0: { + StorageLive(_1); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-unwind.mir index 681dadff302b9..e98b6b720230b 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-unwind.mir @@ -4,8 +4,9 @@ fn main() -> () { let mut _0: (); scope 1 { debug x => const 4_i32; + let _1: i32; scope 2 { - debug y => const 3_i32; + debug y => _1; scope 3 { debug z => const 42_u32; } @@ -13,6 +14,8 @@ fn main() -> () { } bb0: { + StorageLive(_1); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.64bit.panic-abort.mir b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.64bit.panic-abort.mir index 681dadff302b9..e98b6b720230b 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.64bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.64bit.panic-abort.mir @@ -4,8 +4,9 @@ fn main() -> () { let mut _0: (); scope 1 { debug x => const 4_i32; + let _1: i32; scope 2 { - debug y => const 3_i32; + debug y => _1; scope 3 { debug z => const 42_u32; } @@ -13,6 +14,8 @@ fn main() -> () { } bb0: { + StorageLive(_1); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.64bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.64bit.panic-unwind.mir index 681dadff302b9..e98b6b720230b 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.64bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.64bit.panic-unwind.mir @@ -4,8 +4,9 @@ fn main() -> () { let mut _0: (); scope 1 { debug x => const 4_i32; + let _1: i32; scope 2 { - debug y => const 3_i32; + debug y => _1; scope 3 { debug z => const 42_u32; } @@ -13,6 +14,8 @@ fn main() -> () { } bb0: { + StorageLive(_1); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.32bit.panic-abort.mir b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.32bit.panic-abort.mir index 425b95db3363a..6045e890e9831 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.32bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.32bit.panic-abort.mir @@ -4,8 +4,9 @@ fn main() -> () { let mut _0: (); scope 1 { debug x => const 4_i32; + let _1: i32; scope 2 { - debug y => const 3_i32; + debug y => _1; scope 3 { debug z => const 42_u32; } @@ -13,6 +14,8 @@ fn main() -> () { } bb0: { + StorageLive(_1); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.32bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.32bit.panic-unwind.mir index 425b95db3363a..6045e890e9831 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.32bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.32bit.panic-unwind.mir @@ -4,8 +4,9 @@ fn main() -> () { let mut _0: (); scope 1 { debug x => const 4_i32; + let _1: i32; scope 2 { - debug y => const 3_i32; + debug y => _1; scope 3 { debug z => const 42_u32; } @@ -13,6 +14,8 @@ fn main() -> () { } bb0: { + StorageLive(_1); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.64bit.panic-abort.mir b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.64bit.panic-abort.mir index 425b95db3363a..6045e890e9831 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.64bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.64bit.panic-abort.mir @@ -4,8 +4,9 @@ fn main() -> () { let mut _0: (); scope 1 { debug x => const 4_i32; + let _1: i32; scope 2 { - debug y => const 3_i32; + debug y => _1; scope 3 { debug z => const 42_u32; } @@ -13,6 +14,8 @@ fn main() -> () { } bb0: { + StorageLive(_1); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.64bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.64bit.panic-unwind.mir index 425b95db3363a..6045e890e9831 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.64bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.SimplifyLocals-final.after.64bit.panic-unwind.mir @@ -4,8 +4,9 @@ fn main() -> () { let mut _0: (); scope 1 { debug x => const 4_i32; + let _1: i32; scope 2 { - debug y => const 3_i32; + debug y => _1; scope 3 { debug z => const 42_u32; } @@ -13,6 +14,8 @@ fn main() -> () { } bb0: { + StorageLive(_1); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir index 8590c9d3b8375..b50a11240fabf 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir @@ -63,7 +63,7 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> { bb1: { StorageDead(_3); - _0 = const Option::<&mut u32>::None; + _0 = Option::<&mut u32>::None; goto -> bb3; } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir index 8590c9d3b8375..b50a11240fabf 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir @@ -63,7 +63,7 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> { bb1: { StorageDead(_3); - _0 = const Option::<&mut u32>::None; + _0 = Option::<&mut u32>::None; goto -> bb3; }