diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs
index f3b88f46bae..94afb6edcf6 100644
--- a/compiler/rustc_feature/src/active.rs
+++ b/compiler/rustc_feature/src/active.rs
@@ -236,7 +236,7 @@ declare_features! (
/// Allows using the `#[fundamental]` attribute.
(active, fundamental, "1.0.0", Some(29635), None),
/// Allows using `#[link_name="llvm.*"]`.
- (active, link_llvm_intrinsics, "1.0.0", Some(29602), None),
+ (internal, link_llvm_intrinsics, "1.0.0", Some(29602), None),
/// Allows using the `#[linkage = ".."]` attribute.
(active, linkage, "1.0.0", Some(29603), None),
/// Allows declaring with `#![needs_panic_runtime]` that a panic runtime is needed.
@@ -245,6 +245,8 @@ declare_features! (
(active, packed_bundled_libs, "1.69.0", Some(108081), None),
/// Allows using the `#![panic_runtime]` attribute.
(internal, panic_runtime, "1.10.0", Some(32837), None),
+ /// Allows `extern "platform-intrinsic" { ... }`.
+ (internal, platform_intrinsics, "1.4.0", Some(27731), None),
/// Allows using `#[rustc_allow_const_fn_unstable]`.
/// This is an attribute on `const fn` for the same
/// purpose as `#[allow_internal_unstable]`.
@@ -526,8 +528,6 @@ declare_features! (
(active, object_safe_for_dispatch, "1.40.0", Some(43561), None),
/// Allows using `#[optimize(X)]`.
(active, optimize_attribute, "1.34.0", Some(54882), None),
- /// Allows `extern "platform-intrinsic" { ... }`.
- (active, platform_intrinsics, "1.4.0", Some(27731), None),
/// Allows using `#![plugin(myplugin)]`.
(active, plugin, "1.0.0", Some(29597), None),
/// Allows exhaustive integer pattern matching on `usize` and `isize`.
diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs
index 84434d585d3..284560465d6 100644
--- a/compiler/rustc_lint/src/lib.rs
+++ b/compiler/rustc_lint/src/lib.rs
@@ -86,18 +86,14 @@ mod unused;
pub use array_into_iter::ARRAY_INTO_ITER;
-use rustc_ast as ast;
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
use rustc_fluent_macro::fluent_messages;
-use rustc_hir as hir;
-use rustc_hir::def_id::{LocalDefId, LocalModDefId};
+use rustc_hir::def_id::LocalModDefId;
use rustc_middle::query::Providers;
use rustc_middle::ty::TyCtxt;
use rustc_session::lint::builtin::{
BARE_TRAIT_OBJECTS, ELIDED_LIFETIMES_IN_PATHS, EXPLICIT_OUTLIVES_REQUIREMENTS,
};
-use rustc_span::symbol::Ident;
-use rustc_span::Span;
use array_into_iter::ArrayIntoIter;
use builtin::*;
diff --git a/compiler/rustc_lint/src/passes.rs b/compiler/rustc_lint/src/passes.rs
index fca0eeeecc4..7d2a9102640 100644
--- a/compiler/rustc_lint/src/passes.rs
+++ b/compiler/rustc_lint/src/passes.rs
@@ -1,58 +1,53 @@
use crate::context::{EarlyContext, LateContext};
-use rustc_ast as ast;
-use rustc_hir as hir;
use rustc_session::lint::builtin::HardwiredLints;
use rustc_session::lint::LintPass;
-use rustc_span::def_id::LocalDefId;
-use rustc_span::symbol::Ident;
-use rustc_span::Span;
#[macro_export]
macro_rules! late_lint_methods {
($macro:path, $args:tt) => (
$macro!($args, [
- fn check_body(a: &'tcx hir::Body<'tcx>);
- fn check_body_post(a: &'tcx hir::Body<'tcx>);
+ fn check_body(a: &'tcx rustc_hir::Body<'tcx>);
+ fn check_body_post(a: &'tcx rustc_hir::Body<'tcx>);
fn check_crate();
fn check_crate_post();
- fn check_mod(a: &'tcx hir::Mod<'tcx>, b: hir::HirId);
- fn check_foreign_item(a: &'tcx hir::ForeignItem<'tcx>);
- fn check_item(a: &'tcx hir::Item<'tcx>);
- fn check_item_post(a: &'tcx hir::Item<'tcx>);
- fn check_local(a: &'tcx hir::Local<'tcx>);
- fn check_block(a: &'tcx hir::Block<'tcx>);
- fn check_block_post(a: &'tcx hir::Block<'tcx>);
- fn check_stmt(a: &'tcx hir::Stmt<'tcx>);
- fn check_arm(a: &'tcx hir::Arm<'tcx>);
- fn check_pat(a: &'tcx hir::Pat<'tcx>);
- fn check_expr(a: &'tcx hir::Expr<'tcx>);
- fn check_expr_post(a: &'tcx hir::Expr<'tcx>);
- fn check_ty(a: &'tcx hir::Ty<'tcx>);
- fn check_generic_param(a: &'tcx hir::GenericParam<'tcx>);
- fn check_generics(a: &'tcx hir::Generics<'tcx>);
- fn check_poly_trait_ref(a: &'tcx hir::PolyTraitRef<'tcx>);
+ fn check_mod(a: &'tcx rustc_hir::Mod<'tcx>, b: rustc_hir::HirId);
+ fn check_foreign_item(a: &'tcx rustc_hir::ForeignItem<'tcx>);
+ fn check_item(a: &'tcx rustc_hir::Item<'tcx>);
+ fn check_item_post(a: &'tcx rustc_hir::Item<'tcx>);
+ fn check_local(a: &'tcx rustc_hir::Local<'tcx>);
+ fn check_block(a: &'tcx rustc_hir::Block<'tcx>);
+ fn check_block_post(a: &'tcx rustc_hir::Block<'tcx>);
+ fn check_stmt(a: &'tcx rustc_hir::Stmt<'tcx>);
+ fn check_arm(a: &'tcx rustc_hir::Arm<'tcx>);
+ fn check_pat(a: &'tcx rustc_hir::Pat<'tcx>);
+ fn check_expr(a: &'tcx rustc_hir::Expr<'tcx>);
+ fn check_expr_post(a: &'tcx rustc_hir::Expr<'tcx>);
+ fn check_ty(a: &'tcx rustc_hir::Ty<'tcx>);
+ fn check_generic_param(a: &'tcx rustc_hir::GenericParam<'tcx>);
+ fn check_generics(a: &'tcx rustc_hir::Generics<'tcx>);
+ fn check_poly_trait_ref(a: &'tcx rustc_hir::PolyTraitRef<'tcx>);
fn check_fn(
a: rustc_hir::intravisit::FnKind<'tcx>,
- b: &'tcx hir::FnDecl<'tcx>,
- c: &'tcx hir::Body<'tcx>,
- d: Span,
- e: LocalDefId);
- fn check_trait_item(a: &'tcx hir::TraitItem<'tcx>);
- fn check_impl_item(a: &'tcx hir::ImplItem<'tcx>);
- fn check_impl_item_post(a: &'tcx hir::ImplItem<'tcx>);
- fn check_struct_def(a: &'tcx hir::VariantData<'tcx>);
- fn check_field_def(a: &'tcx hir::FieldDef<'tcx>);
- fn check_variant(a: &'tcx hir::Variant<'tcx>);
- fn check_path(a: &hir::Path<'tcx>, b: hir::HirId);
- fn check_attribute(a: &'tcx ast::Attribute);
+ b: &'tcx rustc_hir::FnDecl<'tcx>,
+ c: &'tcx rustc_hir::Body<'tcx>,
+ d: rustc_span::Span,
+ e: rustc_span::def_id::LocalDefId);
+ fn check_trait_item(a: &'tcx rustc_hir::TraitItem<'tcx>);
+ fn check_impl_item(a: &'tcx rustc_hir::ImplItem<'tcx>);
+ fn check_impl_item_post(a: &'tcx rustc_hir::ImplItem<'tcx>);
+ fn check_struct_def(a: &'tcx rustc_hir::VariantData<'tcx>);
+ fn check_field_def(a: &'tcx rustc_hir::FieldDef<'tcx>);
+ fn check_variant(a: &'tcx rustc_hir::Variant<'tcx>);
+ fn check_path(a: &rustc_hir::Path<'tcx>, b: rustc_hir::HirId);
+ fn check_attribute(a: &'tcx rustc_ast::Attribute);
/// Called when entering a syntax node that can have lint attributes such
/// as `#[allow(...)]`. Called with *all* the attributes of that node.
- fn enter_lint_attrs(a: &'tcx [ast::Attribute]);
+ fn enter_lint_attrs(a: &'tcx [rustc_ast::Attribute]);
/// Counterpart to `enter_lint_attrs`.
- fn exit_lint_attrs(a: &'tcx [ast::Attribute]);
+ fn exit_lint_attrs(a: &'tcx [rustc_ast::Attribute]);
]);
)
}
@@ -90,8 +85,8 @@ macro_rules! expand_combined_late_lint_pass_method {
#[macro_export]
macro_rules! expand_combined_late_lint_pass_methods {
($passes:tt, [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
- $(fn $name(&mut self, context: &LateContext<'tcx>, $($param: $arg),*) {
- expand_combined_late_lint_pass_method!($passes, self, $name, (context, $($param),*));
+ $(fn $name(&mut self, context: &$crate::LateContext<'tcx>, $($param: $arg),*) {
+ $crate::expand_combined_late_lint_pass_method!($passes, self, $name, (context, $($param),*));
})*
)
}
@@ -116,19 +111,19 @@ macro_rules! declare_combined_late_lint_pass {
}
}
- $v fn get_lints() -> LintArray {
+ $v fn get_lints() -> $crate::LintArray {
let mut lints = Vec::new();
$(lints.extend_from_slice(&$pass::get_lints());)*
lints
}
}
- impl<'tcx> LateLintPass<'tcx> for $name {
- expand_combined_late_lint_pass_methods!([$($pass),*], $methods);
+ impl<'tcx> $crate::LateLintPass<'tcx> for $name {
+ $crate::expand_combined_late_lint_pass_methods!([$($pass),*], $methods);
}
#[allow(rustc::lint_pass_impl_without_macro)]
- impl LintPass for $name {
+ impl $crate::LintPass for $name {
fn name(&self) -> &'static str {
panic!()
}
@@ -140,42 +135,45 @@ macro_rules! declare_combined_late_lint_pass {
macro_rules! early_lint_methods {
($macro:path, $args:tt) => (
$macro!($args, [
- fn check_param(a: &ast::Param);
- fn check_ident(a: Ident);
- fn check_crate(a: &ast::Crate);
- fn check_crate_post(a: &ast::Crate);
- fn check_item(a: &ast::Item);
- fn check_item_post(a: &ast::Item);
- fn check_local(a: &ast::Local);
- fn check_block(a: &ast::Block);
- fn check_stmt(a: &ast::Stmt);
- fn check_arm(a: &ast::Arm);
- fn check_pat(a: &ast::Pat);
- fn check_pat_post(a: &ast::Pat);
- fn check_expr(a: &ast::Expr);
- fn check_expr_post(a: &ast::Expr);
- fn check_ty(a: &ast::Ty);
- fn check_generic_arg(a: &ast::GenericArg);
- fn check_generic_param(a: &ast::GenericParam);
- fn check_generics(a: &ast::Generics);
- fn check_poly_trait_ref(a: &ast::PolyTraitRef);
- fn check_fn(a: rustc_ast::visit::FnKind<'_>, c: Span, d_: ast::NodeId);
- fn check_trait_item(a: &ast::AssocItem);
- fn check_impl_item(a: &ast::AssocItem);
- fn check_variant(a: &ast::Variant);
- fn check_attribute(a: &ast::Attribute);
- fn check_mac_def(a: &ast::MacroDef);
- fn check_mac(a: &ast::MacCall);
+ fn check_param(a: &rustc_ast::Param);
+ fn check_ident(a: rustc_span::symbol::Ident);
+ fn check_crate(a: &rustc_ast::Crate);
+ fn check_crate_post(a: &rustc_ast::Crate);
+ fn check_item(a: &rustc_ast::Item);
+ fn check_item_post(a: &rustc_ast::Item);
+ fn check_local(a: &rustc_ast::Local);
+ fn check_block(a: &rustc_ast::Block);
+ fn check_stmt(a: &rustc_ast::Stmt);
+ fn check_arm(a: &rustc_ast::Arm);
+ fn check_pat(a: &rustc_ast::Pat);
+ fn check_pat_post(a: &rustc_ast::Pat);
+ fn check_expr(a: &rustc_ast::Expr);
+ fn check_expr_post(a: &rustc_ast::Expr);
+ fn check_ty(a: &rustc_ast::Ty);
+ fn check_generic_arg(a: &rustc_ast::GenericArg);
+ fn check_generic_param(a: &rustc_ast::GenericParam);
+ fn check_generics(a: &rustc_ast::Generics);
+ fn check_poly_trait_ref(a: &rustc_ast::PolyTraitRef);
+ fn check_fn(
+ a: rustc_ast::visit::FnKind<'_>,
+ c: rustc_span::Span,
+ d_: rustc_ast::NodeId);
+ fn check_trait_item(a: &rustc_ast::AssocItem);
+ fn check_impl_item(a: &rustc_ast::AssocItem);
+ fn check_variant(a: &rustc_ast::Variant);
+ fn check_attribute(a: &rustc_ast::Attribute);
+ fn check_mac_def(a: &rustc_ast::MacroDef);
+ fn check_mac(a: &rustc_ast::MacCall);
/// Called when entering a syntax node that can have lint attributes such
/// as `#[allow(...)]`. Called with *all* the attributes of that node.
- fn enter_lint_attrs(a: &[ast::Attribute]);
+ fn enter_lint_attrs(a: &[rustc_ast::Attribute]);
/// Counterpart to `enter_lint_attrs`.
- fn exit_lint_attrs(a: &[ast::Attribute]);
+ fn exit_lint_attrs(a: &[rustc_ast::Attribute]);
- fn enter_where_predicate(a: &ast::WherePredicate);
- fn exit_where_predicate(a: &ast::WherePredicate);
+ fn enter_where_predicate(a: &rustc_ast::WherePredicate);
+ fn exit_where_predicate(a: &rustc_ast::WherePredicate);
]);
)
}
@@ -202,8 +200,8 @@ macro_rules! expand_combined_early_lint_pass_method {
#[macro_export]
macro_rules! expand_combined_early_lint_pass_methods {
($passes:tt, [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
- $(fn $name(&mut self, context: &EarlyContext<'_>, $($param: $arg),*) {
- expand_combined_early_lint_pass_method!($passes, self, $name, (context, $($param),*));
+ $(fn $name(&mut self, context: &$crate::EarlyContext<'_>, $($param: $arg),*) {
+ $crate::expand_combined_early_lint_pass_method!($passes, self, $name, (context, $($param),*));
})*
)
}
@@ -228,19 +226,19 @@ macro_rules! declare_combined_early_lint_pass {
}
}
- $v fn get_lints() -> LintArray {
+ $v fn get_lints() -> $crate::LintArray {
let mut lints = Vec::new();
$(lints.extend_from_slice(&$pass::get_lints());)*
lints
}
}
- impl EarlyLintPass for $name {
- expand_combined_early_lint_pass_methods!([$($pass),*], $methods);
+ impl $crate::EarlyLintPass for $name {
+ $crate::expand_combined_early_lint_pass_methods!([$($pass),*], $methods);
}
#[allow(rustc::lint_pass_impl_without_macro)]
- impl LintPass for $name {
+ impl $crate::LintPass for $name {
fn name(&self) -> &'static str {
panic!()
}
diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs
index 8f651b2a2db..201926fee3e 100644
--- a/compiler/rustc_middle/src/mir/syntax.rs
+++ b/compiler/rustc_middle/src/mir/syntax.rs
@@ -1333,7 +1333,7 @@ pub enum AggregateKind<'tcx> {
Generator(DefId, GenericArgsRef<'tcx>, hir::Movability),
}
-#[derive(Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
+#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
pub enum NullOp<'tcx> {
/// Returns the size of a value of that type
SizeOf,
diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs
index 8c39614903c..89934e4350e 100644
--- a/compiler/rustc_middle/src/thir.rs
+++ b/compiler/rustc_middle/src/thir.rs
@@ -732,12 +732,16 @@ pub enum PatKind<'tcx> {
},
/// One of the following:
- /// * `&str`, which will be handled as a string pattern and thus exhaustiveness
- /// checking will detect if you use the same string twice in different patterns.
- /// * integer, bool, char or float, which will be handled by exhaustiveness to cover exactly
- /// its own value, similar to `&str`, but these values are much simpler.
- /// * Opaque constants, that must not be matched structurally. So anything that does not derive
- /// `PartialEq` and `Eq`.
+ /// * `&str` (represented as a valtree), which will be handled as a string pattern and thus
+ /// exhaustiveness checking will detect if you use the same string twice in different
+ /// patterns.
+ /// * integer, bool, char or float (represented as a valtree), which will be handled by
+ /// exhaustiveness to cover exactly its own value, similar to `&str`, but these values are
+ /// much simpler.
+ /// * Opaque constants (represented as `mir::ConstValue`), that must not be matched
+ /// structurally. So anything that does not derive `PartialEq` and `Eq`.
+ ///
+ /// These are always compared with the matched place using (the semantics of) `PartialEq`.
Constant {
value: mir::Const<'tcx>,
},
diff --git a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
index 4758ace73b6..ae442466029 100644
--- a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
+++ b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
@@ -24,6 +24,8 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
/// Converts an evaluated constant to a pattern (if possible).
/// This means aggregate values (like structs and enums) are converted
/// to a pattern that matches the value (as if you'd compared via structural equality).
+ ///
+ /// `cv` must be a valtree or a `mir::ConstValue`.
#[instrument(level = "debug", skip(self), ret)]
pub(super) fn const_to_pat(
&self,
@@ -64,12 +66,10 @@ struct ConstToPat<'tcx> {
}
/// This error type signals that we encountered a non-struct-eq situation.
-/// We bubble this up in order to get back to the reference destructuring and make that emit
-/// a const pattern instead of a deref pattern. This allows us to simply call `PartialEq::eq`
-/// on such patterns (since that function takes a reference) and not have to jump through any
-/// hoops to get a reference to the value.
+/// We will fall back to calling `PartialEq::eq` on such patterns,
+/// and exhaustiveness checking will consider them as matching nothing.
#[derive(Debug)]
-struct FallbackToConstRef;
+struct FallbackToOpaqueConst;
impl<'tcx> ConstToPat<'tcx> {
fn new(
@@ -136,7 +136,7 @@ impl<'tcx> ConstToPat<'tcx> {
}
ty::ConstKind::Value(valtree) => self
.recur(valtree, cv.ty(), mir_structural_match_violation.unwrap_or(false))
- .unwrap_or_else(|_| {
+ .unwrap_or_else(|_: FallbackToOpaqueConst| {
Box::new(Pat {
span: self.span,
ty: cv.ty(),
@@ -285,7 +285,7 @@ impl<'tcx> ConstToPat<'tcx> {
fn field_pats(
&self,
vals: impl Iterator- , Ty<'tcx>)>,
- ) -> Result>, FallbackToConstRef> {
+ ) -> Result>, FallbackToOpaqueConst> {
vals.enumerate()
.map(|(idx, (val, ty))| {
let field = FieldIdx::new(idx);
@@ -303,7 +303,7 @@ impl<'tcx> ConstToPat<'tcx> {
cv: ValTree<'tcx>,
ty: Ty<'tcx>,
mir_structural_match_violation: bool,
- ) -> Result>, FallbackToConstRef> {
+ ) -> Result>, FallbackToOpaqueConst> {
let id = self.id;
let span = self.span;
let tcx = self.tcx();
@@ -318,7 +318,7 @@ impl<'tcx> ConstToPat<'tcx> {
span,
FloatPattern,
);
- return Err(FallbackToConstRef);
+ return Err(FallbackToOpaqueConst);
}
// If the type is not structurally comparable, just emit the constant directly,
// causing the pattern match code to treat it opaquely.
@@ -342,11 +342,12 @@ impl<'tcx> ConstToPat<'tcx> {
// Since we are behind a reference, we can just bubble the error up so we get a
// constant at reference type, making it easy to let the fallback call
// `PartialEq::eq` on it.
- return Err(FallbackToConstRef);
+ return Err(FallbackToOpaqueConst);
}
ty::FnDef(..) => {
self.saw_const_match_error.set(true);
tcx.sess.emit_err(InvalidPattern { span, non_sm_ty: ty });
+ // We errored, so the pattern we generate is irrelevant.
PatKind::Wild
}
ty::Adt(adt_def, _) if !self.type_marked_structural(ty) => {
@@ -354,6 +355,7 @@ impl<'tcx> ConstToPat<'tcx> {
self.saw_const_match_error.set(true);
let err = TypeNotStructural { span, non_sm_ty: ty };
tcx.sess.emit_err(err);
+ // We errored, so the pattern we generate is irrelevant.
PatKind::Wild
}
ty::Adt(adt_def, args) if adt_def.is_enum() => {
@@ -423,13 +425,15 @@ impl<'tcx> ConstToPat<'tcx> {
IndirectStructuralMatch { non_sm_ty: *pointee_ty },
);
}
- return Err(FallbackToConstRef);
+ return Err(FallbackToOpaqueConst);
} else {
if !self.saw_const_match_error.get() {
self.saw_const_match_error.set(true);
let err = TypeNotStructural { span, non_sm_ty: *pointee_ty };
tcx.sess.emit_err(err);
}
+ tcx.sess.delay_span_bug(span, "`saw_const_match_error` set but no error?");
+ // We errored, so the pattern we generate is irrelevant.
PatKind::Wild
}
}
@@ -442,6 +446,7 @@ impl<'tcx> ConstToPat<'tcx> {
tcx.sess.emit_err(err);
// FIXME: introduce PatKind::Error to silence follow up diagnostics due to unreachable patterns.
+ // We errored, so the pattern we generate is irrelevant.
PatKind::Wild
} else {
let old = self.behind_reference.replace(true);
@@ -472,6 +477,7 @@ impl<'tcx> ConstToPat<'tcx> {
self.saw_const_match_error.set(true);
let err = InvalidPattern { span, non_sm_ty: ty };
tcx.sess.emit_err(err);
+ // We errored, so the pattern we generate is irrelevant.
PatKind::Wild
}
};
diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs
new file mode 100644
index 00000000000..449bade3322
--- /dev/null
+++ b/compiler/rustc_mir_transform/src/gvn.rs
@@ -0,0 +1,538 @@
+//! Global value numbering.
+//!
+//! MIR may contain repeated and/or redundant computations. The objective of this pass is to detect
+//! such redundancies and re-use the already-computed result when possible.
+//!
+//! In a first pass, we compute a symbolic representation of values that are assigned to SSA
+//! locals. This symbolic representation is defined by the `Value` enum. Each produced instance of
+//! `Value` is interned as a `VnIndex`, which allows us to cheaply compute identical values.
+//!
+//! From those assignments, we construct a mapping `VnIndex -> Vec<(Local, Location)>` of available
+//! values, the locals in which they are stored, and a the assignment location.
+//!
+//! In a second pass, we traverse all (non SSA) assignments `x = rvalue` and operands. For each
+//! one, we compute the `VnIndex` of the rvalue. If this `VnIndex` is associated to a constant, we
+//! replace the rvalue/operand by that constant. Otherwise, if there is an SSA local `y`
+//! associated to this `VnIndex`, and if its definition location strictly dominates the assignment
+//! to `x`, we replace the assignment by `x = y`.
+//!
+//! By opportunity, this pass simplifies some `Rvalue`s based on the accumulated knowledge.
+//!
+//! # Operational semantic
+//!
+//! Operationally, this pass attempts to prove bitwise equality between locals. Given this MIR:
+//! ```ignore (MIR)
+//! _a = some value // has VnIndex i
+//! // some MIR
+//! _b = some other value // also has VnIndex i
+//! ```
+//!
+//! We consider it to be replacable by:
+//! ```ignore (MIR)
+//! _a = some value // has VnIndex i
+//! // some MIR
+//! _c = some other value // also has VnIndex i
+//! assume(_a bitwise equal to _c) // follows from having the same VnIndex
+//! _b = _a // follows from the `assume`
+//! ```
+//!
+//! Which is simplifiable to:
+//! ```ignore (MIR)
+//! _a = some value // has VnIndex i
+//! // some MIR
+//! _b = _a
+//! ```
+//!
+//! # Handling of references
+//!
+//! We handle references by assigning a different "provenance" index to each Ref/AddressOf rvalue.
+//! This ensure that we do not spuriously merge borrows that should not be merged. Meanwhile, we
+//! consider all the derefs of an immutable reference to a freeze type to give the same value:
+//! ```ignore (MIR)
+//! _a = *_b // _b is &Freeze
+//! _c = *_b // replaced by _c = _a
+//! ```
+
+use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
+use rustc_data_structures::graph::dominators::Dominators;
+use rustc_index::bit_set::BitSet;
+use rustc_index::IndexVec;
+use rustc_macros::newtype_index;
+use rustc_middle::mir::visit::*;
+use rustc_middle::mir::*;
+use rustc_middle::ty::{self, Ty, TyCtxt};
+use rustc_target::abi::{VariantIdx, FIRST_VARIANT};
+
+use crate::ssa::SsaLocals;
+use crate::MirPass;
+
+pub struct GVN;
+
+impl<'tcx> MirPass<'tcx> for GVN {
+ fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
+ sess.mir_opt_level() >= 4
+ }
+
+ #[instrument(level = "trace", skip(self, tcx, body))]
+ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
+ debug!(def_id = ?body.source.def_id());
+ propagate_ssa(tcx, body);
+ }
+}
+
+fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
+ let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
+ let ssa = SsaLocals::new(body);
+ // Clone dominators as we need them while mutating the body.
+ let dominators = body.basic_blocks.dominators().clone();
+
+ let mut state = VnState::new(tcx, param_env, &ssa, &dominators, &body.local_decls);
+ for arg in body.args_iter() {
+ if ssa.is_ssa(arg) {
+ let value = state.new_opaque().unwrap();
+ state.assign(arg, value);
+ }
+ }
+
+ ssa.for_each_assignment_mut(&mut body.basic_blocks, |local, rvalue, location| {
+ let value = state.simplify_rvalue(rvalue, location).or_else(|| state.new_opaque()).unwrap();
+ // FIXME(#112651) `rvalue` may have a subtype to `local`. We can only mark `local` as
+ // reusable if we have an exact type match.
+ if state.local_decls[local].ty == rvalue.ty(state.local_decls, tcx) {
+ state.assign(local, value);
+ }
+ });
+
+ // Stop creating opaques during replacement as it is useless.
+ state.next_opaque = None;
+
+ let reverse_postorder = body.basic_blocks.reverse_postorder().to_vec();
+ for bb in reverse_postorder {
+ let data = &mut body.basic_blocks.as_mut_preserves_cfg()[bb];
+ state.visit_basic_block_data(bb, data);
+ }
+ let any_replacement = state.any_replacement;
+
+ // For each local that is reused (`y` above), we remove its storage statements do avoid any
+ // difficulty. Those locals are SSA, so should be easy to optimize by LLVM without storage
+ // statements.
+ StorageRemover { tcx, reused_locals: state.reused_locals }.visit_body_preserves_cfg(body);
+
+ if any_replacement {
+ crate::simplify::remove_unused_definitions(body);
+ }
+}
+
+newtype_index! {
+ struct VnIndex {}
+}
+
+#[derive(Debug, PartialEq, Eq, Hash)]
+enum Value<'tcx> {
+ // Root values.
+ /// Used to represent values we know nothing about.
+ /// The `usize` is a counter incremented by `new_opaque`.
+ Opaque(usize),
+ /// Evaluated or unevaluated constant value.
+ Constant(Const<'tcx>),
+ /// An aggregate value, either tuple/closure/struct/enum.
+ /// This does not contain unions, as we cannot reason with the value.
+ Aggregate(Ty<'tcx>, VariantIdx, Vec),
+ /// This corresponds to a `[value; count]` expression.
+ Repeat(VnIndex, ty::Const<'tcx>),
+ /// The address of a place.
+ Address {
+ place: Place<'tcx>,
+ /// Give each borrow and pointer a different provenance, so we don't merge them.
+ provenance: usize,
+ },
+
+ // Extractions.
+ /// This is the *value* obtained by projecting another value.
+ Projection(VnIndex, ProjectionElem>),
+ /// Discriminant of the given value.
+ Discriminant(VnIndex),
+ /// Length of an array or slice.
+ Len(VnIndex),
+
+ // Operations.
+ NullaryOp(NullOp<'tcx>, Ty<'tcx>),
+ UnaryOp(UnOp, VnIndex),
+ BinaryOp(BinOp, VnIndex, VnIndex),
+ CheckedBinaryOp(BinOp, VnIndex, VnIndex),
+ Cast {
+ kind: CastKind,
+ value: VnIndex,
+ from: Ty<'tcx>,
+ to: Ty<'tcx>,
+ },
+}
+
+struct VnState<'body, 'tcx> {
+ tcx: TyCtxt<'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
+ local_decls: &'body LocalDecls<'tcx>,
+ /// Value stored in each local.
+ locals: IndexVec>,
+ /// First local to be assigned that value.
+ rev_locals: FxHashMap>,
+ values: FxIndexSet>,
+ /// Counter to generate different values.
+ /// This is an option to stop creating opaques during replacement.
+ next_opaque: Option,
+ ssa: &'body SsaLocals,
+ dominators: &'body Dominators,
+ reused_locals: BitSet,
+ any_replacement: bool,
+}
+
+impl<'body, 'tcx> VnState<'body, 'tcx> {
+ fn new(
+ tcx: TyCtxt<'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
+ ssa: &'body SsaLocals,
+ dominators: &'body Dominators,
+ local_decls: &'body LocalDecls<'tcx>,
+ ) -> Self {
+ VnState {
+ tcx,
+ param_env,
+ local_decls,
+ locals: IndexVec::from_elem(None, local_decls),
+ rev_locals: FxHashMap::default(),
+ values: FxIndexSet::default(),
+ next_opaque: Some(0),
+ ssa,
+ dominators,
+ reused_locals: BitSet::new_empty(local_decls.len()),
+ any_replacement: false,
+ }
+ }
+
+ #[instrument(level = "trace", skip(self), ret)]
+ fn insert(&mut self, value: Value<'tcx>) -> VnIndex {
+ let (index, _) = self.values.insert_full(value);
+ VnIndex::from_usize(index)
+ }
+
+ /// Create a new `Value` for which we have no information at all, except that it is distinct
+ /// from all the others.
+ #[instrument(level = "trace", skip(self), ret)]
+ fn new_opaque(&mut self) -> Option {
+ let next_opaque = self.next_opaque.as_mut()?;
+ let value = Value::Opaque(*next_opaque);
+ *next_opaque += 1;
+ Some(self.insert(value))
+ }
+
+ /// Create a new `Value::Address` distinct from all the others.
+ #[instrument(level = "trace", skip(self), ret)]
+ fn new_pointer(&mut self, place: Place<'tcx>) -> Option {
+ let next_opaque = self.next_opaque.as_mut()?;
+ let value = Value::Address { place, provenance: *next_opaque };
+ *next_opaque += 1;
+ Some(self.insert(value))
+ }
+
+ fn get(&self, index: VnIndex) -> &Value<'tcx> {
+ self.values.get_index(index.as_usize()).unwrap()
+ }
+
+ /// Record that `local` is assigned `value`. `local` must be SSA.
+ #[instrument(level = "trace", skip(self))]
+ fn assign(&mut self, local: Local, value: VnIndex) {
+ self.locals[local] = Some(value);
+
+ // Only register the value if its type is `Sized`, as we will emit copies of it.
+ let is_sized = !self.tcx.features().unsized_locals
+ || self.local_decls[local].ty.is_sized(self.tcx, self.param_env);
+ if is_sized {
+ self.rev_locals.entry(value).or_default().push(local);
+ }
+ }
+
+ /// Represent the *value* which would be read from `place`, and point `place` to a preexisting
+ /// place with the same value (if that already exists).
+ #[instrument(level = "trace", skip(self), ret)]
+ fn simplify_place_value(
+ &mut self,
+ place: &mut Place<'tcx>,
+ location: Location,
+ ) -> Option {
+ // Invariant: `place` and `place_ref` point to the same value, even if they point to
+ // different memory locations.
+ let mut place_ref = place.as_ref();
+
+ // Invariant: `value` holds the value up-to the `index`th projection excluded.
+ let mut value = self.locals[place.local]?;
+ for (index, proj) in place.projection.iter().enumerate() {
+ if let Some(local) = self.try_as_local(value, location) {
+ // Both `local` and `Place { local: place.local, projection: projection[..index] }`
+ // hold the same value. Therefore, following place holds the value in the original
+ // `place`.
+ place_ref = PlaceRef { local, projection: &place.projection[index..] };
+ }
+
+ let proj = match proj {
+ ProjectionElem::Deref => {
+ let ty = Place::ty_from(
+ place.local,
+ &place.projection[..index],
+ self.local_decls,
+ self.tcx,
+ )
+ .ty;
+ if let Some(Mutability::Not) = ty.ref_mutability()
+ && let Some(pointee_ty) = ty.builtin_deref(true)
+ && pointee_ty.ty.is_freeze(self.tcx, self.param_env)
+ {
+ // An immutable borrow `_x` always points to the same value for the
+ // lifetime of the borrow, so we can merge all instances of `*_x`.
+ ProjectionElem::Deref
+ } else {
+ return None;
+ }
+ }
+ ProjectionElem::Field(f, ty) => ProjectionElem::Field(f, ty),
+ ProjectionElem::Index(idx) => {
+ let idx = self.locals[idx]?;
+ ProjectionElem::Index(idx)
+ }
+ ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
+ ProjectionElem::ConstantIndex { offset, min_length, from_end }
+ }
+ ProjectionElem::Subslice { from, to, from_end } => {
+ ProjectionElem::Subslice { from, to, from_end }
+ }
+ ProjectionElem::Downcast(name, index) => ProjectionElem::Downcast(name, index),
+ ProjectionElem::OpaqueCast(ty) => ProjectionElem::OpaqueCast(ty),
+ };
+ value = self.insert(Value::Projection(value, proj));
+ }
+
+ if let Some(local) = self.try_as_local(value, location)
+ && local != place.local // in case we had no projection to begin with.
+ {
+ *place = local.into();
+ self.reused_locals.insert(local);
+ self.any_replacement = true;
+ } else if place_ref.local != place.local
+ || place_ref.projection.len() < place.projection.len()
+ {
+ // By the invariant on `place_ref`.
+ *place = place_ref.project_deeper(&[], self.tcx);
+ self.reused_locals.insert(place_ref.local);
+ self.any_replacement = true;
+ }
+
+ Some(value)
+ }
+
+ #[instrument(level = "trace", skip(self), ret)]
+ fn simplify_operand(
+ &mut self,
+ operand: &mut Operand<'tcx>,
+ location: Location,
+ ) -> Option {
+ match *operand {
+ Operand::Constant(ref constant) => Some(self.insert(Value::Constant(constant.const_))),
+ Operand::Copy(ref mut place) | Operand::Move(ref mut place) => {
+ let value = self.simplify_place_value(place, location)?;
+ if let Some(const_) = self.try_as_constant(value) {
+ *operand = Operand::Constant(Box::new(const_));
+ self.any_replacement = true;
+ }
+ Some(value)
+ }
+ }
+ }
+
+ #[instrument(level = "trace", skip(self), ret)]
+ fn simplify_rvalue(
+ &mut self,
+ rvalue: &mut Rvalue<'tcx>,
+ location: Location,
+ ) -> Option {
+ let value = match *rvalue {
+ // Forward values.
+ Rvalue::Use(ref mut operand) => return self.simplify_operand(operand, location),
+ Rvalue::CopyForDeref(place) => {
+ let mut operand = Operand::Copy(place);
+ let val = self.simplify_operand(&mut operand, location);
+ *rvalue = Rvalue::Use(operand);
+ return val;
+ }
+
+ // Roots.
+ Rvalue::Repeat(ref mut op, amount) => {
+ let op = self.simplify_operand(op, location)?;
+ Value::Repeat(op, amount)
+ }
+ Rvalue::NullaryOp(op, ty) => Value::NullaryOp(op, ty),
+ Rvalue::Aggregate(box ref kind, ref mut fields) => {
+ let variant_index = match *kind {
+ AggregateKind::Array(..)
+ | AggregateKind::Tuple
+ | AggregateKind::Closure(..)
+ | AggregateKind::Generator(..) => FIRST_VARIANT,
+ AggregateKind::Adt(_, variant_index, _, _, None) => variant_index,
+ // Do not track unions.
+ AggregateKind::Adt(_, _, _, _, Some(_)) => return None,
+ };
+ let fields: Option> = fields
+ .iter_mut()
+ .map(|op| self.simplify_operand(op, location).or_else(|| self.new_opaque()))
+ .collect();
+ let ty = rvalue.ty(self.local_decls, self.tcx);
+ Value::Aggregate(ty, variant_index, fields?)
+ }
+ Rvalue::Ref(.., place) | Rvalue::AddressOf(_, place) => return self.new_pointer(place),
+
+ // Operations.
+ Rvalue::Len(ref mut place) => {
+ let place = self.simplify_place_value(place, location)?;
+ Value::Len(place)
+ }
+ Rvalue::Cast(kind, ref mut value, to) => {
+ let from = value.ty(self.local_decls, self.tcx);
+ let value = self.simplify_operand(value, location)?;
+ Value::Cast { kind, value, from, to }
+ }
+ Rvalue::BinaryOp(op, box (ref mut lhs, ref mut rhs)) => {
+ let lhs = self.simplify_operand(lhs, location);
+ let rhs = self.simplify_operand(rhs, location);
+ Value::BinaryOp(op, lhs?, rhs?)
+ }
+ Rvalue::CheckedBinaryOp(op, box (ref mut lhs, ref mut rhs)) => {
+ let lhs = self.simplify_operand(lhs, location);
+ let rhs = self.simplify_operand(rhs, location);
+ Value::CheckedBinaryOp(op, lhs?, rhs?)
+ }
+ Rvalue::UnaryOp(op, ref mut arg) => {
+ let arg = self.simplify_operand(arg, location)?;
+ Value::UnaryOp(op, arg)
+ }
+ Rvalue::Discriminant(ref mut place) => {
+ let place = self.simplify_place_value(place, location)?;
+ Value::Discriminant(place)
+ }
+
+ // Unsupported values.
+ Rvalue::ThreadLocalRef(..) | Rvalue::ShallowInitBox(..) => return None,
+ };
+ debug!(?value);
+ Some(self.insert(value))
+ }
+}
+
+impl<'tcx> VnState<'_, 'tcx> {
+ /// If `index` is a `Value::Constant`, return the `Constant` to be put in the MIR.
+ fn try_as_constant(&mut self, index: VnIndex) -> Option> {
+ if let Value::Constant(const_) = *self.get(index) {
+ // Some constants may contain pointers. We need to preserve the provenance of these
+ // pointers, but not all constants guarantee this:
+ // - valtrees purposefully do not;
+ // - ConstValue::Slice does not either.
+ match const_ {
+ Const::Ty(c) => match c.kind() {
+ ty::ConstKind::Value(valtree) => match valtree {
+ // This is just an integer, keep it.
+ ty::ValTree::Leaf(_) => {}
+ ty::ValTree::Branch(_) => return None,
+ },
+ ty::ConstKind::Param(..)
+ | ty::ConstKind::Unevaluated(..)
+ | ty::ConstKind::Expr(..) => {}
+ // Should not appear in runtime MIR.
+ ty::ConstKind::Infer(..)
+ | ty::ConstKind::Bound(..)
+ | ty::ConstKind::Placeholder(..)
+ | ty::ConstKind::Error(..) => bug!(),
+ },
+ Const::Unevaluated(..) => {}
+ // If the same slice appears twice in the MIR, we cannot guarantee that we will
+ // give the same `AllocId` to the data.
+ Const::Val(ConstValue::Slice { .. }, _) => return None,
+ Const::Val(
+ ConstValue::ZeroSized | ConstValue::Scalar(_) | ConstValue::Indirect { .. },
+ _,
+ ) => {}
+ }
+ Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_ })
+ } else {
+ None
+ }
+ }
+
+ /// If there is a local which is assigned `index`, and its assignment strictly dominates `loc`,
+ /// return it.
+ fn try_as_local(&mut self, index: VnIndex, loc: Location) -> Option {
+ let other = self.rev_locals.get(&index)?;
+ other
+ .iter()
+ .copied()
+ .find(|&other| self.ssa.assignment_dominates(self.dominators, other, loc))
+ }
+}
+
+impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> {
+ fn tcx(&self) -> TyCtxt<'tcx> {
+ self.tcx
+ }
+
+ fn visit_operand(&mut self, operand: &mut Operand<'tcx>, location: Location) {
+ self.simplify_operand(operand, location);
+ }
+
+ fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, location: Location) {
+ self.super_statement(stmt, location);
+ if let StatementKind::Assign(box (_, ref mut rvalue)) = stmt.kind
+ // Do not try to simplify a constant, it's already in canonical shape.
+ && !matches!(rvalue, Rvalue::Use(Operand::Constant(_)))
+ && let Some(value) = self.simplify_rvalue(rvalue, location)
+ {
+ if let Some(const_) = self.try_as_constant(value) {
+ *rvalue = Rvalue::Use(Operand::Constant(Box::new(const_)));
+ self.any_replacement = true;
+ } else if let Some(local) = self.try_as_local(value, location)
+ && *rvalue != Rvalue::Use(Operand::Move(local.into()))
+ {
+ *rvalue = Rvalue::Use(Operand::Copy(local.into()));
+ self.reused_locals.insert(local);
+ self.any_replacement = true;
+ }
+ }
+ }
+}
+
+struct StorageRemover<'tcx> {
+ tcx: TyCtxt<'tcx>,
+ reused_locals: BitSet,
+}
+
+impl<'tcx> MutVisitor<'tcx> for StorageRemover<'tcx> {
+ fn tcx(&self) -> TyCtxt<'tcx> {
+ self.tcx
+ }
+
+ fn visit_operand(&mut self, operand: &mut Operand<'tcx>, _: Location) {
+ if let Operand::Move(place) = *operand
+ && let Some(local) = place.as_local()
+ && self.reused_locals.contains(local)
+ {
+ *operand = Operand::Copy(place);
+ }
+ }
+
+ fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, loc: Location) {
+ match stmt.kind {
+ // When removing storage statements, we need to remove both (#107511).
+ StatementKind::StorageLive(l) | StatementKind::StorageDead(l)
+ if self.reused_locals.contains(l) =>
+ {
+ stmt.make_nop()
+ }
+ _ => self.super_statement(stmt, loc),
+ }
+ }
+}
diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs
index d7fef093278..9e4bc456d51 100644
--- a/compiler/rustc_mir_transform/src/lib.rs
+++ b/compiler/rustc_mir_transform/src/lib.rs
@@ -76,6 +76,7 @@ mod errors;
mod ffi_unwind_calls;
mod function_item_references;
mod generator;
+mod gvn;
pub mod inline;
mod instsimplify;
mod large_enums;
@@ -549,6 +550,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
// latter pass will leverage the created opportunities.
&separate_const_switch::SeparateConstSwitch,
&const_prop::ConstProp,
+ &gvn::GVN,
&dataflow_const_prop::DataflowConstProp,
//
// Const-prop runs unconditionally, but doesn't mutate the MIR at mir-opt-level=0.
diff --git a/compiler/rustc_mir_transform/src/ref_prop.rs b/compiler/rustc_mir_transform/src/ref_prop.rs
index 49a940b5779..67941cf4395 100644
--- a/compiler/rustc_mir_transform/src/ref_prop.rs
+++ b/compiler/rustc_mir_transform/src/ref_prop.rs
@@ -108,7 +108,7 @@ enum Value<'tcx> {
}
/// For each local, save the place corresponding to `*local`.
-#[instrument(level = "trace", skip(tcx, body))]
+#[instrument(level = "trace", skip(tcx, body, ssa))]
fn compute_replacement<'tcx>(
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
diff --git a/compiler/rustc_mir_transform/src/ssa.rs b/compiler/rustc_mir_transform/src/ssa.rs
index 04bc461c815..3a675752fba 100644
--- a/compiler/rustc_mir_transform/src/ssa.rs
+++ b/compiler/rustc_mir_transform/src/ssa.rs
@@ -13,7 +13,6 @@ use rustc_middle::middle::resolve_bound_vars::Set1;
use rustc_middle::mir::visit::*;
use rustc_middle::mir::*;
-#[derive(Debug)]
pub struct SsaLocals {
/// Assignments to each local. This defines whether the local is SSA.
assignments: IndexVec>,
@@ -129,6 +128,25 @@ impl SsaLocals {
self.direct_uses[local]
}
+ pub fn assignment_dominates(
+ &self,
+ dominators: &Dominators,
+ local: Local,
+ location: Location,
+ ) -> bool {
+ match self.assignments[local] {
+ Set1::One(LocationExtended::Arg) => true,
+ Set1::One(LocationExtended::Plain(ass)) => {
+ if ass.block == location.block {
+ ass.statement_index < location.statement_index
+ } else {
+ dominators.dominates(ass.block, location.block)
+ }
+ }
+ _ => false,
+ }
+ }
+
pub fn assignments<'a, 'tcx>(
&'a self,
body: &'a Body<'tcx>,
@@ -146,6 +164,24 @@ impl SsaLocals {
})
}
+ pub fn for_each_assignment_mut<'tcx>(
+ &self,
+ basic_blocks: &mut BasicBlocks<'tcx>,
+ mut f: impl FnMut(Local, &mut Rvalue<'tcx>, Location),
+ ) {
+ for &local in &self.assignment_order {
+ if let Set1::One(LocationExtended::Plain(loc)) = self.assignments[local] {
+ // `loc` must point to a direct assignment to `local`.
+ let bbs = basic_blocks.as_mut_preserves_cfg();
+ let bb = &mut bbs[loc.block];
+ let stmt = &mut bb.statements[loc.statement_index];
+ let StatementKind::Assign(box (target, ref mut rvalue)) = stmt.kind else { bug!() };
+ assert_eq!(target.as_local(), Some(local));
+ f(local, rvalue, loc)
+ }
+ }
+ }
+
/// Compute the equivalence classes for locals, based on copy statements.
///
/// The returned vector maps each local to the one it copies. In the following case:
diff --git a/src/doc/style-guide/src/items.md b/src/doc/style-guide/src/items.md
index a6d941f6d04..b215de6ad28 100644
--- a/src/doc/style-guide/src/items.md
+++ b/src/doc/style-guide/src/items.md
@@ -367,26 +367,52 @@ where
## Type aliases
Keep type aliases on one line when they fit. If necessary to break the line, do
-so after the `=`, and block-indent the right-hand side:
+so before the `=`, and block-indent the right-hand side:
```rust
pub type Foo = Bar;
// If multi-line is required
-type VeryLongType =
- AnEvenLongerType>;
+type VeryLongType
+ = AnEvenLongerType>;
```
-Where possible avoid `where` clauses and keep type constraints inline. Where
-that is not possible split the line before and after the `where` clause (and
-split the `where` clause as normal), e.g.,
+When there is a trailing `where` clause after the type, and no `where` clause
+present before the type, break before the `=` and indent. Then break before the
+`where` keyword and format the clauses normally, e.g.,
```rust
+// With only a trailing where clause
type VeryLongType
+ = AnEvenLongerType>
+where
+ T: U::AnAssociatedType,
+ U: SomeBound;
+```
+
+When there is a `where` clause before the type, format it normally, and break
+after the last clause. Do not indent before the `=` to leave it visually
+distinct from the indented clauses that precede it. If there is additionally a
+`where` clause after the type, break before the `where` keyword and format the
+clauses normally.
+
+```rust
+// With only a preceding where clause.
+type WithPrecedingWC
where
T: U::AnAssociatedType,
U: SomeBound,
= AnEvenLongerType>;
+
+// Or with both a preceding and trailing where clause.
+type WithPrecedingWC
+where
+ T: U::AnAssociatedType,
+ U: SomeBound,
+= AnEvenLongerType>
+where
+ T: U::AnAssociatedType2,
+ U: SomeBound2;
```
## Associated types
diff --git a/src/doc/unstable-book/src/language-features/lang-items.md b/src/doc/unstable-book/src/language-features/lang-items.md
index 9e20662fff3..32b882e763d 100644
--- a/src/doc/unstable-book/src/language-features/lang-items.md
+++ b/src/doc/unstable-book/src/language-features/lang-items.md
@@ -37,7 +37,7 @@ Most lang items are defined by `core`, but if you're trying to build
an executable without the `std` crate, you might run into the need
for lang item definitions.
-[personality]: https://github.com/rust-lang/rust/blob/master/library/std/src/personality/gcc.rs
+[personality]: https://github.com/rust-lang/rust/blob/master/library/std/src/sys/personality/gcc.rs
## Example: Implementing a `Box`
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index 6dbf2185e3d..d24e6e5faf5 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -1083,7 +1083,7 @@ impl<'a, 'tcx> TagIterator<'a, 'tcx> {
}
fn parse_in_attribute_block(&mut self) -> Option> {
- while let Some((pos, c)) = self.inner.next() {
+ if let Some((pos, c)) = self.inner.next() {
if c == '}' {
self.is_in_attribute_block = false;
return self.next();
diff --git a/src/librustdoc/html/templates/type_layout.html b/src/librustdoc/html/templates/type_layout.html
index 287cbab07d2..b8b7785a2a1 100644
--- a/src/librustdoc/html/templates/type_layout.html
+++ b/src/librustdoc/html/templates/type_layout.html
@@ -9,12 +9,12 @@
Note: Most layout information is completely {#+ #}
unstable and may even differ between compilations. {#+ #}
The only exception is types with certain
repr(...)
{#+ #}
- attributes. Please see the Rust Reference’s {#+ #}
+ attributes. Please see the Rust Reference's {#+ #}
“Type Layout” {#+ #}
chapter for details on type layout guarantees. {# #}
{# #}
{# #}
- Size: {{ type_layout_size|safe }}
{# #}
+ Size: {{+ type_layout_size|safe }}
{# #}
{% if !variants.is_empty() %}
{# #}
Size for each variant: {# #}
diff --git a/src/tools/miri/tests/pass/function_pointers.rs b/src/tools/miri/tests/pass/function_pointers.rs
index b66826e3fcd..1c99a96feda 100644
--- a/src/tools/miri/tests/pass/function_pointers.rs
+++ b/src/tools/miri/tests/pass/function_pointers.rs
@@ -23,6 +23,10 @@ fn h(i: i32, j: i32) -> i32 {
j * i * 7
}
+fn i() -> i32 {
+ 73
+}
+
fn return_fn_ptr(f: fn() -> i32) -> fn() -> i32 {
f
}
@@ -72,10 +76,18 @@ fn main() {
assert_eq!(indirect3(h), 210);
assert_eq!(indirect_mut3(h), 210);
assert_eq!(indirect_once3(h), 210);
- let g = f as fn() -> i32;
- assert!(return_fn_ptr(g) == g);
- assert!(return_fn_ptr(g) as unsafe fn() -> i32 == g as fn() -> i32 as unsafe fn() -> i32);
- assert!(return_fn_ptr(f) != f);
+ // Check that `i` always has the same address. This is not guaranteed
+ // but Miri currently uses a fixed address for monomorphic functions.
+ assert!(return_fn_ptr(i) == i);
+ assert!(return_fn_ptr(i) as unsafe fn() -> i32 == i as fn() -> i32 as unsafe fn() -> i32);
+ // We don't check anything for `f`. Miri gives it many different addresses
+ // but mir-opts can turn them into the same address.
+ let _val = return_fn_ptr(f) != f;
+ // However, if we only turn `f` into a function pointer and use that pointer,
+ // it is equal to itself.
+ let f2 = f as fn() -> i32;
+ assert!(return_fn_ptr(f2) == f2);
+ assert!(return_fn_ptr(f2) as unsafe fn() -> i32 == f2 as fn() -> i32 as unsafe fn() -> i32);
// Any non-null value is okay for function pointers.
unsafe {
diff --git a/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff b/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff
new file mode 100644
index 00000000000..3f5173c189e
--- /dev/null
+++ b/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff
@@ -0,0 +1,342 @@
+- // MIR for `arithmetic` before GVN
++ // MIR for `arithmetic` after GVN
+
+ fn arithmetic(_1: u64) -> () {
+ debug x => _1;
+ let mut _0: ();
+ let _2: ();
+ let mut _3: u64;
+ let mut _4: u64;
+ let _5: ();
+ let mut _6: u64;
+ let mut _7: u64;
+ let _8: ();
+ let mut _9: u64;
+ let mut _10: u64;
+ let _11: ();
+ let mut _12: u64;
+ let mut _13: u64;
+ let _14: ();
+ let mut _15: u64;
+ let mut _16: u64;
+ let mut _17: bool;
+ let _18: ();
+ let mut _19: u64;
+ let mut _20: u64;
+ let mut _21: bool;
+ let _22: ();
+ let mut _23: u64;
+ let mut _24: u64;
+ let mut _25: bool;
+ let _26: ();
+ let mut _27: u64;
+ let mut _28: u64;
+ let mut _29: bool;
+ let _30: ();
+ let mut _31: u64;
+ let mut _32: u64;
+ let mut _33: bool;
+ let _34: ();
+ let mut _35: u64;
+ let mut _36: u64;
+ let mut _37: bool;
+ let _38: ();
+ let mut _39: u64;
+ let mut _40: u64;
+ let mut _41: bool;
+ let _42: ();
+ let mut _43: u64;
+ let mut _44: u64;
+ let mut _45: bool;
+ let _46: ();
+ let mut _47: u64;
+ let mut _48: u64;
+ let _49: ();
+ let mut _50: u64;
+ let mut _51: u64;
+ let _52: ();
+ let mut _53: u64;
+ let mut _54: u64;
+ let _55: ();
+ let mut _56: u64;
+ let mut _57: u64;
+ let _58: ();
+ let mut _59: u64;
+ let mut _60: u64;
+
+ bb0: {
+ StorageLive(_2);
+ StorageLive(_3);
+- StorageLive(_4);
+- _4 = _1;
+- _3 = Add(move _4, const 0_u64);
+- StorageDead(_4);
++ _3 = Add(_1, const 0_u64);
+ _2 = opaque::(move _3) -> [return: bb1, unwind unreachable];
+ }
+
+ bb1: {
+ StorageDead(_3);
+ StorageDead(_2);
+ StorageLive(_5);
+ StorageLive(_6);
+- StorageLive(_7);
+- _7 = _1;
+- _6 = Sub(move _7, const 0_u64);
+- StorageDead(_7);
++ _6 = Sub(_1, const 0_u64);
+ _5 = opaque::(move _6) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
+ StorageDead(_6);
+ StorageDead(_5);
+ StorageLive(_8);
+ StorageLive(_9);
+- StorageLive(_10);
+- _10 = _1;
+- _9 = Mul(move _10, const 0_u64);
+- StorageDead(_10);
++ _9 = Mul(_1, const 0_u64);
+ _8 = opaque::(move _9) -> [return: bb3, unwind unreachable];
+ }
+
+ bb3: {
+ StorageDead(_9);
+ StorageDead(_8);
+ StorageLive(_11);
+ StorageLive(_12);
+- StorageLive(_13);
+- _13 = _1;
+- _12 = Mul(move _13, const 1_u64);
+- StorageDead(_13);
++ _12 = Mul(_1, const 1_u64);
+ _11 = opaque::(move _12) -> [return: bb4, unwind unreachable];
+ }
+
+ bb4: {
+ StorageDead(_12);
+ StorageDead(_11);
+ StorageLive(_14);
+ StorageLive(_15);
+- StorageLive(_16);
+- _16 = _1;
+ _17 = Eq(const 0_u64, const 0_u64);
+- assert(!move _17, "attempt to divide `{}` by zero", _16) -> [success: bb5, unwind unreachable];
++ assert(!_17, "attempt to divide `{}` by zero", _1) -> [success: bb5, unwind unreachable];
+ }
+
+ bb5: {
+- _15 = Div(move _16, const 0_u64);
+- StorageDead(_16);
++ _15 = Div(_1, const 0_u64);
+ _14 = opaque::(move _15) -> [return: bb6, unwind unreachable];
+ }
+
+ bb6: {
+ StorageDead(_15);
+ StorageDead(_14);
+ StorageLive(_18);
+ StorageLive(_19);
+- StorageLive(_20);
+- _20 = _1;
+ _21 = Eq(const 1_u64, const 0_u64);
+- assert(!move _21, "attempt to divide `{}` by zero", _20) -> [success: bb7, unwind unreachable];
++ assert(!_21, "attempt to divide `{}` by zero", _1) -> [success: bb7, unwind unreachable];
+ }
+
+ bb7: {
+- _19 = Div(move _20, const 1_u64);
+- StorageDead(_20);
++ _19 = Div(_1, const 1_u64);
+ _18 = opaque::(move _19) -> [return: bb8, unwind unreachable];
+ }
+
+ bb8: {
+ StorageDead(_19);
+ StorageDead(_18);
+ StorageLive(_22);
+ StorageLive(_23);
+- StorageLive(_24);
+- _24 = _1;
+- _25 = Eq(_24, const 0_u64);
+- assert(!move _25, "attempt to divide `{}` by zero", const 0_u64) -> [success: bb9, unwind unreachable];
++ _25 = Eq(_1, const 0_u64);
++ assert(!_25, "attempt to divide `{}` by zero", const 0_u64) -> [success: bb9, unwind unreachable];
+ }
+
+ bb9: {
+- _23 = Div(const 0_u64, move _24);
+- StorageDead(_24);
++ _23 = Div(const 0_u64, _1);
+ _22 = opaque::(move _23) -> [return: bb10, unwind unreachable];
+ }
+
+ bb10: {
+ StorageDead(_23);
+ StorageDead(_22);
+ StorageLive(_26);
+ StorageLive(_27);
+- StorageLive(_28);
+- _28 = _1;
+- _29 = Eq(_28, const 0_u64);
+- assert(!move _29, "attempt to divide `{}` by zero", const 1_u64) -> [success: bb11, unwind unreachable];
++ assert(!_25, "attempt to divide `{}` by zero", const 1_u64) -> [success: bb11, unwind unreachable];
+ }
+
+ bb11: {
+- _27 = Div(const 1_u64, move _28);
+- StorageDead(_28);
++ _27 = Div(const 1_u64, _1);
+ _26 = opaque::(move _27) -> [return: bb12, unwind unreachable];
+ }
+
+ bb12: {
+ StorageDead(_27);
+ StorageDead(_26);
+ StorageLive(_30);
+ StorageLive(_31);
+- StorageLive(_32);
+- _32 = _1;
+- _33 = Eq(const 0_u64, const 0_u64);
+- assert(!move _33, "attempt to calculate the remainder of `{}` with a divisor of zero", _32) -> [success: bb13, unwind unreachable];
++ assert(!_17, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb13, unwind unreachable];
+ }
+
+ bb13: {
+- _31 = Rem(move _32, const 0_u64);
+- StorageDead(_32);
++ _31 = Rem(_1, const 0_u64);
+ _30 = opaque::(move _31) -> [return: bb14, unwind unreachable];
+ }
+
+ bb14: {
+ StorageDead(_31);
+ StorageDead(_30);
+ StorageLive(_34);
+ StorageLive(_35);
+- StorageLive(_36);
+- _36 = _1;
+- _37 = Eq(const 1_u64, const 0_u64);
+- assert(!move _37, "attempt to calculate the remainder of `{}` with a divisor of zero", _36) -> [success: bb15, unwind unreachable];
++ assert(!_21, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb15, unwind unreachable];
+ }
+
+ bb15: {
+- _35 = Rem(move _36, const 1_u64);
+- StorageDead(_36);
++ _35 = Rem(_1, const 1_u64);
+ _34 = opaque::(move _35) -> [return: bb16, unwind unreachable];
+ }
+
+ bb16: {
+ StorageDead(_35);
+ StorageDead(_34);
+ StorageLive(_38);
+ StorageLive(_39);
+- StorageLive(_40);
+- _40 = _1;
+- _41 = Eq(_40, const 0_u64);
+- assert(!move _41, "attempt to calculate the remainder of `{}` with a divisor of zero", const 0_u64) -> [success: bb17, unwind unreachable];
++ assert(!_25, "attempt to calculate the remainder of `{}` with a divisor of zero", const 0_u64) -> [success: bb17, unwind unreachable];
+ }
+
+ bb17: {
+- _39 = Rem(const 0_u64, move _40);
+- StorageDead(_40);
++ _39 = Rem(const 0_u64, _1);
+ _38 = opaque::(move _39) -> [return: bb18, unwind unreachable];
+ }
+
+ bb18: {
+ StorageDead(_39);
+ StorageDead(_38);
+ StorageLive(_42);
+ StorageLive(_43);
+- StorageLive(_44);
+- _44 = _1;
+- _45 = Eq(_44, const 0_u64);
+- assert(!move _45, "attempt to calculate the remainder of `{}` with a divisor of zero", const 1_u64) -> [success: bb19, unwind unreachable];
++ assert(!_25, "attempt to calculate the remainder of `{}` with a divisor of zero", const 1_u64) -> [success: bb19, unwind unreachable];
+ }
+
+ bb19: {
+- _43 = Rem(const 1_u64, move _44);
+- StorageDead(_44);
++ _43 = Rem(const 1_u64, _1);
+ _42 = opaque::(move _43) -> [return: bb20, unwind unreachable];
+ }
+
+ bb20: {
+ StorageDead(_43);
+ StorageDead(_42);
+ StorageLive(_46);
+ StorageLive(_47);
+- StorageLive(_48);
+- _48 = _1;
+- _47 = BitAnd(move _48, const 0_u64);
+- StorageDead(_48);
++ _47 = BitAnd(_1, const 0_u64);
+ _46 = opaque::(move _47) -> [return: bb21, unwind unreachable];
+ }
+
+ bb21: {
+ StorageDead(_47);
+ StorageDead(_46);
+ StorageLive(_49);
+ StorageLive(_50);
+- StorageLive(_51);
+- _51 = _1;
+- _50 = BitOr(move _51, const 0_u64);
+- StorageDead(_51);
++ _50 = BitOr(_1, const 0_u64);
+ _49 = opaque::(move _50) -> [return: bb22, unwind unreachable];
+ }
+
+ bb22: {
+ StorageDead(_50);
+ StorageDead(_49);
+ StorageLive(_52);
+ StorageLive(_53);
+- StorageLive(_54);
+- _54 = _1;
+- _53 = BitXor(move _54, const 0_u64);
+- StorageDead(_54);
++ _53 = BitXor(_1, const 0_u64);
+ _52 = opaque::(move _53) -> [return: bb23, unwind unreachable];
+ }
+
+ bb23: {
+ StorageDead(_53);
+ StorageDead(_52);
+ StorageLive(_55);
+ StorageLive(_56);
+- StorageLive(_57);
+- _57 = _1;
+- _56 = Shr(move _57, const 0_i32);
+- StorageDead(_57);
++ _56 = Shr(_1, const 0_i32);
+ _55 = opaque::(move _56) -> [return: bb24, unwind unreachable];
+ }
+
+ bb24: {
+ StorageDead(_56);
+ StorageDead(_55);
+ StorageLive(_58);
+ StorageLive(_59);
+- StorageLive(_60);
+- _60 = _1;
+- _59 = Shl(move _60, const 0_i32);
+- StorageDead(_60);
++ _59 = Shl(_1, const 0_i32);
+ _58 = opaque::(move _59) -> [return: bb25, unwind unreachable];
+ }
+
+ bb25: {
+ StorageDead(_59);
+ StorageDead(_58);
+ _0 = const ();
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff b/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff
new file mode 100644
index 00000000000..38da21d91d4
--- /dev/null
+++ b/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff
@@ -0,0 +1,342 @@
+- // MIR for `arithmetic` before GVN
++ // MIR for `arithmetic` after GVN
+
+ fn arithmetic(_1: u64) -> () {
+ debug x => _1;
+ let mut _0: ();
+ let _2: ();
+ let mut _3: u64;
+ let mut _4: u64;
+ let _5: ();
+ let mut _6: u64;
+ let mut _7: u64;
+ let _8: ();
+ let mut _9: u64;
+ let mut _10: u64;
+ let _11: ();
+ let mut _12: u64;
+ let mut _13: u64;
+ let _14: ();
+ let mut _15: u64;
+ let mut _16: u64;
+ let mut _17: bool;
+ let _18: ();
+ let mut _19: u64;
+ let mut _20: u64;
+ let mut _21: bool;
+ let _22: ();
+ let mut _23: u64;
+ let mut _24: u64;
+ let mut _25: bool;
+ let _26: ();
+ let mut _27: u64;
+ let mut _28: u64;
+ let mut _29: bool;
+ let _30: ();
+ let mut _31: u64;
+ let mut _32: u64;
+ let mut _33: bool;
+ let _34: ();
+ let mut _35: u64;
+ let mut _36: u64;
+ let mut _37: bool;
+ let _38: ();
+ let mut _39: u64;
+ let mut _40: u64;
+ let mut _41: bool;
+ let _42: ();
+ let mut _43: u64;
+ let mut _44: u64;
+ let mut _45: bool;
+ let _46: ();
+ let mut _47: u64;
+ let mut _48: u64;
+ let _49: ();
+ let mut _50: u64;
+ let mut _51: u64;
+ let _52: ();
+ let mut _53: u64;
+ let mut _54: u64;
+ let _55: ();
+ let mut _56: u64;
+ let mut _57: u64;
+ let _58: ();
+ let mut _59: u64;
+ let mut _60: u64;
+
+ bb0: {
+ StorageLive(_2);
+ StorageLive(_3);
+- StorageLive(_4);
+- _4 = _1;
+- _3 = Add(move _4, const 0_u64);
+- StorageDead(_4);
++ _3 = Add(_1, const 0_u64);
+ _2 = opaque::(move _3) -> [return: bb1, unwind continue];
+ }
+
+ bb1: {
+ StorageDead(_3);
+ StorageDead(_2);
+ StorageLive(_5);
+ StorageLive(_6);
+- StorageLive(_7);
+- _7 = _1;
+- _6 = Sub(move _7, const 0_u64);
+- StorageDead(_7);
++ _6 = Sub(_1, const 0_u64);
+ _5 = opaque::(move _6) -> [return: bb2, unwind continue];
+ }
+
+ bb2: {
+ StorageDead(_6);
+ StorageDead(_5);
+ StorageLive(_8);
+ StorageLive(_9);
+- StorageLive(_10);
+- _10 = _1;
+- _9 = Mul(move _10, const 0_u64);
+- StorageDead(_10);
++ _9 = Mul(_1, const 0_u64);
+ _8 = opaque::(move _9) -> [return: bb3, unwind continue];
+ }
+
+ bb3: {
+ StorageDead(_9);
+ StorageDead(_8);
+ StorageLive(_11);
+ StorageLive(_12);
+- StorageLive(_13);
+- _13 = _1;
+- _12 = Mul(move _13, const 1_u64);
+- StorageDead(_13);
++ _12 = Mul(_1, const 1_u64);
+ _11 = opaque::(move _12) -> [return: bb4, unwind continue];
+ }
+
+ bb4: {
+ StorageDead(_12);
+ StorageDead(_11);
+ StorageLive(_14);
+ StorageLive(_15);
+- StorageLive(_16);
+- _16 = _1;
+ _17 = Eq(const 0_u64, const 0_u64);
+- assert(!move _17, "attempt to divide `{}` by zero", _16) -> [success: bb5, unwind continue];
++ assert(!_17, "attempt to divide `{}` by zero", _1) -> [success: bb5, unwind continue];
+ }
+
+ bb5: {
+- _15 = Div(move _16, const 0_u64);
+- StorageDead(_16);
++ _15 = Div(_1, const 0_u64);
+ _14 = opaque::(move _15) -> [return: bb6, unwind continue];
+ }
+
+ bb6: {
+ StorageDead(_15);
+ StorageDead(_14);
+ StorageLive(_18);
+ StorageLive(_19);
+- StorageLive(_20);
+- _20 = _1;
+ _21 = Eq(const 1_u64, const 0_u64);
+- assert(!move _21, "attempt to divide `{}` by zero", _20) -> [success: bb7, unwind continue];
++ assert(!_21, "attempt to divide `{}` by zero", _1) -> [success: bb7, unwind continue];
+ }
+
+ bb7: {
+- _19 = Div(move _20, const 1_u64);
+- StorageDead(_20);
++ _19 = Div(_1, const 1_u64);
+ _18 = opaque::(move _19) -> [return: bb8, unwind continue];
+ }
+
+ bb8: {
+ StorageDead(_19);
+ StorageDead(_18);
+ StorageLive(_22);
+ StorageLive(_23);
+- StorageLive(_24);
+- _24 = _1;
+- _25 = Eq(_24, const 0_u64);
+- assert(!move _25, "attempt to divide `{}` by zero", const 0_u64) -> [success: bb9, unwind continue];
++ _25 = Eq(_1, const 0_u64);
++ assert(!_25, "attempt to divide `{}` by zero", const 0_u64) -> [success: bb9, unwind continue];
+ }
+
+ bb9: {
+- _23 = Div(const 0_u64, move _24);
+- StorageDead(_24);
++ _23 = Div(const 0_u64, _1);
+ _22 = opaque::(move _23) -> [return: bb10, unwind continue];
+ }
+
+ bb10: {
+ StorageDead(_23);
+ StorageDead(_22);
+ StorageLive(_26);
+ StorageLive(_27);
+- StorageLive(_28);
+- _28 = _1;
+- _29 = Eq(_28, const 0_u64);
+- assert(!move _29, "attempt to divide `{}` by zero", const 1_u64) -> [success: bb11, unwind continue];
++ assert(!_25, "attempt to divide `{}` by zero", const 1_u64) -> [success: bb11, unwind continue];
+ }
+
+ bb11: {
+- _27 = Div(const 1_u64, move _28);
+- StorageDead(_28);
++ _27 = Div(const 1_u64, _1);
+ _26 = opaque::(move _27) -> [return: bb12, unwind continue];
+ }
+
+ bb12: {
+ StorageDead(_27);
+ StorageDead(_26);
+ StorageLive(_30);
+ StorageLive(_31);
+- StorageLive(_32);
+- _32 = _1;
+- _33 = Eq(const 0_u64, const 0_u64);
+- assert(!move _33, "attempt to calculate the remainder of `{}` with a divisor of zero", _32) -> [success: bb13, unwind continue];
++ assert(!_17, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb13, unwind continue];
+ }
+
+ bb13: {
+- _31 = Rem(move _32, const 0_u64);
+- StorageDead(_32);
++ _31 = Rem(_1, const 0_u64);
+ _30 = opaque::(move _31) -> [return: bb14, unwind continue];
+ }
+
+ bb14: {
+ StorageDead(_31);
+ StorageDead(_30);
+ StorageLive(_34);
+ StorageLive(_35);
+- StorageLive(_36);
+- _36 = _1;
+- _37 = Eq(const 1_u64, const 0_u64);
+- assert(!move _37, "attempt to calculate the remainder of `{}` with a divisor of zero", _36) -> [success: bb15, unwind continue];
++ assert(!_21, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb15, unwind continue];
+ }
+
+ bb15: {
+- _35 = Rem(move _36, const 1_u64);
+- StorageDead(_36);
++ _35 = Rem(_1, const 1_u64);
+ _34 = opaque::(move _35) -> [return: bb16, unwind continue];
+ }
+
+ bb16: {
+ StorageDead(_35);
+ StorageDead(_34);
+ StorageLive(_38);
+ StorageLive(_39);
+- StorageLive(_40);
+- _40 = _1;
+- _41 = Eq(_40, const 0_u64);
+- assert(!move _41, "attempt to calculate the remainder of `{}` with a divisor of zero", const 0_u64) -> [success: bb17, unwind continue];
++ assert(!_25, "attempt to calculate the remainder of `{}` with a divisor of zero", const 0_u64) -> [success: bb17, unwind continue];
+ }
+
+ bb17: {
+- _39 = Rem(const 0_u64, move _40);
+- StorageDead(_40);
++ _39 = Rem(const 0_u64, _1);
+ _38 = opaque::(move _39) -> [return: bb18, unwind continue];
+ }
+
+ bb18: {
+ StorageDead(_39);
+ StorageDead(_38);
+ StorageLive(_42);
+ StorageLive(_43);
+- StorageLive(_44);
+- _44 = _1;
+- _45 = Eq(_44, const 0_u64);
+- assert(!move _45, "attempt to calculate the remainder of `{}` with a divisor of zero", const 1_u64) -> [success: bb19, unwind continue];
++ assert(!_25, "attempt to calculate the remainder of `{}` with a divisor of zero", const 1_u64) -> [success: bb19, unwind continue];
+ }
+
+ bb19: {
+- _43 = Rem(const 1_u64, move _44);
+- StorageDead(_44);
++ _43 = Rem(const 1_u64, _1);
+ _42 = opaque::(move _43) -> [return: bb20, unwind continue];
+ }
+
+ bb20: {
+ StorageDead(_43);
+ StorageDead(_42);
+ StorageLive(_46);
+ StorageLive(_47);
+- StorageLive(_48);
+- _48 = _1;
+- _47 = BitAnd(move _48, const 0_u64);
+- StorageDead(_48);
++ _47 = BitAnd(_1, const 0_u64);
+ _46 = opaque::(move _47) -> [return: bb21, unwind continue];
+ }
+
+ bb21: {
+ StorageDead(_47);
+ StorageDead(_46);
+ StorageLive(_49);
+ StorageLive(_50);
+- StorageLive(_51);
+- _51 = _1;
+- _50 = BitOr(move _51, const 0_u64);
+- StorageDead(_51);
++ _50 = BitOr(_1, const 0_u64);
+ _49 = opaque::(move _50) -> [return: bb22, unwind continue];
+ }
+
+ bb22: {
+ StorageDead(_50);
+ StorageDead(_49);
+ StorageLive(_52);
+ StorageLive(_53);
+- StorageLive(_54);
+- _54 = _1;
+- _53 = BitXor(move _54, const 0_u64);
+- StorageDead(_54);
++ _53 = BitXor(_1, const 0_u64);
+ _52 = opaque::(move _53) -> [return: bb23, unwind continue];
+ }
+
+ bb23: {
+ StorageDead(_53);
+ StorageDead(_52);
+ StorageLive(_55);
+ StorageLive(_56);
+- StorageLive(_57);
+- _57 = _1;
+- _56 = Shr(move _57, const 0_i32);
+- StorageDead(_57);
++ _56 = Shr(_1, const 0_i32);
+ _55 = opaque::(move _56) -> [return: bb24, unwind continue];
+ }
+
+ bb24: {
+ StorageDead(_56);
+ StorageDead(_55);
+ StorageLive(_58);
+ StorageLive(_59);
+- StorageLive(_60);
+- _60 = _1;
+- _59 = Shl(move _60, const 0_i32);
+- StorageDead(_60);
++ _59 = Shl(_1, const 0_i32);
+ _58 = opaque::(move _59) -> [return: bb25, unwind continue];
+ }
+
+ bb25: {
+ StorageDead(_59);
+ StorageDead(_58);
+ _0 = const ();
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff
new file mode 100644
index 00000000000..0c342799e07
--- /dev/null
+++ b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff
@@ -0,0 +1,389 @@
+- // MIR for `arithmetic_checked` before GVN
++ // MIR for `arithmetic_checked` after GVN
+
+ fn arithmetic_checked(_1: u64) -> () {
+ debug x => _1;
+ let mut _0: ();
+ let _2: ();
+ let mut _3: u64;
+ let mut _4: u64;
+ let mut _5: (u64, bool);
+ let _6: ();
+ let mut _7: u64;
+ let mut _8: u64;
+ let mut _9: (u64, bool);
+ let _10: ();
+ let mut _11: u64;
+ let mut _12: u64;
+ let mut _13: (u64, bool);
+ let _14: ();
+ let mut _15: u64;
+ let mut _16: u64;
+ let mut _17: (u64, bool);
+ let _18: ();
+ let mut _19: u64;
+ let mut _20: u64;
+ let mut _21: bool;
+ let _22: ();
+ let mut _23: u64;
+ let mut _24: u64;
+ let mut _25: bool;
+ let _26: ();
+ let mut _27: u64;
+ let mut _28: u64;
+ let mut _29: bool;
+ let _30: ();
+ let mut _31: u64;
+ let mut _32: u64;
+ let mut _33: bool;
+ let _34: ();
+ let mut _35: u64;
+ let mut _36: u64;
+ let mut _37: bool;
+ let _38: ();
+ let mut _39: u64;
+ let mut _40: u64;
+ let mut _41: bool;
+ let _42: ();
+ let mut _43: u64;
+ let mut _44: u64;
+ let mut _45: bool;
+ let _46: ();
+ let mut _47: u64;
+ let mut _48: u64;
+ let mut _49: bool;
+ let _50: ();
+ let mut _51: u64;
+ let mut _52: u64;
+ let _53: ();
+ let mut _54: u64;
+ let mut _55: u64;
+ let _56: ();
+ let mut _57: u64;
+ let mut _58: u64;
+ let _59: ();
+ let mut _60: u64;
+ let mut _61: u64;
+ let mut _62: u32;
+ let mut _63: bool;
+ let _64: ();
+ let mut _65: u64;
+ let mut _66: u64;
+ let mut _67: u32;
+ let mut _68: bool;
+
+ bb0: {
+ StorageLive(_2);
+ StorageLive(_3);
+- StorageLive(_4);
+- _4 = _1;
+- _5 = CheckedAdd(_4, const 0_u64);
+- assert(!move (_5.1: bool), "attempt to compute `{} + {}`, which would overflow", move _4, const 0_u64) -> [success: bb1, unwind unreachable];
++ _5 = CheckedAdd(_1, const 0_u64);
++ assert(!move (_5.1: bool), "attempt to compute `{} + {}`, which would overflow", _1, const 0_u64) -> [success: bb1, unwind unreachable];
+ }
+
+ bb1: {
+ _3 = move (_5.0: u64);
+- StorageDead(_4);
+ _2 = opaque::(move _3) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
+ StorageDead(_3);
+ StorageDead(_2);
+ StorageLive(_6);
+ StorageLive(_7);
+- StorageLive(_8);
+- _8 = _1;
+- _9 = CheckedSub(_8, const 0_u64);
+- assert(!move (_9.1: bool), "attempt to compute `{} - {}`, which would overflow", move _8, const 0_u64) -> [success: bb3, unwind unreachable];
++ _9 = CheckedSub(_1, const 0_u64);
++ assert(!move (_9.1: bool), "attempt to compute `{} - {}`, which would overflow", _1, const 0_u64) -> [success: bb3, unwind unreachable];
+ }
+
+ bb3: {
+ _7 = move (_9.0: u64);
+- StorageDead(_8);
+ _6 = opaque::(move _7) -> [return: bb4, unwind unreachable];
+ }
+
+ bb4: {
+ StorageDead(_7);
+ StorageDead(_6);
+ StorageLive(_10);
+ StorageLive(_11);
+- StorageLive(_12);
+- _12 = _1;
+- _13 = CheckedMul(_12, const 0_u64);
+- assert(!move (_13.1: bool), "attempt to compute `{} * {}`, which would overflow", move _12, const 0_u64) -> [success: bb5, unwind unreachable];
++ _13 = CheckedMul(_1, const 0_u64);
++ assert(!move (_13.1: bool), "attempt to compute `{} * {}`, which would overflow", _1, const 0_u64) -> [success: bb5, unwind unreachable];
+ }
+
+ bb5: {
+ _11 = move (_13.0: u64);
+- StorageDead(_12);
+ _10 = opaque::(move _11) -> [return: bb6, unwind unreachable];
+ }
+
+ bb6: {
+ StorageDead(_11);
+ StorageDead(_10);
+ StorageLive(_14);
+ StorageLive(_15);
+- StorageLive(_16);
+- _16 = _1;
+- _17 = CheckedMul(_16, const 1_u64);
+- assert(!move (_17.1: bool), "attempt to compute `{} * {}`, which would overflow", move _16, const 1_u64) -> [success: bb7, unwind unreachable];
++ _17 = CheckedMul(_1, const 1_u64);
++ assert(!move (_17.1: bool), "attempt to compute `{} * {}`, which would overflow", _1, const 1_u64) -> [success: bb7, unwind unreachable];
+ }
+
+ bb7: {
+ _15 = move (_17.0: u64);
+- StorageDead(_16);
+ _14 = opaque::(move _15) -> [return: bb8, unwind unreachable];
+ }
+
+ bb8: {
+ StorageDead(_15);
+ StorageDead(_14);
+ StorageLive(_18);
+ StorageLive(_19);
+- StorageLive(_20);
+- _20 = _1;
+ _21 = Eq(const 0_u64, const 0_u64);
+- assert(!move _21, "attempt to divide `{}` by zero", _20) -> [success: bb9, unwind unreachable];
++ assert(!_21, "attempt to divide `{}` by zero", _1) -> [success: bb9, unwind unreachable];
+ }
+
+ bb9: {
+- _19 = Div(move _20, const 0_u64);
+- StorageDead(_20);
++ _19 = Div(_1, const 0_u64);
+ _18 = opaque::(move _19) -> [return: bb10, unwind unreachable];
+ }
+
+ bb10: {
+ StorageDead(_19);
+ StorageDead(_18);
+ StorageLive(_22);
+ StorageLive(_23);
+- StorageLive(_24);
+- _24 = _1;
+ _25 = Eq(const 1_u64, const 0_u64);
+- assert(!move _25, "attempt to divide `{}` by zero", _24) -> [success: bb11, unwind unreachable];
++ assert(!_25, "attempt to divide `{}` by zero", _1) -> [success: bb11, unwind unreachable];
+ }
+
+ bb11: {
+- _23 = Div(move _24, const 1_u64);
+- StorageDead(_24);
++ _23 = Div(_1, const 1_u64);
+ _22 = opaque::(move _23) -> [return: bb12, unwind unreachable];
+ }
+
+ bb12: {
+ StorageDead(_23);
+ StorageDead(_22);
+ StorageLive(_26);
+ StorageLive(_27);
+- StorageLive(_28);
+- _28 = _1;
+- _29 = Eq(_28, const 0_u64);
+- assert(!move _29, "attempt to divide `{}` by zero", const 0_u64) -> [success: bb13, unwind unreachable];
++ _29 = Eq(_1, const 0_u64);
++ assert(!_29, "attempt to divide `{}` by zero", const 0_u64) -> [success: bb13, unwind unreachable];
+ }
+
+ bb13: {
+- _27 = Div(const 0_u64, move _28);
+- StorageDead(_28);
++ _27 = Div(const 0_u64, _1);
+ _26 = opaque::(move _27) -> [return: bb14, unwind unreachable];
+ }
+
+ bb14: {
+ StorageDead(_27);
+ StorageDead(_26);
+ StorageLive(_30);
+ StorageLive(_31);
+- StorageLive(_32);
+- _32 = _1;
+- _33 = Eq(_32, const 0_u64);
+- assert(!move _33, "attempt to divide `{}` by zero", const 1_u64) -> [success: bb15, unwind unreachable];
++ assert(!_29, "attempt to divide `{}` by zero", const 1_u64) -> [success: bb15, unwind unreachable];
+ }
+
+ bb15: {
+- _31 = Div(const 1_u64, move _32);
+- StorageDead(_32);
++ _31 = Div(const 1_u64, _1);
+ _30 = opaque::(move _31) -> [return: bb16, unwind unreachable];
+ }
+
+ bb16: {
+ StorageDead(_31);
+ StorageDead(_30);
+ StorageLive(_34);
+ StorageLive(_35);
+- StorageLive(_36);
+- _36 = _1;
+- _37 = Eq(const 0_u64, const 0_u64);
+- assert(!move _37, "attempt to calculate the remainder of `{}` with a divisor of zero", _36) -> [success: bb17, unwind unreachable];
++ assert(!_21, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb17, unwind unreachable];
+ }
+
+ bb17: {
+- _35 = Rem(move _36, const 0_u64);
+- StorageDead(_36);
++ _35 = Rem(_1, const 0_u64);
+ _34 = opaque::(move _35) -> [return: bb18, unwind unreachable];
+ }
+
+ bb18: {
+ StorageDead(_35);
+ StorageDead(_34);
+ StorageLive(_38);
+ StorageLive(_39);
+- StorageLive(_40);
+- _40 = _1;
+- _41 = Eq(const 1_u64, const 0_u64);
+- assert(!move _41, "attempt to calculate the remainder of `{}` with a divisor of zero", _40) -> [success: bb19, unwind unreachable];
++ assert(!_25, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb19, unwind unreachable];
+ }
+
+ bb19: {
+- _39 = Rem(move _40, const 1_u64);
+- StorageDead(_40);
++ _39 = Rem(_1, const 1_u64);
+ _38 = opaque::(move _39) -> [return: bb20, unwind unreachable];
+ }
+
+ bb20: {
+ StorageDead(_39);
+ StorageDead(_38);
+ StorageLive(_42);
+ StorageLive(_43);
+- StorageLive(_44);
+- _44 = _1;
+- _45 = Eq(_44, const 0_u64);
+- assert(!move _45, "attempt to calculate the remainder of `{}` with a divisor of zero", const 0_u64) -> [success: bb21, unwind unreachable];
++ assert(!_29, "attempt to calculate the remainder of `{}` with a divisor of zero", const 0_u64) -> [success: bb21, unwind unreachable];
+ }
+
+ bb21: {
+- _43 = Rem(const 0_u64, move _44);
+- StorageDead(_44);
++ _43 = Rem(const 0_u64, _1);
+ _42 = opaque::(move _43) -> [return: bb22, unwind unreachable];
+ }
+
+ bb22: {
+ StorageDead(_43);
+ StorageDead(_42);
+ StorageLive(_46);
+ StorageLive(_47);
+- StorageLive(_48);
+- _48 = _1;
+- _49 = Eq(_48, const 0_u64);
+- assert(!move _49, "attempt to calculate the remainder of `{}` with a divisor of zero", const 1_u64) -> [success: bb23, unwind unreachable];
++ assert(!_29, "attempt to calculate the remainder of `{}` with a divisor of zero", const 1_u64) -> [success: bb23, unwind unreachable];
+ }
+
+ bb23: {
+- _47 = Rem(const 1_u64, move _48);
+- StorageDead(_48);
++ _47 = Rem(const 1_u64, _1);
+ _46 = opaque::(move _47) -> [return: bb24, unwind unreachable];
+ }
+
+ bb24: {
+ StorageDead(_47);
+ StorageDead(_46);
+ StorageLive(_50);
+ StorageLive(_51);
+- StorageLive(_52);
+- _52 = _1;
+- _51 = BitAnd(move _52, const 0_u64);
+- StorageDead(_52);
++ _51 = BitAnd(_1, const 0_u64);
+ _50 = opaque::(move _51) -> [return: bb25, unwind unreachable];
+ }
+
+ bb25: {
+ StorageDead(_51);
+ StorageDead(_50);
+ StorageLive(_53);
+ StorageLive(_54);
+- StorageLive(_55);
+- _55 = _1;
+- _54 = BitOr(move _55, const 0_u64);
+- StorageDead(_55);
++ _54 = BitOr(_1, const 0_u64);
+ _53 = opaque::(move _54) -> [return: bb26, unwind unreachable];
+ }
+
+ bb26: {
+ StorageDead(_54);
+ StorageDead(_53);
+ StorageLive(_56);
+ StorageLive(_57);
+- StorageLive(_58);
+- _58 = _1;
+- _57 = BitXor(move _58, const 0_u64);
+- StorageDead(_58);
++ _57 = BitXor(_1, const 0_u64);
+ _56 = opaque::(move _57) -> [return: bb27, unwind unreachable];
+ }
+
+ bb27: {
+ StorageDead(_57);
+ StorageDead(_56);
+ StorageLive(_59);
+ StorageLive(_60);
+- StorageLive(_61);
+- _61 = _1;
+ _62 = const 0_i32 as u32 (IntToInt);
+- _63 = Lt(move _62, const 64_u32);
+- assert(move _63, "attempt to shift right by `{}`, which would overflow", const 0_i32) -> [success: bb28, unwind unreachable];
++ _63 = Lt(_62, const 64_u32);
++ assert(_63, "attempt to shift right by `{}`, which would overflow", const 0_i32) -> [success: bb28, unwind unreachable];
+ }
+
+ bb28: {
+- _60 = Shr(move _61, const 0_i32);
+- StorageDead(_61);
++ _60 = Shr(_1, const 0_i32);
+ _59 = opaque::(move _60) -> [return: bb29, unwind unreachable];
+ }
+
+ bb29: {
+ StorageDead(_60);
+ StorageDead(_59);
+ StorageLive(_64);
+ StorageLive(_65);
+- StorageLive(_66);
+- _66 = _1;
+- _67 = const 0_i32 as u32 (IntToInt);
+- _68 = Lt(move _67, const 64_u32);
+- assert(move _68, "attempt to shift left by `{}`, which would overflow", const 0_i32) -> [success: bb30, unwind unreachable];
++ assert(_63, "attempt to shift left by `{}`, which would overflow", const 0_i32) -> [success: bb30, unwind unreachable];
+ }
+
+ bb30: {
+- _65 = Shl(move _66, const 0_i32);
+- StorageDead(_66);
++ _65 = Shl(_1, const 0_i32);
+ _64 = opaque::(move _65) -> [return: bb31, unwind unreachable];
+ }
+
+ bb31: {
+ StorageDead(_65);
+ StorageDead(_64);
+ _0 = const ();
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff
new file mode 100644
index 00000000000..7813c29b962
--- /dev/null
+++ b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff
@@ -0,0 +1,389 @@
+- // MIR for `arithmetic_checked` before GVN
++ // MIR for `arithmetic_checked` after GVN
+
+ fn arithmetic_checked(_1: u64) -> () {
+ debug x => _1;
+ let mut _0: ();
+ let _2: ();
+ let mut _3: u64;
+ let mut _4: u64;
+ let mut _5: (u64, bool);
+ let _6: ();
+ let mut _7: u64;
+ let mut _8: u64;
+ let mut _9: (u64, bool);
+ let _10: ();
+ let mut _11: u64;
+ let mut _12: u64;
+ let mut _13: (u64, bool);
+ let _14: ();
+ let mut _15: u64;
+ let mut _16: u64;
+ let mut _17: (u64, bool);
+ let _18: ();
+ let mut _19: u64;
+ let mut _20: u64;
+ let mut _21: bool;
+ let _22: ();
+ let mut _23: u64;
+ let mut _24: u64;
+ let mut _25: bool;
+ let _26: ();
+ let mut _27: u64;
+ let mut _28: u64;
+ let mut _29: bool;
+ let _30: ();
+ let mut _31: u64;
+ let mut _32: u64;
+ let mut _33: bool;
+ let _34: ();
+ let mut _35: u64;
+ let mut _36: u64;
+ let mut _37: bool;
+ let _38: ();
+ let mut _39: u64;
+ let mut _40: u64;
+ let mut _41: bool;
+ let _42: ();
+ let mut _43: u64;
+ let mut _44: u64;
+ let mut _45: bool;
+ let _46: ();
+ let mut _47: u64;
+ let mut _48: u64;
+ let mut _49: bool;
+ let _50: ();
+ let mut _51: u64;
+ let mut _52: u64;
+ let _53: ();
+ let mut _54: u64;
+ let mut _55: u64;
+ let _56: ();
+ let mut _57: u64;
+ let mut _58: u64;
+ let _59: ();
+ let mut _60: u64;
+ let mut _61: u64;
+ let mut _62: u32;
+ let mut _63: bool;
+ let _64: ();
+ let mut _65: u64;
+ let mut _66: u64;
+ let mut _67: u32;
+ let mut _68: bool;
+
+ bb0: {
+ StorageLive(_2);
+ StorageLive(_3);
+- StorageLive(_4);
+- _4 = _1;
+- _5 = CheckedAdd(_4, const 0_u64);
+- assert(!move (_5.1: bool), "attempt to compute `{} + {}`, which would overflow", move _4, const 0_u64) -> [success: bb1, unwind continue];
++ _5 = CheckedAdd(_1, const 0_u64);
++ assert(!move (_5.1: bool), "attempt to compute `{} + {}`, which would overflow", _1, const 0_u64) -> [success: bb1, unwind continue];
+ }
+
+ bb1: {
+ _3 = move (_5.0: u64);
+- StorageDead(_4);
+ _2 = opaque::(move _3) -> [return: bb2, unwind continue];
+ }
+
+ bb2: {
+ StorageDead(_3);
+ StorageDead(_2);
+ StorageLive(_6);
+ StorageLive(_7);
+- StorageLive(_8);
+- _8 = _1;
+- _9 = CheckedSub(_8, const 0_u64);
+- assert(!move (_9.1: bool), "attempt to compute `{} - {}`, which would overflow", move _8, const 0_u64) -> [success: bb3, unwind continue];
++ _9 = CheckedSub(_1, const 0_u64);
++ assert(!move (_9.1: bool), "attempt to compute `{} - {}`, which would overflow", _1, const 0_u64) -> [success: bb3, unwind continue];
+ }
+
+ bb3: {
+ _7 = move (_9.0: u64);
+- StorageDead(_8);
+ _6 = opaque::(move _7) -> [return: bb4, unwind continue];
+ }
+
+ bb4: {
+ StorageDead(_7);
+ StorageDead(_6);
+ StorageLive(_10);
+ StorageLive(_11);
+- StorageLive(_12);
+- _12 = _1;
+- _13 = CheckedMul(_12, const 0_u64);
+- assert(!move (_13.1: bool), "attempt to compute `{} * {}`, which would overflow", move _12, const 0_u64) -> [success: bb5, unwind continue];
++ _13 = CheckedMul(_1, const 0_u64);
++ assert(!move (_13.1: bool), "attempt to compute `{} * {}`, which would overflow", _1, const 0_u64) -> [success: bb5, unwind continue];
+ }
+
+ bb5: {
+ _11 = move (_13.0: u64);
+- StorageDead(_12);
+ _10 = opaque::(move _11) -> [return: bb6, unwind continue];
+ }
+
+ bb6: {
+ StorageDead(_11);
+ StorageDead(_10);
+ StorageLive(_14);
+ StorageLive(_15);
+- StorageLive(_16);
+- _16 = _1;
+- _17 = CheckedMul(_16, const 1_u64);
+- assert(!move (_17.1: bool), "attempt to compute `{} * {}`, which would overflow", move _16, const 1_u64) -> [success: bb7, unwind continue];
++ _17 = CheckedMul(_1, const 1_u64);
++ assert(!move (_17.1: bool), "attempt to compute `{} * {}`, which would overflow", _1, const 1_u64) -> [success: bb7, unwind continue];
+ }
+
+ bb7: {
+ _15 = move (_17.0: u64);
+- StorageDead(_16);
+ _14 = opaque::(move _15) -> [return: bb8, unwind continue];
+ }
+
+ bb8: {
+ StorageDead(_15);
+ StorageDead(_14);
+ StorageLive(_18);
+ StorageLive(_19);
+- StorageLive(_20);
+- _20 = _1;
+ _21 = Eq(const 0_u64, const 0_u64);
+- assert(!move _21, "attempt to divide `{}` by zero", _20) -> [success: bb9, unwind continue];
++ assert(!_21, "attempt to divide `{}` by zero", _1) -> [success: bb9, unwind continue];
+ }
+
+ bb9: {
+- _19 = Div(move _20, const 0_u64);
+- StorageDead(_20);
++ _19 = Div(_1, const 0_u64);
+ _18 = opaque::(move _19) -> [return: bb10, unwind continue];
+ }
+
+ bb10: {
+ StorageDead(_19);
+ StorageDead(_18);
+ StorageLive(_22);
+ StorageLive(_23);
+- StorageLive(_24);
+- _24 = _1;
+ _25 = Eq(const 1_u64, const 0_u64);
+- assert(!move _25, "attempt to divide `{}` by zero", _24) -> [success: bb11, unwind continue];
++ assert(!_25, "attempt to divide `{}` by zero", _1) -> [success: bb11, unwind continue];
+ }
+
+ bb11: {
+- _23 = Div(move _24, const 1_u64);
+- StorageDead(_24);
++ _23 = Div(_1, const 1_u64);
+ _22 = opaque::(move _23) -> [return: bb12, unwind continue];
+ }
+
+ bb12: {
+ StorageDead(_23);
+ StorageDead(_22);
+ StorageLive(_26);
+ StorageLive(_27);
+- StorageLive(_28);
+- _28 = _1;
+- _29 = Eq(_28, const 0_u64);
+- assert(!move _29, "attempt to divide `{}` by zero", const 0_u64) -> [success: bb13, unwind continue];
++ _29 = Eq(_1, const 0_u64);
++ assert(!_29, "attempt to divide `{}` by zero", const 0_u64) -> [success: bb13, unwind continue];
+ }
+
+ bb13: {
+- _27 = Div(const 0_u64, move _28);
+- StorageDead(_28);
++ _27 = Div(const 0_u64, _1);
+ _26 = opaque::(move _27) -> [return: bb14, unwind continue];
+ }
+
+ bb14: {
+ StorageDead(_27);
+ StorageDead(_26);
+ StorageLive(_30);
+ StorageLive(_31);
+- StorageLive(_32);
+- _32 = _1;
+- _33 = Eq(_32, const 0_u64);
+- assert(!move _33, "attempt to divide `{}` by zero", const 1_u64) -> [success: bb15, unwind continue];
++ assert(!_29, "attempt to divide `{}` by zero", const 1_u64) -> [success: bb15, unwind continue];
+ }
+
+ bb15: {
+- _31 = Div(const 1_u64, move _32);
+- StorageDead(_32);
++ _31 = Div(const 1_u64, _1);
+ _30 = opaque::(move _31) -> [return: bb16, unwind continue];
+ }
+
+ bb16: {
+ StorageDead(_31);
+ StorageDead(_30);
+ StorageLive(_34);
+ StorageLive(_35);
+- StorageLive(_36);
+- _36 = _1;
+- _37 = Eq(const 0_u64, const 0_u64);
+- assert(!move _37, "attempt to calculate the remainder of `{}` with a divisor of zero", _36) -> [success: bb17, unwind continue];
++ assert(!_21, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb17, unwind continue];
+ }
+
+ bb17: {
+- _35 = Rem(move _36, const 0_u64);
+- StorageDead(_36);
++ _35 = Rem(_1, const 0_u64);
+ _34 = opaque::(move _35) -> [return: bb18, unwind continue];
+ }
+
+ bb18: {
+ StorageDead(_35);
+ StorageDead(_34);
+ StorageLive(_38);
+ StorageLive(_39);
+- StorageLive(_40);
+- _40 = _1;
+- _41 = Eq(const 1_u64, const 0_u64);
+- assert(!move _41, "attempt to calculate the remainder of `{}` with a divisor of zero", _40) -> [success: bb19, unwind continue];
++ assert(!_25, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb19, unwind continue];
+ }
+
+ bb19: {
+- _39 = Rem(move _40, const 1_u64);
+- StorageDead(_40);
++ _39 = Rem(_1, const 1_u64);
+ _38 = opaque::(move _39) -> [return: bb20, unwind continue];
+ }
+
+ bb20: {
+ StorageDead(_39);
+ StorageDead(_38);
+ StorageLive(_42);
+ StorageLive(_43);
+- StorageLive(_44);
+- _44 = _1;
+- _45 = Eq(_44, const 0_u64);
+- assert(!move _45, "attempt to calculate the remainder of `{}` with a divisor of zero", const 0_u64) -> [success: bb21, unwind continue];
++ assert(!_29, "attempt to calculate the remainder of `{}` with a divisor of zero", const 0_u64) -> [success: bb21, unwind continue];
+ }
+
+ bb21: {
+- _43 = Rem(const 0_u64, move _44);
+- StorageDead(_44);
++ _43 = Rem(const 0_u64, _1);
+ _42 = opaque::(move _43) -> [return: bb22, unwind continue];
+ }
+
+ bb22: {
+ StorageDead(_43);
+ StorageDead(_42);
+ StorageLive(_46);
+ StorageLive(_47);
+- StorageLive(_48);
+- _48 = _1;
+- _49 = Eq(_48, const 0_u64);
+- assert(!move _49, "attempt to calculate the remainder of `{}` with a divisor of zero", const 1_u64) -> [success: bb23, unwind continue];
++ assert(!_29, "attempt to calculate the remainder of `{}` with a divisor of zero", const 1_u64) -> [success: bb23, unwind continue];
+ }
+
+ bb23: {
+- _47 = Rem(const 1_u64, move _48);
+- StorageDead(_48);
++ _47 = Rem(const 1_u64, _1);
+ _46 = opaque::(move _47) -> [return: bb24, unwind continue];
+ }
+
+ bb24: {
+ StorageDead(_47);
+ StorageDead(_46);
+ StorageLive(_50);
+ StorageLive(_51);
+- StorageLive(_52);
+- _52 = _1;
+- _51 = BitAnd(move _52, const 0_u64);
+- StorageDead(_52);
++ _51 = BitAnd(_1, const 0_u64);
+ _50 = opaque::(move _51) -> [return: bb25, unwind continue];
+ }
+
+ bb25: {
+ StorageDead(_51);
+ StorageDead(_50);
+ StorageLive(_53);
+ StorageLive(_54);
+- StorageLive(_55);
+- _55 = _1;
+- _54 = BitOr(move _55, const 0_u64);
+- StorageDead(_55);
++ _54 = BitOr(_1, const 0_u64);
+ _53 = opaque::(move _54) -> [return: bb26, unwind continue];
+ }
+
+ bb26: {
+ StorageDead(_54);
+ StorageDead(_53);
+ StorageLive(_56);
+ StorageLive(_57);
+- StorageLive(_58);
+- _58 = _1;
+- _57 = BitXor(move _58, const 0_u64);
+- StorageDead(_58);
++ _57 = BitXor(_1, const 0_u64);
+ _56 = opaque::(move _57) -> [return: bb27, unwind continue];
+ }
+
+ bb27: {
+ StorageDead(_57);
+ StorageDead(_56);
+ StorageLive(_59);
+ StorageLive(_60);
+- StorageLive(_61);
+- _61 = _1;
+ _62 = const 0_i32 as u32 (IntToInt);
+- _63 = Lt(move _62, const 64_u32);
+- assert(move _63, "attempt to shift right by `{}`, which would overflow", const 0_i32) -> [success: bb28, unwind continue];
++ _63 = Lt(_62, const 64_u32);
++ assert(_63, "attempt to shift right by `{}`, which would overflow", const 0_i32) -> [success: bb28, unwind continue];
+ }
+
+ bb28: {
+- _60 = Shr(move _61, const 0_i32);
+- StorageDead(_61);
++ _60 = Shr(_1, const 0_i32);
+ _59 = opaque::(move _60) -> [return: bb29, unwind continue];
+ }
+
+ bb29: {
+ StorageDead(_60);
+ StorageDead(_59);
+ StorageLive(_64);
+ StorageLive(_65);
+- StorageLive(_66);
+- _66 = _1;
+- _67 = const 0_i32 as u32 (IntToInt);
+- _68 = Lt(move _67, const 64_u32);
+- assert(move _68, "attempt to shift left by `{}`, which would overflow", const 0_i32) -> [success: bb30, unwind continue];
++ assert(_63, "attempt to shift left by `{}`, which would overflow", const 0_i32) -> [success: bb30, unwind continue];
+ }
+
+ bb30: {
+- _65 = Shl(move _66, const 0_i32);
+- StorageDead(_66);
++ _65 = Shl(_1, const 0_i32);
+ _64 = opaque::(move _65) -> [return: bb31, unwind continue];
+ }
+
+ bb31: {
+ StorageDead(_65);
+ StorageDead(_64);
+ _0 = const ();
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.arithmetic_float.GVN.panic-abort.diff b/tests/mir-opt/gvn.arithmetic_float.GVN.panic-abort.diff
new file mode 100644
index 00000000000..7d5ac8353fe
--- /dev/null
+++ b/tests/mir-opt/gvn.arithmetic_float.GVN.panic-abort.diff
@@ -0,0 +1,165 @@
+- // MIR for `arithmetic_float` before GVN
++ // MIR for `arithmetic_float` after GVN
+
+ fn arithmetic_float(_1: f64) -> () {
+ debug x => _1;
+ let mut _0: ();
+ let _2: ();
+ let mut _3: f64;
+ let mut _4: f64;
+ let _5: ();
+ let mut _6: f64;
+ let mut _7: f64;
+ let _8: ();
+ let mut _9: f64;
+ let mut _10: f64;
+ let _11: ();
+ let mut _12: f64;
+ let mut _13: f64;
+ let _14: ();
+ let mut _15: f64;
+ let mut _16: f64;
+ let _17: ();
+ let mut _18: f64;
+ let mut _19: f64;
+ let _20: ();
+ let mut _21: f64;
+ let mut _22: f64;
+ let _23: ();
+ let mut _24: bool;
+ let mut _25: f64;
+ let mut _26: f64;
+ let _27: ();
+ let mut _28: bool;
+ let mut _29: f64;
+ let mut _30: f64;
+
+ bb0: {
+ StorageLive(_2);
+ StorageLive(_3);
+- StorageLive(_4);
+- _4 = _1;
+- _3 = Add(move _4, const 0f64);
+- StorageDead(_4);
++ _3 = Add(_1, const 0f64);
+ _2 = opaque::(move _3) -> [return: bb1, unwind unreachable];
+ }
+
+ bb1: {
+ StorageDead(_3);
+ StorageDead(_2);
+ StorageLive(_5);
+ StorageLive(_6);
+- StorageLive(_7);
+- _7 = _1;
+- _6 = Sub(move _7, const 0f64);
+- StorageDead(_7);
++ _6 = Sub(_1, const 0f64);
+ _5 = opaque::(move _6) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
+ StorageDead(_6);
+ StorageDead(_5);
+ StorageLive(_8);
+ StorageLive(_9);
+- StorageLive(_10);
+- _10 = _1;
+- _9 = Mul(move _10, const 0f64);
+- StorageDead(_10);
++ _9 = Mul(_1, const 0f64);
+ _8 = opaque::(move _9) -> [return: bb3, unwind unreachable];
+ }
+
+ bb3: {
+ StorageDead(_9);
+ StorageDead(_8);
+ StorageLive(_11);
+ StorageLive(_12);
+- StorageLive(_13);
+- _13 = _1;
+- _12 = Div(move _13, const 0f64);
+- StorageDead(_13);
++ _12 = Div(_1, const 0f64);
+ _11 = opaque::(move _12) -> [return: bb4, unwind unreachable];
+ }
+
+ bb4: {
+ StorageDead(_12);
+ StorageDead(_11);
+ StorageLive(_14);
+ StorageLive(_15);
+- StorageLive(_16);
+- _16 = _1;
+- _15 = Div(const 0f64, move _16);
+- StorageDead(_16);
++ _15 = Div(const 0f64, _1);
+ _14 = opaque::(move _15) -> [return: bb5, unwind unreachable];
+ }
+
+ bb5: {
+ StorageDead(_15);
+ StorageDead(_14);
+ StorageLive(_17);
+ StorageLive(_18);
+- StorageLive(_19);
+- _19 = _1;
+- _18 = Rem(move _19, const 0f64);
+- StorageDead(_19);
++ _18 = Rem(_1, const 0f64);
+ _17 = opaque::(move _18) -> [return: bb6, unwind unreachable];
+ }
+
+ bb6: {
+ StorageDead(_18);
+ StorageDead(_17);
+ StorageLive(_20);
+ StorageLive(_21);
+- StorageLive(_22);
+- _22 = _1;
+- _21 = Rem(const 0f64, move _22);
+- StorageDead(_22);
++ _21 = Rem(const 0f64, _1);
+ _20 = opaque::(move _21) -> [return: bb7, unwind unreachable];
+ }
+
+ bb7: {
+ StorageDead(_21);
+ StorageDead(_20);
+ StorageLive(_23);
+ StorageLive(_24);
+- StorageLive(_25);
+- _25 = _1;
+- StorageLive(_26);
+- _26 = _1;
+- _24 = Eq(move _25, move _26);
+- StorageDead(_26);
+- StorageDead(_25);
++ _24 = Eq(_1, _1);
+ _23 = opaque::(move _24) -> [return: bb8, unwind unreachable];
+ }
+
+ bb8: {
+ StorageDead(_24);
+ StorageDead(_23);
+ StorageLive(_27);
+ StorageLive(_28);
+- StorageLive(_29);
+- _29 = _1;
+- StorageLive(_30);
+- _30 = _1;
+- _28 = Ne(move _29, move _30);
+- StorageDead(_30);
+- StorageDead(_29);
++ _28 = Ne(_1, _1);
+ _27 = opaque::(move _28) -> [return: bb9, unwind unreachable];
+ }
+
+ bb9: {
+ StorageDead(_28);
+ StorageDead(_27);
+ _0 = const ();
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.arithmetic_float.GVN.panic-unwind.diff b/tests/mir-opt/gvn.arithmetic_float.GVN.panic-unwind.diff
new file mode 100644
index 00000000000..36c26dc6605
--- /dev/null
+++ b/tests/mir-opt/gvn.arithmetic_float.GVN.panic-unwind.diff
@@ -0,0 +1,165 @@
+- // MIR for `arithmetic_float` before GVN
++ // MIR for `arithmetic_float` after GVN
+
+ fn arithmetic_float(_1: f64) -> () {
+ debug x => _1;
+ let mut _0: ();
+ let _2: ();
+ let mut _3: f64;
+ let mut _4: f64;
+ let _5: ();
+ let mut _6: f64;
+ let mut _7: f64;
+ let _8: ();
+ let mut _9: f64;
+ let mut _10: f64;
+ let _11: ();
+ let mut _12: f64;
+ let mut _13: f64;
+ let _14: ();
+ let mut _15: f64;
+ let mut _16: f64;
+ let _17: ();
+ let mut _18: f64;
+ let mut _19: f64;
+ let _20: ();
+ let mut _21: f64;
+ let mut _22: f64;
+ let _23: ();
+ let mut _24: bool;
+ let mut _25: f64;
+ let mut _26: f64;
+ let _27: ();
+ let mut _28: bool;
+ let mut _29: f64;
+ let mut _30: f64;
+
+ bb0: {
+ StorageLive(_2);
+ StorageLive(_3);
+- StorageLive(_4);
+- _4 = _1;
+- _3 = Add(move _4, const 0f64);
+- StorageDead(_4);
++ _3 = Add(_1, const 0f64);
+ _2 = opaque::(move _3) -> [return: bb1, unwind continue];
+ }
+
+ bb1: {
+ StorageDead(_3);
+ StorageDead(_2);
+ StorageLive(_5);
+ StorageLive(_6);
+- StorageLive(_7);
+- _7 = _1;
+- _6 = Sub(move _7, const 0f64);
+- StorageDead(_7);
++ _6 = Sub(_1, const 0f64);
+ _5 = opaque::(move _6) -> [return: bb2, unwind continue];
+ }
+
+ bb2: {
+ StorageDead(_6);
+ StorageDead(_5);
+ StorageLive(_8);
+ StorageLive(_9);
+- StorageLive(_10);
+- _10 = _1;
+- _9 = Mul(move _10, const 0f64);
+- StorageDead(_10);
++ _9 = Mul(_1, const 0f64);
+ _8 = opaque::(move _9) -> [return: bb3, unwind continue];
+ }
+
+ bb3: {
+ StorageDead(_9);
+ StorageDead(_8);
+ StorageLive(_11);
+ StorageLive(_12);
+- StorageLive(_13);
+- _13 = _1;
+- _12 = Div(move _13, const 0f64);
+- StorageDead(_13);
++ _12 = Div(_1, const 0f64);
+ _11 = opaque::(move _12) -> [return: bb4, unwind continue];
+ }
+
+ bb4: {
+ StorageDead(_12);
+ StorageDead(_11);
+ StorageLive(_14);
+ StorageLive(_15);
+- StorageLive(_16);
+- _16 = _1;
+- _15 = Div(const 0f64, move _16);
+- StorageDead(_16);
++ _15 = Div(const 0f64, _1);
+ _14 = opaque::(move _15) -> [return: bb5, unwind continue];
+ }
+
+ bb5: {
+ StorageDead(_15);
+ StorageDead(_14);
+ StorageLive(_17);
+ StorageLive(_18);
+- StorageLive(_19);
+- _19 = _1;
+- _18 = Rem(move _19, const 0f64);
+- StorageDead(_19);
++ _18 = Rem(_1, const 0f64);
+ _17 = opaque::(move _18) -> [return: bb6, unwind continue];
+ }
+
+ bb6: {
+ StorageDead(_18);
+ StorageDead(_17);
+ StorageLive(_20);
+ StorageLive(_21);
+- StorageLive(_22);
+- _22 = _1;
+- _21 = Rem(const 0f64, move _22);
+- StorageDead(_22);
++ _21 = Rem(const 0f64, _1);
+ _20 = opaque::(move _21) -> [return: bb7, unwind continue];
+ }
+
+ bb7: {
+ StorageDead(_21);
+ StorageDead(_20);
+ StorageLive(_23);
+ StorageLive(_24);
+- StorageLive(_25);
+- _25 = _1;
+- StorageLive(_26);
+- _26 = _1;
+- _24 = Eq(move _25, move _26);
+- StorageDead(_26);
+- StorageDead(_25);
++ _24 = Eq(_1, _1);
+ _23 = opaque::(move _24) -> [return: bb8, unwind continue];
+ }
+
+ bb8: {
+ StorageDead(_24);
+ StorageDead(_23);
+ StorageLive(_27);
+ StorageLive(_28);
+- StorageLive(_29);
+- _29 = _1;
+- StorageLive(_30);
+- _30 = _1;
+- _28 = Ne(move _29, move _30);
+- StorageDead(_30);
+- StorageDead(_29);
++ _28 = Ne(_1, _1);
+ _27 = opaque::(move _28) -> [return: bb9, unwind continue];
+ }
+
+ bb9: {
+ StorageDead(_28);
+ StorageDead(_27);
+ _0 = const ();
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.cast.GVN.panic-abort.diff b/tests/mir-opt/gvn.cast.GVN.panic-abort.diff
new file mode 100644
index 00000000000..513fe60b65d
--- /dev/null
+++ b/tests/mir-opt/gvn.cast.GVN.panic-abort.diff
@@ -0,0 +1,501 @@
+- // MIR for `cast` before GVN
++ // MIR for `cast` after GVN
+
+ fn cast() -> () {
+ let mut _0: ();
+ let _1: i64;
+ let _4: ();
+ let mut _5: u8;
+ let mut _6: i64;
+ let _7: ();
+ let mut _8: u16;
+ let mut _9: i64;
+ let _10: ();
+ let mut _11: u32;
+ let mut _12: i64;
+ let _13: ();
+ let mut _14: u64;
+ let mut _15: i64;
+ let _16: ();
+ let mut _17: i8;
+ let mut _18: i64;
+ let _19: ();
+ let mut _20: i16;
+ let mut _21: i64;
+ let _22: ();
+ let mut _23: i32;
+ let mut _24: i64;
+ let _25: ();
+ let mut _26: i64;
+ let _27: ();
+ let mut _28: f32;
+ let mut _29: i64;
+ let _30: ();
+ let mut _31: f64;
+ let mut _32: i64;
+ let _33: ();
+ let mut _34: u8;
+ let mut _35: u64;
+ let _36: ();
+ let mut _37: u16;
+ let mut _38: u64;
+ let _39: ();
+ let mut _40: u32;
+ let mut _41: u64;
+ let _42: ();
+ let mut _43: u64;
+ let _44: ();
+ let mut _45: i8;
+ let mut _46: u64;
+ let _47: ();
+ let mut _48: i16;
+ let mut _49: u64;
+ let _50: ();
+ let mut _51: i32;
+ let mut _52: u64;
+ let _53: ();
+ let mut _54: i64;
+ let mut _55: u64;
+ let _56: ();
+ let mut _57: f32;
+ let mut _58: u64;
+ let _59: ();
+ let mut _60: f64;
+ let mut _61: u64;
+ let _62: ();
+ let mut _63: u8;
+ let mut _64: f64;
+ let _65: ();
+ let mut _66: u16;
+ let mut _67: f64;
+ let _68: ();
+ let mut _69: u32;
+ let mut _70: f64;
+ let _71: ();
+ let mut _72: u64;
+ let mut _73: f64;
+ let _74: ();
+ let mut _75: i8;
+ let mut _76: f64;
+ let _77: ();
+ let mut _78: i16;
+ let mut _79: f64;
+ let _80: ();
+ let mut _81: i32;
+ let mut _82: f64;
+ let _83: ();
+ let mut _84: i64;
+ let mut _85: f64;
+ let _86: ();
+ let mut _87: f32;
+ let mut _88: f64;
+ let _89: ();
+ let mut _90: f64;
+ scope 1 {
+ debug i => _1;
+ let _2: u64;
+ scope 2 {
+ debug u => _2;
+ let _3: f64;
+ scope 3 {
+ debug f => _3;
+ }
+ }
+ }
+
+ bb0: {
+- StorageLive(_1);
+ _1 = const 1_i64;
+- StorageLive(_2);
+ _2 = const 1_u64;
+- StorageLive(_3);
+ _3 = const 1f64;
+ StorageLive(_4);
+ StorageLive(_5);
+- StorageLive(_6);
+- _6 = _1;
+- _5 = move _6 as u8 (IntToInt);
+- StorageDead(_6);
++ _5 = const 1_i64 as u8 (IntToInt);
+ _4 = opaque::(move _5) -> [return: bb1, unwind unreachable];
+ }
+
+ bb1: {
+ StorageDead(_5);
+ StorageDead(_4);
+ StorageLive(_7);
+ StorageLive(_8);
+- StorageLive(_9);
+- _9 = _1;
+- _8 = move _9 as u16 (IntToInt);
+- StorageDead(_9);
++ _8 = const 1_i64 as u16 (IntToInt);
+ _7 = opaque::(move _8) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
+ StorageDead(_8);
+ StorageDead(_7);
+ StorageLive(_10);
+ StorageLive(_11);
+- StorageLive(_12);
+- _12 = _1;
+- _11 = move _12 as u32 (IntToInt);
+- StorageDead(_12);
++ _11 = const 1_i64 as u32 (IntToInt);
+ _10 = opaque::(move _11) -> [return: bb3, unwind unreachable];
+ }
+
+ bb3: {
+ StorageDead(_11);
+ StorageDead(_10);
+ StorageLive(_13);
+ StorageLive(_14);
+- StorageLive(_15);
+- _15 = _1;
+- _14 = move _15 as u64 (IntToInt);
+- StorageDead(_15);
++ _14 = const 1_i64 as u64 (IntToInt);
+ _13 = opaque::(move _14) -> [return: bb4, unwind unreachable];
+ }
+
+ bb4: {
+ StorageDead(_14);
+ StorageDead(_13);
+ StorageLive(_16);
+ StorageLive(_17);
+- StorageLive(_18);
+- _18 = _1;
+- _17 = move _18 as i8 (IntToInt);
+- StorageDead(_18);
++ _17 = const 1_i64 as i8 (IntToInt);
+ _16 = opaque::(move _17) -> [return: bb5, unwind unreachable];
+ }
+
+ bb5: {
+ StorageDead(_17);
+ StorageDead(_16);
+ StorageLive(_19);
+ StorageLive(_20);
+- StorageLive(_21);
+- _21 = _1;
+- _20 = move _21 as i16 (IntToInt);
+- StorageDead(_21);
++ _20 = const 1_i64 as i16 (IntToInt);
+ _19 = opaque::(move _20) -> [return: bb6, unwind unreachable];
+ }
+
+ bb6: {
+ StorageDead(_20);
+ StorageDead(_19);
+ StorageLive(_22);
+ StorageLive(_23);
+- StorageLive(_24);
+- _24 = _1;
+- _23 = move _24 as i32 (IntToInt);
+- StorageDead(_24);
++ _23 = const 1_i64 as i32 (IntToInt);
+ _22 = opaque::(move _23) -> [return: bb7, unwind unreachable];
+ }
+
+ bb7: {
+ StorageDead(_23);
+ StorageDead(_22);
+ StorageLive(_25);
+- StorageLive(_26);
+- _26 = _1;
+- _25 = opaque::(move _26) -> [return: bb8, unwind unreachable];
++ _25 = opaque::(const 1_i64) -> [return: bb8, unwind unreachable];
+ }
+
+ bb8: {
+- StorageDead(_26);
+ StorageDead(_25);
+ StorageLive(_27);
+ StorageLive(_28);
+- StorageLive(_29);
+- _29 = _1;
+- _28 = move _29 as f32 (IntToFloat);
+- StorageDead(_29);
++ _28 = const 1_i64 as f32 (IntToFloat);
+ _27 = opaque::(move _28) -> [return: bb9, unwind unreachable];
+ }
+
+ bb9: {
+ StorageDead(_28);
+ StorageDead(_27);
+ StorageLive(_30);
+ StorageLive(_31);
+- StorageLive(_32);
+- _32 = _1;
+- _31 = move _32 as f64 (IntToFloat);
+- StorageDead(_32);
++ _31 = const 1_i64 as f64 (IntToFloat);
+ _30 = opaque::(move _31) -> [return: bb10, unwind unreachable];
+ }
+
+ bb10: {
+ StorageDead(_31);
+ StorageDead(_30);
+ StorageLive(_33);
+ StorageLive(_34);
+- StorageLive(_35);
+- _35 = _2;
+- _34 = move _35 as u8 (IntToInt);
+- StorageDead(_35);
++ _34 = const 1_u64 as u8 (IntToInt);
+ _33 = opaque::(move _34) -> [return: bb11, unwind unreachable];
+ }
+
+ bb11: {
+ StorageDead(_34);
+ StorageDead(_33);
+ StorageLive(_36);
+ StorageLive(_37);
+- StorageLive(_38);
+- _38 = _2;
+- _37 = move _38 as u16 (IntToInt);
+- StorageDead(_38);
++ _37 = const 1_u64 as u16 (IntToInt);
+ _36 = opaque::(move _37) -> [return: bb12, unwind unreachable];
+ }
+
+ bb12: {
+ StorageDead(_37);
+ StorageDead(_36);
+ StorageLive(_39);
+ StorageLive(_40);
+- StorageLive(_41);
+- _41 = _2;
+- _40 = move _41 as u32 (IntToInt);
+- StorageDead(_41);
++ _40 = const 1_u64 as u32 (IntToInt);
+ _39 = opaque::(move _40) -> [return: bb13, unwind unreachable];
+ }
+
+ bb13: {
+ StorageDead(_40);
+ StorageDead(_39);
+ StorageLive(_42);
+- StorageLive(_43);
+- _43 = _2;
+- _42 = opaque::(move _43) -> [return: bb14, unwind unreachable];
++ _42 = opaque::(const 1_u64) -> [return: bb14, unwind unreachable];
+ }
+
+ bb14: {
+- StorageDead(_43);
+ StorageDead(_42);
+ StorageLive(_44);
+ StorageLive(_45);
+- StorageLive(_46);
+- _46 = _2;
+- _45 = move _46 as i8 (IntToInt);
+- StorageDead(_46);
++ _45 = const 1_u64 as i8 (IntToInt);
+ _44 = opaque::(move _45) -> [return: bb15, unwind unreachable];
+ }
+
+ bb15: {
+ StorageDead(_45);
+ StorageDead(_44);
+ StorageLive(_47);
+ StorageLive(_48);
+- StorageLive(_49);
+- _49 = _2;
+- _48 = move _49 as i16 (IntToInt);
+- StorageDead(_49);
++ _48 = const 1_u64 as i16 (IntToInt);
+ _47 = opaque::(move _48) -> [return: bb16, unwind unreachable];
+ }
+
+ bb16: {
+ StorageDead(_48);
+ StorageDead(_47);
+ StorageLive(_50);
+ StorageLive(_51);
+- StorageLive(_52);
+- _52 = _2;
+- _51 = move _52 as i32 (IntToInt);
+- StorageDead(_52);
++ _51 = const 1_u64 as i32 (IntToInt);
+ _50 = opaque::(move _51) -> [return: bb17, unwind unreachable];
+ }
+
+ bb17: {
+ StorageDead(_51);
+ StorageDead(_50);
+ StorageLive(_53);
+ StorageLive(_54);
+- StorageLive(_55);
+- _55 = _2;
+- _54 = move _55 as i64 (IntToInt);
+- StorageDead(_55);
++ _54 = const 1_u64 as i64 (IntToInt);
+ _53 = opaque::(move _54) -> [return: bb18, unwind unreachable];
+ }
+
+ bb18: {
+ StorageDead(_54);
+ StorageDead(_53);
+ StorageLive(_56);
+ StorageLive(_57);
+- StorageLive(_58);
+- _58 = _2;
+- _57 = move _58 as f32 (IntToFloat);
+- StorageDead(_58);
++ _57 = const 1_u64 as f32 (IntToFloat);
+ _56 = opaque::(move _57) -> [return: bb19, unwind unreachable];
+ }
+
+ bb19: {
+ StorageDead(_57);
+ StorageDead(_56);
+ StorageLive(_59);
+ StorageLive(_60);
+- StorageLive(_61);
+- _61 = _2;
+- _60 = move _61 as f64 (IntToFloat);
+- StorageDead(_61);
++ _60 = const 1_u64 as f64 (IntToFloat);
+ _59 = opaque::(move _60) -> [return: bb20, unwind unreachable];
+ }
+
+ bb20: {
+ StorageDead(_60);
+ StorageDead(_59);
+ StorageLive(_62);
+ StorageLive(_63);
+- StorageLive(_64);
+- _64 = _3;
+- _63 = move _64 as u8 (FloatToInt);
+- StorageDead(_64);
++ _63 = const 1f64 as u8 (FloatToInt);
+ _62 = opaque::(move _63) -> [return: bb21, unwind unreachable];
+ }
+
+ bb21: {
+ StorageDead(_63);
+ StorageDead(_62);
+ StorageLive(_65);
+ StorageLive(_66);
+- StorageLive(_67);
+- _67 = _3;
+- _66 = move _67 as u16 (FloatToInt);
+- StorageDead(_67);
++ _66 = const 1f64 as u16 (FloatToInt);
+ _65 = opaque::(move _66) -> [return: bb22, unwind unreachable];
+ }
+
+ bb22: {
+ StorageDead(_66);
+ StorageDead(_65);
+ StorageLive(_68);
+ StorageLive(_69);
+- StorageLive(_70);
+- _70 = _3;
+- _69 = move _70 as u32 (FloatToInt);
+- StorageDead(_70);
++ _69 = const 1f64 as u32 (FloatToInt);
+ _68 = opaque::(move _69) -> [return: bb23, unwind unreachable];
+ }
+
+ bb23: {
+ StorageDead(_69);
+ StorageDead(_68);
+ StorageLive(_71);
+ StorageLive(_72);
+- StorageLive(_73);
+- _73 = _3;
+- _72 = move _73 as u64 (FloatToInt);
+- StorageDead(_73);
++ _72 = const 1f64 as u64 (FloatToInt);
+ _71 = opaque::(move _72) -> [return: bb24, unwind unreachable];
+ }
+
+ bb24: {
+ StorageDead(_72);
+ StorageDead(_71);
+ StorageLive(_74);
+ StorageLive(_75);
+- StorageLive(_76);
+- _76 = _3;
+- _75 = move _76 as i8 (FloatToInt);
+- StorageDead(_76);
++ _75 = const 1f64 as i8 (FloatToInt);
+ _74 = opaque::(move _75) -> [return: bb25, unwind unreachable];
+ }
+
+ bb25: {
+ StorageDead(_75);
+ StorageDead(_74);
+ StorageLive(_77);
+ StorageLive(_78);
+- StorageLive(_79);
+- _79 = _3;
+- _78 = move _79 as i16 (FloatToInt);
+- StorageDead(_79);
++ _78 = const 1f64 as i16 (FloatToInt);
+ _77 = opaque::(move _78) -> [return: bb26, unwind unreachable];
+ }
+
+ bb26: {
+ StorageDead(_78);
+ StorageDead(_77);
+ StorageLive(_80);
+ StorageLive(_81);
+- StorageLive(_82);
+- _82 = _3;
+- _81 = move _82 as i32 (FloatToInt);
+- StorageDead(_82);
++ _81 = const 1f64 as i32 (FloatToInt);
+ _80 = opaque::(move _81) -> [return: bb27, unwind unreachable];
+ }
+
+ bb27: {
+ StorageDead(_81);
+ StorageDead(_80);
+ StorageLive(_83);
+ StorageLive(_84);
+- StorageLive(_85);
+- _85 = _3;
+- _84 = move _85 as i64 (FloatToInt);
+- StorageDead(_85);
++ _84 = const 1f64 as i64 (FloatToInt);
+ _83 = opaque::(move _84) -> [return: bb28, unwind unreachable];
+ }
+
+ bb28: {
+ StorageDead(_84);
+ StorageDead(_83);
+ StorageLive(_86);
+ StorageLive(_87);
+- StorageLive(_88);
+- _88 = _3;
+- _87 = move _88 as f32 (FloatToFloat);
+- StorageDead(_88);
++ _87 = const 1f64 as f32 (FloatToFloat);
+ _86 = opaque::(move _87) -> [return: bb29, unwind unreachable];
+ }
+
+ bb29: {
+ StorageDead(_87);
+ StorageDead(_86);
+ StorageLive(_89);
+- StorageLive(_90);
+- _90 = _3;
+- _89 = opaque::(move _90) -> [return: bb30, unwind unreachable];
++ _89 = opaque::(const 1f64) -> [return: bb30, unwind unreachable];
+ }
+
+ bb30: {
+- StorageDead(_90);
+ StorageDead(_89);
+ _0 = const ();
+- StorageDead(_3);
+- StorageDead(_2);
+- StorageDead(_1);
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff b/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff
new file mode 100644
index 00000000000..33192ed8de0
--- /dev/null
+++ b/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff
@@ -0,0 +1,501 @@
+- // MIR for `cast` before GVN
++ // MIR for `cast` after GVN
+
+ fn cast() -> () {
+ let mut _0: ();
+ let _1: i64;
+ let _4: ();
+ let mut _5: u8;
+ let mut _6: i64;
+ let _7: ();
+ let mut _8: u16;
+ let mut _9: i64;
+ let _10: ();
+ let mut _11: u32;
+ let mut _12: i64;
+ let _13: ();
+ let mut _14: u64;
+ let mut _15: i64;
+ let _16: ();
+ let mut _17: i8;
+ let mut _18: i64;
+ let _19: ();
+ let mut _20: i16;
+ let mut _21: i64;
+ let _22: ();
+ let mut _23: i32;
+ let mut _24: i64;
+ let _25: ();
+ let mut _26: i64;
+ let _27: ();
+ let mut _28: f32;
+ let mut _29: i64;
+ let _30: ();
+ let mut _31: f64;
+ let mut _32: i64;
+ let _33: ();
+ let mut _34: u8;
+ let mut _35: u64;
+ let _36: ();
+ let mut _37: u16;
+ let mut _38: u64;
+ let _39: ();
+ let mut _40: u32;
+ let mut _41: u64;
+ let _42: ();
+ let mut _43: u64;
+ let _44: ();
+ let mut _45: i8;
+ let mut _46: u64;
+ let _47: ();
+ let mut _48: i16;
+ let mut _49: u64;
+ let _50: ();
+ let mut _51: i32;
+ let mut _52: u64;
+ let _53: ();
+ let mut _54: i64;
+ let mut _55: u64;
+ let _56: ();
+ let mut _57: f32;
+ let mut _58: u64;
+ let _59: ();
+ let mut _60: f64;
+ let mut _61: u64;
+ let _62: ();
+ let mut _63: u8;
+ let mut _64: f64;
+ let _65: ();
+ let mut _66: u16;
+ let mut _67: f64;
+ let _68: ();
+ let mut _69: u32;
+ let mut _70: f64;
+ let _71: ();
+ let mut _72: u64;
+ let mut _73: f64;
+ let _74: ();
+ let mut _75: i8;
+ let mut _76: f64;
+ let _77: ();
+ let mut _78: i16;
+ let mut _79: f64;
+ let _80: ();
+ let mut _81: i32;
+ let mut _82: f64;
+ let _83: ();
+ let mut _84: i64;
+ let mut _85: f64;
+ let _86: ();
+ let mut _87: f32;
+ let mut _88: f64;
+ let _89: ();
+ let mut _90: f64;
+ scope 1 {
+ debug i => _1;
+ let _2: u64;
+ scope 2 {
+ debug u => _2;
+ let _3: f64;
+ scope 3 {
+ debug f => _3;
+ }
+ }
+ }
+
+ bb0: {
+- StorageLive(_1);
+ _1 = const 1_i64;
+- StorageLive(_2);
+ _2 = const 1_u64;
+- StorageLive(_3);
+ _3 = const 1f64;
+ StorageLive(_4);
+ StorageLive(_5);
+- StorageLive(_6);
+- _6 = _1;
+- _5 = move _6 as u8 (IntToInt);
+- StorageDead(_6);
++ _5 = const 1_i64 as u8 (IntToInt);
+ _4 = opaque::(move _5) -> [return: bb1, unwind continue];
+ }
+
+ bb1: {
+ StorageDead(_5);
+ StorageDead(_4);
+ StorageLive(_7);
+ StorageLive(_8);
+- StorageLive(_9);
+- _9 = _1;
+- _8 = move _9 as u16 (IntToInt);
+- StorageDead(_9);
++ _8 = const 1_i64 as u16 (IntToInt);
+ _7 = opaque::(move _8) -> [return: bb2, unwind continue];
+ }
+
+ bb2: {
+ StorageDead(_8);
+ StorageDead(_7);
+ StorageLive(_10);
+ StorageLive(_11);
+- StorageLive(_12);
+- _12 = _1;
+- _11 = move _12 as u32 (IntToInt);
+- StorageDead(_12);
++ _11 = const 1_i64 as u32 (IntToInt);
+ _10 = opaque::(move _11) -> [return: bb3, unwind continue];
+ }
+
+ bb3: {
+ StorageDead(_11);
+ StorageDead(_10);
+ StorageLive(_13);
+ StorageLive(_14);
+- StorageLive(_15);
+- _15 = _1;
+- _14 = move _15 as u64 (IntToInt);
+- StorageDead(_15);
++ _14 = const 1_i64 as u64 (IntToInt);
+ _13 = opaque::(move _14) -> [return: bb4, unwind continue];
+ }
+
+ bb4: {
+ StorageDead(_14);
+ StorageDead(_13);
+ StorageLive(_16);
+ StorageLive(_17);
+- StorageLive(_18);
+- _18 = _1;
+- _17 = move _18 as i8 (IntToInt);
+- StorageDead(_18);
++ _17 = const 1_i64 as i8 (IntToInt);
+ _16 = opaque::(move _17) -> [return: bb5, unwind continue];
+ }
+
+ bb5: {
+ StorageDead(_17);
+ StorageDead(_16);
+ StorageLive(_19);
+ StorageLive(_20);
+- StorageLive(_21);
+- _21 = _1;
+- _20 = move _21 as i16 (IntToInt);
+- StorageDead(_21);
++ _20 = const 1_i64 as i16 (IntToInt);
+ _19 = opaque::(move _20) -> [return: bb6, unwind continue];
+ }
+
+ bb6: {
+ StorageDead(_20);
+ StorageDead(_19);
+ StorageLive(_22);
+ StorageLive(_23);
+- StorageLive(_24);
+- _24 = _1;
+- _23 = move _24 as i32 (IntToInt);
+- StorageDead(_24);
++ _23 = const 1_i64 as i32 (IntToInt);
+ _22 = opaque::(move _23) -> [return: bb7, unwind continue];
+ }
+
+ bb7: {
+ StorageDead(_23);
+ StorageDead(_22);
+ StorageLive(_25);
+- StorageLive(_26);
+- _26 = _1;
+- _25 = opaque::(move _26) -> [return: bb8, unwind continue];
++ _25 = opaque::(const 1_i64) -> [return: bb8, unwind continue];
+ }
+
+ bb8: {
+- StorageDead(_26);
+ StorageDead(_25);
+ StorageLive(_27);
+ StorageLive(_28);
+- StorageLive(_29);
+- _29 = _1;
+- _28 = move _29 as f32 (IntToFloat);
+- StorageDead(_29);
++ _28 = const 1_i64 as f32 (IntToFloat);
+ _27 = opaque::(move _28) -> [return: bb9, unwind continue];
+ }
+
+ bb9: {
+ StorageDead(_28);
+ StorageDead(_27);
+ StorageLive(_30);
+ StorageLive(_31);
+- StorageLive(_32);
+- _32 = _1;
+- _31 = move _32 as f64 (IntToFloat);
+- StorageDead(_32);
++ _31 = const 1_i64 as f64 (IntToFloat);
+ _30 = opaque::(move _31) -> [return: bb10, unwind continue];
+ }
+
+ bb10: {
+ StorageDead(_31);
+ StorageDead(_30);
+ StorageLive(_33);
+ StorageLive(_34);
+- StorageLive(_35);
+- _35 = _2;
+- _34 = move _35 as u8 (IntToInt);
+- StorageDead(_35);
++ _34 = const 1_u64 as u8 (IntToInt);
+ _33 = opaque::(move _34) -> [return: bb11, unwind continue];
+ }
+
+ bb11: {
+ StorageDead(_34);
+ StorageDead(_33);
+ StorageLive(_36);
+ StorageLive(_37);
+- StorageLive(_38);
+- _38 = _2;
+- _37 = move _38 as u16 (IntToInt);
+- StorageDead(_38);
++ _37 = const 1_u64 as u16 (IntToInt);
+ _36 = opaque::(move _37) -> [return: bb12, unwind continue];
+ }
+
+ bb12: {
+ StorageDead(_37);
+ StorageDead(_36);
+ StorageLive(_39);
+ StorageLive(_40);
+- StorageLive(_41);
+- _41 = _2;
+- _40 = move _41 as u32 (IntToInt);
+- StorageDead(_41);
++ _40 = const 1_u64 as u32 (IntToInt);
+ _39 = opaque::(move _40) -> [return: bb13, unwind continue];
+ }
+
+ bb13: {
+ StorageDead(_40);
+ StorageDead(_39);
+ StorageLive(_42);
+- StorageLive(_43);
+- _43 = _2;
+- _42 = opaque::(move _43) -> [return: bb14, unwind continue];
++ _42 = opaque::(const 1_u64) -> [return: bb14, unwind continue];
+ }
+
+ bb14: {
+- StorageDead(_43);
+ StorageDead(_42);
+ StorageLive(_44);
+ StorageLive(_45);
+- StorageLive(_46);
+- _46 = _2;
+- _45 = move _46 as i8 (IntToInt);
+- StorageDead(_46);
++ _45 = const 1_u64 as i8 (IntToInt);
+ _44 = opaque::(move _45) -> [return: bb15, unwind continue];
+ }
+
+ bb15: {
+ StorageDead(_45);
+ StorageDead(_44);
+ StorageLive(_47);
+ StorageLive(_48);
+- StorageLive(_49);
+- _49 = _2;
+- _48 = move _49 as i16 (IntToInt);
+- StorageDead(_49);
++ _48 = const 1_u64 as i16 (IntToInt);
+ _47 = opaque::(move _48) -> [return: bb16, unwind continue];
+ }
+
+ bb16: {
+ StorageDead(_48);
+ StorageDead(_47);
+ StorageLive(_50);
+ StorageLive(_51);
+- StorageLive(_52);
+- _52 = _2;
+- _51 = move _52 as i32 (IntToInt);
+- StorageDead(_52);
++ _51 = const 1_u64 as i32 (IntToInt);
+ _50 = opaque::(move _51) -> [return: bb17, unwind continue];
+ }
+
+ bb17: {
+ StorageDead(_51);
+ StorageDead(_50);
+ StorageLive(_53);
+ StorageLive(_54);
+- StorageLive(_55);
+- _55 = _2;
+- _54 = move _55 as i64 (IntToInt);
+- StorageDead(_55);
++ _54 = const 1_u64 as i64 (IntToInt);
+ _53 = opaque::(move _54) -> [return: bb18, unwind continue];
+ }
+
+ bb18: {
+ StorageDead(_54);
+ StorageDead(_53);
+ StorageLive(_56);
+ StorageLive(_57);
+- StorageLive(_58);
+- _58 = _2;
+- _57 = move _58 as f32 (IntToFloat);
+- StorageDead(_58);
++ _57 = const 1_u64 as f32 (IntToFloat);
+ _56 = opaque::(move _57) -> [return: bb19, unwind continue];
+ }
+
+ bb19: {
+ StorageDead(_57);
+ StorageDead(_56);
+ StorageLive(_59);
+ StorageLive(_60);
+- StorageLive(_61);
+- _61 = _2;
+- _60 = move _61 as f64 (IntToFloat);
+- StorageDead(_61);
++ _60 = const 1_u64 as f64 (IntToFloat);
+ _59 = opaque::(move _60) -> [return: bb20, unwind continue];
+ }
+
+ bb20: {
+ StorageDead(_60);
+ StorageDead(_59);
+ StorageLive(_62);
+ StorageLive(_63);
+- StorageLive(_64);
+- _64 = _3;
+- _63 = move _64 as u8 (FloatToInt);
+- StorageDead(_64);
++ _63 = const 1f64 as u8 (FloatToInt);
+ _62 = opaque::(move _63) -> [return: bb21, unwind continue];
+ }
+
+ bb21: {
+ StorageDead(_63);
+ StorageDead(_62);
+ StorageLive(_65);
+ StorageLive(_66);
+- StorageLive(_67);
+- _67 = _3;
+- _66 = move _67 as u16 (FloatToInt);
+- StorageDead(_67);
++ _66 = const 1f64 as u16 (FloatToInt);
+ _65 = opaque::(move _66) -> [return: bb22, unwind continue];
+ }
+
+ bb22: {
+ StorageDead(_66);
+ StorageDead(_65);
+ StorageLive(_68);
+ StorageLive(_69);
+- StorageLive(_70);
+- _70 = _3;
+- _69 = move _70 as u32 (FloatToInt);
+- StorageDead(_70);
++ _69 = const 1f64 as u32 (FloatToInt);
+ _68 = opaque::(move _69) -> [return: bb23, unwind continue];
+ }
+
+ bb23: {
+ StorageDead(_69);
+ StorageDead(_68);
+ StorageLive(_71);
+ StorageLive(_72);
+- StorageLive(_73);
+- _73 = _3;
+- _72 = move _73 as u64 (FloatToInt);
+- StorageDead(_73);
++ _72 = const 1f64 as u64 (FloatToInt);
+ _71 = opaque::(move _72) -> [return: bb24, unwind continue];
+ }
+
+ bb24: {
+ StorageDead(_72);
+ StorageDead(_71);
+ StorageLive(_74);
+ StorageLive(_75);
+- StorageLive(_76);
+- _76 = _3;
+- _75 = move _76 as i8 (FloatToInt);
+- StorageDead(_76);
++ _75 = const 1f64 as i8 (FloatToInt);
+ _74 = opaque::(move _75) -> [return: bb25, unwind continue];
+ }
+
+ bb25: {
+ StorageDead(_75);
+ StorageDead(_74);
+ StorageLive(_77);
+ StorageLive(_78);
+- StorageLive(_79);
+- _79 = _3;
+- _78 = move _79 as i16 (FloatToInt);
+- StorageDead(_79);
++ _78 = const 1f64 as i16 (FloatToInt);
+ _77 = opaque::(move _78) -> [return: bb26, unwind continue];
+ }
+
+ bb26: {
+ StorageDead(_78);
+ StorageDead(_77);
+ StorageLive(_80);
+ StorageLive(_81);
+- StorageLive(_82);
+- _82 = _3;
+- _81 = move _82 as i32 (FloatToInt);
+- StorageDead(_82);
++ _81 = const 1f64 as i32 (FloatToInt);
+ _80 = opaque::(move _81) -> [return: bb27, unwind continue];
+ }
+
+ bb27: {
+ StorageDead(_81);
+ StorageDead(_80);
+ StorageLive(_83);
+ StorageLive(_84);
+- StorageLive(_85);
+- _85 = _3;
+- _84 = move _85 as i64 (FloatToInt);
+- StorageDead(_85);
++ _84 = const 1f64 as i64 (FloatToInt);
+ _83 = opaque::(move _84) -> [return: bb28, unwind continue];
+ }
+
+ bb28: {
+ StorageDead(_84);
+ StorageDead(_83);
+ StorageLive(_86);
+ StorageLive(_87);
+- StorageLive(_88);
+- _88 = _3;
+- _87 = move _88 as f32 (FloatToFloat);
+- StorageDead(_88);
++ _87 = const 1f64 as f32 (FloatToFloat);
+ _86 = opaque::(move _87) -> [return: bb29, unwind continue];
+ }
+
+ bb29: {
+ StorageDead(_87);
+ StorageDead(_86);
+ StorageLive(_89);
+- StorageLive(_90);
+- _90 = _3;
+- _89 = opaque::(move _90) -> [return: bb30, unwind continue];
++ _89 = opaque::(const 1f64) -> [return: bb30, unwind continue];
+ }
+
+ bb30: {
+- StorageDead(_90);
+ StorageDead(_89);
+ _0 = const ();
+- StorageDead(_3);
+- StorageDead(_2);
+- StorageDead(_1);
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.dereferences.GVN.panic-abort.diff b/tests/mir-opt/gvn.dereferences.GVN.panic-abort.diff
new file mode 100644
index 00000000000..ee320cf6787
--- /dev/null
+++ b/tests/mir-opt/gvn.dereferences.GVN.panic-abort.diff
@@ -0,0 +1,191 @@
+- // MIR for `dereferences` before GVN
++ // MIR for `dereferences` after GVN
+
+ fn dereferences(_1: &mut u32, _2: &impl Copy, _3: &S) -> () {
+ debug t => _1;
+ debug u => _2;
+ debug s => _3;
+ let mut _0: ();
+ let _4: ();
+ let mut _5: u32;
+ let _6: ();
+ let mut _7: u32;
+ let _8: *const u32;
+ let _9: ();
+ let mut _10: u32;
+ let _11: ();
+ let mut _12: u32;
+ let _14: ();
+ let mut _15: u32;
+ let _16: ();
+ let mut _17: u32;
+ let _19: ();
+ let mut _20: u32;
+ let _21: ();
+ let mut _22: u32;
+ let _23: ();
+ let mut _24: &u32;
+ let _25: ();
+ let mut _26: impl Copy;
+ let _27: ();
+ let mut _28: impl Copy;
+ let _29: ();
+ let mut _30: u32;
+ let _31: ();
+ let mut _32: u32;
+ scope 1 {
+ debug z => _8;
+ let _13: *mut u32;
+ scope 2 {
+ }
+ scope 3 {
+ }
+ scope 4 {
+ debug z => _13;
+ let _18: &u32;
+ scope 5 {
+ }
+ scope 6 {
+ }
+ scope 7 {
+ debug z => _18;
+ }
+ }
+ }
+
+ bb0: {
+ StorageLive(_4);
+ StorageLive(_5);
+ _5 = (*_1);
+ _4 = opaque::(move _5) -> [return: bb1, unwind unreachable];
+ }
+
+ bb1: {
+ StorageDead(_5);
+ StorageDead(_4);
+ StorageLive(_6);
+ StorageLive(_7);
+ _7 = (*_1);
+ _6 = opaque::(move _7) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
+ StorageDead(_7);
+ StorageDead(_6);
+ StorageLive(_8);
+ _8 = &raw const (*_1);
+ StorageLive(_9);
+ StorageLive(_10);
+ _10 = (*_8);
+ _9 = opaque::(move _10) -> [return: bb3, unwind unreachable];
+ }
+
+ bb3: {
+ StorageDead(_10);
+ StorageDead(_9);
+ StorageLive(_11);
+ StorageLive(_12);
+ _12 = (*_8);
+ _11 = opaque::(move _12) -> [return: bb4, unwind unreachable];
+ }
+
+ bb4: {
+ StorageDead(_12);
+ StorageDead(_11);
+ StorageLive(_13);
+ _13 = &raw mut (*_1);
+ StorageLive(_14);
+ StorageLive(_15);
+ _15 = (*_13);
+ _14 = opaque::(move _15) -> [return: bb5, unwind unreachable];
+ }
+
+ bb5: {
+ StorageDead(_15);
+ StorageDead(_14);
+ StorageLive(_16);
+ StorageLive(_17);
+ _17 = (*_13);
+ _16 = opaque::(move _17) -> [return: bb6, unwind unreachable];
+ }
+
+ bb6: {
+ StorageDead(_17);
+ StorageDead(_16);
+ StorageLive(_18);
+ _18 = &(*_1);
+ StorageLive(_19);
+- StorageLive(_20);
+ _20 = (*_18);
+- _19 = opaque::(move _20) -> [return: bb7, unwind unreachable];
++ _19 = opaque::(_20) -> [return: bb7, unwind unreachable];
+ }
+
+ bb7: {
+- StorageDead(_20);
+ StorageDead(_19);
+ StorageLive(_21);
+- StorageLive(_22);
+- _22 = (*_18);
+- _21 = opaque::(move _22) -> [return: bb8, unwind unreachable];
++ _21 = opaque::(_20) -> [return: bb8, unwind unreachable];
+ }
+
+ bb8: {
+- StorageDead(_22);
+ StorageDead(_21);
+ StorageLive(_23);
+ StorageLive(_24);
+ _24 = &(*_18);
+ _23 = opaque::<&u32>(move _24) -> [return: bb9, unwind unreachable];
+ }
+
+ bb9: {
+ StorageDead(_24);
+ StorageDead(_23);
+ StorageLive(_25);
+ StorageLive(_26);
+ _26 = (*_2);
+ _25 = opaque::(move _26) -> [return: bb10, unwind unreachable];
+ }
+
+ bb10: {
+ StorageDead(_26);
+ StorageDead(_25);
+ StorageLive(_27);
+ StorageLive(_28);
+ _28 = (*_2);
+ _27 = opaque::(move _28) -> [return: bb11, unwind unreachable];
+ }
+
+ bb11: {
+ StorageDead(_28);
+ StorageDead(_27);
+ StorageLive(_29);
+- StorageLive(_30);
+ _30 = ((*_3).0: u32);
+- _29 = opaque::(move _30) -> [return: bb12, unwind unreachable];
++ _29 = opaque::(_30) -> [return: bb12, unwind unreachable];
+ }
+
+ bb12: {
+- StorageDead(_30);
+ StorageDead(_29);
+ StorageLive(_31);
+- StorageLive(_32);
+- _32 = ((*_3).0: u32);
+- _31 = opaque::(move _32) -> [return: bb13, unwind unreachable];
++ _31 = opaque::(_30) -> [return: bb13, unwind unreachable];
+ }
+
+ bb13: {
+- StorageDead(_32);
+ StorageDead(_31);
+ _0 = const ();
+ StorageDead(_18);
+ StorageDead(_13);
+ StorageDead(_8);
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff b/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff
new file mode 100644
index 00000000000..f627b4d5988
--- /dev/null
+++ b/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff
@@ -0,0 +1,191 @@
+- // MIR for `dereferences` before GVN
++ // MIR for `dereferences` after GVN
+
+ fn dereferences(_1: &mut u32, _2: &impl Copy, _3: &S) -> () {
+ debug t => _1;
+ debug u => _2;
+ debug s => _3;
+ let mut _0: ();
+ let _4: ();
+ let mut _5: u32;
+ let _6: ();
+ let mut _7: u32;
+ let _8: *const u32;
+ let _9: ();
+ let mut _10: u32;
+ let _11: ();
+ let mut _12: u32;
+ let _14: ();
+ let mut _15: u32;
+ let _16: ();
+ let mut _17: u32;
+ let _19: ();
+ let mut _20: u32;
+ let _21: ();
+ let mut _22: u32;
+ let _23: ();
+ let mut _24: &u32;
+ let _25: ();
+ let mut _26: impl Copy;
+ let _27: ();
+ let mut _28: impl Copy;
+ let _29: ();
+ let mut _30: u32;
+ let _31: ();
+ let mut _32: u32;
+ scope 1 {
+ debug z => _8;
+ let _13: *mut u32;
+ scope 2 {
+ }
+ scope 3 {
+ }
+ scope 4 {
+ debug z => _13;
+ let _18: &u32;
+ scope 5 {
+ }
+ scope 6 {
+ }
+ scope 7 {
+ debug z => _18;
+ }
+ }
+ }
+
+ bb0: {
+ StorageLive(_4);
+ StorageLive(_5);
+ _5 = (*_1);
+ _4 = opaque::(move _5) -> [return: bb1, unwind continue];
+ }
+
+ bb1: {
+ StorageDead(_5);
+ StorageDead(_4);
+ StorageLive(_6);
+ StorageLive(_7);
+ _7 = (*_1);
+ _6 = opaque::(move _7) -> [return: bb2, unwind continue];
+ }
+
+ bb2: {
+ StorageDead(_7);
+ StorageDead(_6);
+ StorageLive(_8);
+ _8 = &raw const (*_1);
+ StorageLive(_9);
+ StorageLive(_10);
+ _10 = (*_8);
+ _9 = opaque::(move _10) -> [return: bb3, unwind continue];
+ }
+
+ bb3: {
+ StorageDead(_10);
+ StorageDead(_9);
+ StorageLive(_11);
+ StorageLive(_12);
+ _12 = (*_8);
+ _11 = opaque::(move _12) -> [return: bb4, unwind continue];
+ }
+
+ bb4: {
+ StorageDead(_12);
+ StorageDead(_11);
+ StorageLive(_13);
+ _13 = &raw mut (*_1);
+ StorageLive(_14);
+ StorageLive(_15);
+ _15 = (*_13);
+ _14 = opaque::(move _15) -> [return: bb5, unwind continue];
+ }
+
+ bb5: {
+ StorageDead(_15);
+ StorageDead(_14);
+ StorageLive(_16);
+ StorageLive(_17);
+ _17 = (*_13);
+ _16 = opaque::(move _17) -> [return: bb6, unwind continue];
+ }
+
+ bb6: {
+ StorageDead(_17);
+ StorageDead(_16);
+ StorageLive(_18);
+ _18 = &(*_1);
+ StorageLive(_19);
+- StorageLive(_20);
+ _20 = (*_18);
+- _19 = opaque::(move _20) -> [return: bb7, unwind continue];
++ _19 = opaque::(_20) -> [return: bb7, unwind continue];
+ }
+
+ bb7: {
+- StorageDead(_20);
+ StorageDead(_19);
+ StorageLive(_21);
+- StorageLive(_22);
+- _22 = (*_18);
+- _21 = opaque::(move _22) -> [return: bb8, unwind continue];
++ _21 = opaque::(_20) -> [return: bb8, unwind continue];
+ }
+
+ bb8: {
+- StorageDead(_22);
+ StorageDead(_21);
+ StorageLive(_23);
+ StorageLive(_24);
+ _24 = &(*_18);
+ _23 = opaque::<&u32>(move _24) -> [return: bb9, unwind continue];
+ }
+
+ bb9: {
+ StorageDead(_24);
+ StorageDead(_23);
+ StorageLive(_25);
+ StorageLive(_26);
+ _26 = (*_2);
+ _25 = opaque::(move _26) -> [return: bb10, unwind continue];
+ }
+
+ bb10: {
+ StorageDead(_26);
+ StorageDead(_25);
+ StorageLive(_27);
+ StorageLive(_28);
+ _28 = (*_2);
+ _27 = opaque::(move _28) -> [return: bb11, unwind continue];
+ }
+
+ bb11: {
+ StorageDead(_28);
+ StorageDead(_27);
+ StorageLive(_29);
+- StorageLive(_30);
+ _30 = ((*_3).0: u32);
+- _29 = opaque::(move _30) -> [return: bb12, unwind continue];
++ _29 = opaque::(_30) -> [return: bb12, unwind continue];
+ }
+
+ bb12: {
+- StorageDead(_30);
+ StorageDead(_29);
+ StorageLive(_31);
+- StorageLive(_32);
+- _32 = ((*_3).0: u32);
+- _31 = opaque::(move _32) -> [return: bb13, unwind continue];
++ _31 = opaque::(_30) -> [return: bb13, unwind continue];
+ }
+
+ bb13: {
+- StorageDead(_32);
+ StorageDead(_31);
+ _0 = const ();
+ StorageDead(_18);
+ StorageDead(_13);
+ StorageDead(_8);
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.multiple_branches.GVN.panic-abort.diff b/tests/mir-opt/gvn.multiple_branches.GVN.panic-abort.diff
new file mode 100644
index 00000000000..0a66900283b
--- /dev/null
+++ b/tests/mir-opt/gvn.multiple_branches.GVN.panic-abort.diff
@@ -0,0 +1,198 @@
+- // MIR for `multiple_branches` before GVN
++ // MIR for `multiple_branches` after GVN
+
+ fn multiple_branches(_1: bool, _2: u8, _3: u8) -> () {
+ debug t => _1;
+ debug x => _2;
+ debug y => _3;
+ let mut _0: ();
+ let _4: ();
+ let mut _5: bool;
+ let _6: ();
+ let mut _7: u8;
+ let mut _8: u8;
+ let mut _9: u8;
+ let _10: ();
+ let mut _11: u8;
+ let mut _12: u8;
+ let mut _13: u8;
+ let _14: ();
+ let mut _15: u8;
+ let mut _16: u8;
+ let mut _17: u8;
+ let _18: ();
+ let mut _19: u8;
+ let mut _20: u8;
+ let mut _21: u8;
+ let _22: ();
+ let mut _23: u8;
+ let mut _24: u8;
+ let mut _25: u8;
+ let mut _26: bool;
+ let _27: ();
+ let mut _28: u8;
+ let mut _29: u8;
+ let mut _30: u8;
+ let _31: ();
+ let mut _32: u8;
+ let mut _33: u8;
+ let mut _34: u8;
+
+ bb0: {
+- StorageLive(_4);
+- StorageLive(_5);
+- _5 = _1;
+- switchInt(move _5) -> [0: bb4, otherwise: bb1];
++ switchInt(_1) -> [0: bb4, otherwise: bb1];
+ }
+
+ bb1: {
+ StorageLive(_6);
+- StorageLive(_7);
+- StorageLive(_8);
+- _8 = _2;
+- StorageLive(_9);
+- _9 = _3;
+- _7 = Add(move _8, move _9);
+- StorageDead(_9);
+- StorageDead(_8);
+- _6 = opaque::(move _7) -> [return: bb2, unwind unreachable];
++ _7 = Add(_2, _3);
++ _6 = opaque::(_7) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
+- StorageDead(_7);
+ StorageDead(_6);
+ StorageLive(_10);
+- StorageLive(_11);
+- StorageLive(_12);
+- _12 = _2;
+- StorageLive(_13);
+- _13 = _3;
+- _11 = Add(move _12, move _13);
+- StorageDead(_13);
+- StorageDead(_12);
+- _10 = opaque::(move _11) -> [return: bb3, unwind unreachable];
++ _10 = opaque::(_7) -> [return: bb3, unwind unreachable];
+ }
+
+ bb3: {
+- StorageDead(_11);
+ StorageDead(_10);
+- _4 = const ();
+ goto -> bb7;
+ }
+
+ bb4: {
+ StorageLive(_14);
+- StorageLive(_15);
+- StorageLive(_16);
+- _16 = _2;
+- StorageLive(_17);
+- _17 = _3;
+- _15 = Add(move _16, move _17);
+- StorageDead(_17);
+- StorageDead(_16);
+- _14 = opaque::(move _15) -> [return: bb5, unwind unreachable];
++ _15 = Add(_2, _3);
++ _14 = opaque::(_15) -> [return: bb5, unwind unreachable];
+ }
+
+ bb5: {
+- StorageDead(_15);
+ StorageDead(_14);
+ StorageLive(_18);
+- StorageLive(_19);
+- StorageLive(_20);
+- _20 = _2;
+- StorageLive(_21);
+- _21 = _3;
+- _19 = Add(move _20, move _21);
+- StorageDead(_21);
+- StorageDead(_20);
+- _18 = opaque::(move _19) -> [return: bb6, unwind unreachable];
++ _18 = opaque::(_15) -> [return: bb6, unwind unreachable];
+ }
+
+ bb6: {
+- StorageDead(_19);
+ StorageDead(_18);
+- _4 = const ();
+ goto -> bb7;
+ }
+
+ bb7: {
+- StorageDead(_5);
+- StorageDead(_4);
+ StorageLive(_22);
+- StorageLive(_23);
+- StorageLive(_24);
+- _24 = _2;
+- StorageLive(_25);
+- _25 = _3;
+- _23 = Add(move _24, move _25);
+- StorageDead(_25);
+- StorageDead(_24);
+- _22 = opaque::(move _23) -> [return: bb8, unwind unreachable];
++ _23 = Add(_2, _3);
++ _22 = opaque::(_23) -> [return: bb8, unwind unreachable];
+ }
+
+ bb8: {
+- StorageDead(_23);
+ StorageDead(_22);
+- StorageLive(_26);
+- _26 = _1;
+- switchInt(move _26) -> [0: bb11, otherwise: bb9];
++ switchInt(_1) -> [0: bb11, otherwise: bb9];
+ }
+
+ bb9: {
+ StorageLive(_27);
+- StorageLive(_28);
+- StorageLive(_29);
+- _29 = _2;
+- StorageLive(_30);
+- _30 = _3;
+- _28 = Add(move _29, move _30);
+- StorageDead(_30);
+- StorageDead(_29);
+- _27 = opaque::(move _28) -> [return: bb10, unwind unreachable];
++ _27 = opaque::(_23) -> [return: bb10, unwind unreachable];
+ }
+
+ bb10: {
+- StorageDead(_28);
+ StorageDead(_27);
+ _0 = const ();
+ goto -> bb13;
+ }
+
+ bb11: {
+ StorageLive(_31);
+- StorageLive(_32);
+- StorageLive(_33);
+- _33 = _2;
+- StorageLive(_34);
+- _34 = _3;
+- _32 = Add(move _33, move _34);
+- StorageDead(_34);
+- StorageDead(_33);
+- _31 = opaque::(move _32) -> [return: bb12, unwind unreachable];
++ _31 = opaque::(_23) -> [return: bb12, unwind unreachable];
+ }
+
+ bb12: {
+- StorageDead(_32);
+ StorageDead(_31);
+ _0 = const ();
+ goto -> bb13;
+ }
+
+ bb13: {
+- StorageDead(_26);
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.multiple_branches.GVN.panic-unwind.diff b/tests/mir-opt/gvn.multiple_branches.GVN.panic-unwind.diff
new file mode 100644
index 00000000000..0199f2720a9
--- /dev/null
+++ b/tests/mir-opt/gvn.multiple_branches.GVN.panic-unwind.diff
@@ -0,0 +1,198 @@
+- // MIR for `multiple_branches` before GVN
++ // MIR for `multiple_branches` after GVN
+
+ fn multiple_branches(_1: bool, _2: u8, _3: u8) -> () {
+ debug t => _1;
+ debug x => _2;
+ debug y => _3;
+ let mut _0: ();
+ let _4: ();
+ let mut _5: bool;
+ let _6: ();
+ let mut _7: u8;
+ let mut _8: u8;
+ let mut _9: u8;
+ let _10: ();
+ let mut _11: u8;
+ let mut _12: u8;
+ let mut _13: u8;
+ let _14: ();
+ let mut _15: u8;
+ let mut _16: u8;
+ let mut _17: u8;
+ let _18: ();
+ let mut _19: u8;
+ let mut _20: u8;
+ let mut _21: u8;
+ let _22: ();
+ let mut _23: u8;
+ let mut _24: u8;
+ let mut _25: u8;
+ let mut _26: bool;
+ let _27: ();
+ let mut _28: u8;
+ let mut _29: u8;
+ let mut _30: u8;
+ let _31: ();
+ let mut _32: u8;
+ let mut _33: u8;
+ let mut _34: u8;
+
+ bb0: {
+- StorageLive(_4);
+- StorageLive(_5);
+- _5 = _1;
+- switchInt(move _5) -> [0: bb4, otherwise: bb1];
++ switchInt(_1) -> [0: bb4, otherwise: bb1];
+ }
+
+ bb1: {
+ StorageLive(_6);
+- StorageLive(_7);
+- StorageLive(_8);
+- _8 = _2;
+- StorageLive(_9);
+- _9 = _3;
+- _7 = Add(move _8, move _9);
+- StorageDead(_9);
+- StorageDead(_8);
+- _6 = opaque::(move _7) -> [return: bb2, unwind continue];
++ _7 = Add(_2, _3);
++ _6 = opaque::(_7) -> [return: bb2, unwind continue];
+ }
+
+ bb2: {
+- StorageDead(_7);
+ StorageDead(_6);
+ StorageLive(_10);
+- StorageLive(_11);
+- StorageLive(_12);
+- _12 = _2;
+- StorageLive(_13);
+- _13 = _3;
+- _11 = Add(move _12, move _13);
+- StorageDead(_13);
+- StorageDead(_12);
+- _10 = opaque::(move _11) -> [return: bb3, unwind continue];
++ _10 = opaque::(_7) -> [return: bb3, unwind continue];
+ }
+
+ bb3: {
+- StorageDead(_11);
+ StorageDead(_10);
+- _4 = const ();
+ goto -> bb7;
+ }
+
+ bb4: {
+ StorageLive(_14);
+- StorageLive(_15);
+- StorageLive(_16);
+- _16 = _2;
+- StorageLive(_17);
+- _17 = _3;
+- _15 = Add(move _16, move _17);
+- StorageDead(_17);
+- StorageDead(_16);
+- _14 = opaque::(move _15) -> [return: bb5, unwind continue];
++ _15 = Add(_2, _3);
++ _14 = opaque::(_15) -> [return: bb5, unwind continue];
+ }
+
+ bb5: {
+- StorageDead(_15);
+ StorageDead(_14);
+ StorageLive(_18);
+- StorageLive(_19);
+- StorageLive(_20);
+- _20 = _2;
+- StorageLive(_21);
+- _21 = _3;
+- _19 = Add(move _20, move _21);
+- StorageDead(_21);
+- StorageDead(_20);
+- _18 = opaque::(move _19) -> [return: bb6, unwind continue];
++ _18 = opaque::(_15) -> [return: bb6, unwind continue];
+ }
+
+ bb6: {
+- StorageDead(_19);
+ StorageDead(_18);
+- _4 = const ();
+ goto -> bb7;
+ }
+
+ bb7: {
+- StorageDead(_5);
+- StorageDead(_4);
+ StorageLive(_22);
+- StorageLive(_23);
+- StorageLive(_24);
+- _24 = _2;
+- StorageLive(_25);
+- _25 = _3;
+- _23 = Add(move _24, move _25);
+- StorageDead(_25);
+- StorageDead(_24);
+- _22 = opaque::(move _23) -> [return: bb8, unwind continue];
++ _23 = Add(_2, _3);
++ _22 = opaque::(_23) -> [return: bb8, unwind continue];
+ }
+
+ bb8: {
+- StorageDead(_23);
+ StorageDead(_22);
+- StorageLive(_26);
+- _26 = _1;
+- switchInt(move _26) -> [0: bb11, otherwise: bb9];
++ switchInt(_1) -> [0: bb11, otherwise: bb9];
+ }
+
+ bb9: {
+ StorageLive(_27);
+- StorageLive(_28);
+- StorageLive(_29);
+- _29 = _2;
+- StorageLive(_30);
+- _30 = _3;
+- _28 = Add(move _29, move _30);
+- StorageDead(_30);
+- StorageDead(_29);
+- _27 = opaque::(move _28) -> [return: bb10, unwind continue];
++ _27 = opaque::(_23) -> [return: bb10, unwind continue];
+ }
+
+ bb10: {
+- StorageDead(_28);
+ StorageDead(_27);
+ _0 = const ();
+ goto -> bb13;
+ }
+
+ bb11: {
+ StorageLive(_31);
+- StorageLive(_32);
+- StorageLive(_33);
+- _33 = _2;
+- StorageLive(_34);
+- _34 = _3;
+- _32 = Add(move _33, move _34);
+- StorageDead(_34);
+- StorageDead(_33);
+- _31 = opaque::(move _32) -> [return: bb12, unwind continue];
++ _31 = opaque::(_23) -> [return: bb12, unwind continue];
+ }
+
+ bb12: {
+- StorageDead(_32);
+ StorageDead(_31);
+ _0 = const ();
+ goto -> bb13;
+ }
+
+ bb13: {
+- StorageDead(_26);
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.references.GVN.panic-abort.diff b/tests/mir-opt/gvn.references.GVN.panic-abort.diff
new file mode 100644
index 00000000000..b7ad4ab1fd3
--- /dev/null
+++ b/tests/mir-opt/gvn.references.GVN.panic-abort.diff
@@ -0,0 +1,105 @@
+- // MIR for `references` before GVN
++ // MIR for `references` after GVN
+
+ fn references(_1: impl Sized) -> () {
+ debug x => _1;
+ let mut _0: ();
+ let _2: ();
+ let mut _3: &impl Sized;
+ let _4: ();
+ let mut _5: &impl Sized;
+ let _6: ();
+ let mut _7: &mut impl Sized;
+ let _8: ();
+ let mut _9: &mut impl Sized;
+ let _10: ();
+ let mut _11: *const impl Sized;
+ let _12: ();
+ let mut _13: *const impl Sized;
+ let _14: ();
+ let mut _15: *mut impl Sized;
+ let _16: ();
+ let mut _17: *mut impl Sized;
+
+ bb0: {
+ StorageLive(_2);
+ StorageLive(_3);
+ _3 = &_1;
+ _2 = opaque::<&impl Sized>(move _3) -> [return: bb1, unwind unreachable];
+ }
+
+ bb1: {
+ StorageDead(_3);
+ StorageDead(_2);
+ StorageLive(_4);
+ StorageLive(_5);
+ _5 = &_1;
+ _4 = opaque::<&impl Sized>(move _5) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
+ StorageDead(_5);
+ StorageDead(_4);
+ StorageLive(_6);
+ StorageLive(_7);
+ _7 = &mut _1;
+ _6 = opaque::<&mut impl Sized>(move _7) -> [return: bb3, unwind unreachable];
+ }
+
+ bb3: {
+ StorageDead(_7);
+ StorageDead(_6);
+ StorageLive(_8);
+ StorageLive(_9);
+ _9 = &mut _1;
+ _8 = opaque::<&mut impl Sized>(move _9) -> [return: bb4, unwind unreachable];
+ }
+
+ bb4: {
+ StorageDead(_9);
+ StorageDead(_8);
+ StorageLive(_10);
+ StorageLive(_11);
+ _11 = &raw const _1;
+ _10 = opaque::<*const impl Sized>(move _11) -> [return: bb5, unwind unreachable];
+ }
+
+ bb5: {
+ StorageDead(_11);
+ StorageDead(_10);
+ StorageLive(_12);
+ StorageLive(_13);
+ _13 = &raw const _1;
+ _12 = opaque::<*const impl Sized>(move _13) -> [return: bb6, unwind unreachable];
+ }
+
+ bb6: {
+ StorageDead(_13);
+ StorageDead(_12);
+ StorageLive(_14);
+ StorageLive(_15);
+ _15 = &raw mut _1;
+ _14 = opaque::<*mut impl Sized>(move _15) -> [return: bb7, unwind unreachable];
+ }
+
+ bb7: {
+ StorageDead(_15);
+ StorageDead(_14);
+ StorageLive(_16);
+ StorageLive(_17);
+ _17 = &raw mut _1;
+ _16 = opaque::<*mut impl Sized>(move _17) -> [return: bb8, unwind unreachable];
+ }
+
+ bb8: {
+ StorageDead(_17);
+ StorageDead(_16);
+ _0 = const ();
+ drop(_1) -> [return: bb9, unwind unreachable];
+ }
+
+ bb9: {
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.references.GVN.panic-unwind.diff b/tests/mir-opt/gvn.references.GVN.panic-unwind.diff
new file mode 100644
index 00000000000..08ed4c629a6
--- /dev/null
+++ b/tests/mir-opt/gvn.references.GVN.panic-unwind.diff
@@ -0,0 +1,113 @@
+- // MIR for `references` before GVN
++ // MIR for `references` after GVN
+
+ fn references(_1: impl Sized) -> () {
+ debug x => _1;
+ let mut _0: ();
+ let _2: ();
+ let mut _3: &impl Sized;
+ let _4: ();
+ let mut _5: &impl Sized;
+ let _6: ();
+ let mut _7: &mut impl Sized;
+ let _8: ();
+ let mut _9: &mut impl Sized;
+ let _10: ();
+ let mut _11: *const impl Sized;
+ let _12: ();
+ let mut _13: *const impl Sized;
+ let _14: ();
+ let mut _15: *mut impl Sized;
+ let _16: ();
+ let mut _17: *mut impl Sized;
+
+ bb0: {
+ StorageLive(_2);
+ StorageLive(_3);
+ _3 = &_1;
+ _2 = opaque::<&impl Sized>(move _3) -> [return: bb1, unwind: bb10];
+ }
+
+ bb1: {
+ StorageDead(_3);
+ StorageDead(_2);
+ StorageLive(_4);
+ StorageLive(_5);
+ _5 = &_1;
+ _4 = opaque::<&impl Sized>(move _5) -> [return: bb2, unwind: bb10];
+ }
+
+ bb2: {
+ StorageDead(_5);
+ StorageDead(_4);
+ StorageLive(_6);
+ StorageLive(_7);
+ _7 = &mut _1;
+ _6 = opaque::<&mut impl Sized>(move _7) -> [return: bb3, unwind: bb10];
+ }
+
+ bb3: {
+ StorageDead(_7);
+ StorageDead(_6);
+ StorageLive(_8);
+ StorageLive(_9);
+ _9 = &mut _1;
+ _8 = opaque::<&mut impl Sized>(move _9) -> [return: bb4, unwind: bb10];
+ }
+
+ bb4: {
+ StorageDead(_9);
+ StorageDead(_8);
+ StorageLive(_10);
+ StorageLive(_11);
+ _11 = &raw const _1;
+ _10 = opaque::<*const impl Sized>(move _11) -> [return: bb5, unwind: bb10];
+ }
+
+ bb5: {
+ StorageDead(_11);
+ StorageDead(_10);
+ StorageLive(_12);
+ StorageLive(_13);
+ _13 = &raw const _1;
+ _12 = opaque::<*const impl Sized>(move _13) -> [return: bb6, unwind: bb10];
+ }
+
+ bb6: {
+ StorageDead(_13);
+ StorageDead(_12);
+ StorageLive(_14);
+ StorageLive(_15);
+ _15 = &raw mut _1;
+ _14 = opaque::<*mut impl Sized>(move _15) -> [return: bb7, unwind: bb10];
+ }
+
+ bb7: {
+ StorageDead(_15);
+ StorageDead(_14);
+ StorageLive(_16);
+ StorageLive(_17);
+ _17 = &raw mut _1;
+ _16 = opaque::<*mut impl Sized>(move _17) -> [return: bb8, unwind: bb10];
+ }
+
+ bb8: {
+ StorageDead(_17);
+ StorageDead(_16);
+ _0 = const ();
+ drop(_1) -> [return: bb9, unwind: bb11];
+ }
+
+ bb9: {
+ return;
+ }
+
+ bb10 (cleanup): {
+ drop(_1) -> [return: bb11, unwind terminate(cleanup)];
+ }
+
+ bb11 (cleanup): {
+ resume;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.repeated_index.GVN.panic-abort.diff b/tests/mir-opt/gvn.repeated_index.GVN.panic-abort.diff
new file mode 100644
index 00000000000..4c29523d6b2
--- /dev/null
+++ b/tests/mir-opt/gvn.repeated_index.GVN.panic-abort.diff
@@ -0,0 +1,76 @@
+- // MIR for `repeated_index` before GVN
++ // MIR for `repeated_index` after GVN
+
+ fn repeated_index(_1: T, _2: usize) -> () {
+ debug x => _1;
+ debug idx => _2;
+ let mut _0: ();
+ let _3: [T; N];
+ let mut _4: T;
+ let _5: ();
+ let mut _6: T;
+ let _7: usize;
+ let mut _8: usize;
+ let mut _9: bool;
+ let _10: ();
+ let mut _11: T;
+ let _12: usize;
+ let mut _13: usize;
+ let mut _14: bool;
+ scope 1 {
+ debug a => _3;
+ }
+
+ bb0: {
+ StorageLive(_3);
+- StorageLive(_4);
+- _4 = _1;
+- _3 = [move _4; N];
+- StorageDead(_4);
++ _3 = [_1; N];
+ StorageLive(_5);
+ StorageLive(_6);
+ StorageLive(_7);
+ _7 = const 0_usize;
+ _8 = Len(_3);
+- _9 = Lt(_7, _8);
+- assert(move _9, "index out of bounds: the length is {} but the index is {}", move _8, _7) -> [success: bb1, unwind unreachable];
++ _9 = Lt(const 0_usize, _8);
++ assert(move _9, "index out of bounds: the length is {} but the index is {}", _8, const 0_usize) -> [success: bb1, unwind unreachable];
+ }
+
+ bb1: {
+ _6 = _3[_7];
+ _5 = opaque::(move _6) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
+ StorageDead(_6);
+ StorageDead(_7);
+ StorageDead(_5);
+ StorageLive(_10);
+ StorageLive(_11);
+ StorageLive(_12);
+ _12 = _2;
+- _13 = Len(_3);
+- _14 = Lt(_12, _13);
+- assert(move _14, "index out of bounds: the length is {} but the index is {}", move _13, _12) -> [success: bb3, unwind unreachable];
++ _14 = Lt(_2, _8);
++ assert(move _14, "index out of bounds: the length is {} but the index is {}", _8, _2) -> [success: bb3, unwind unreachable];
+ }
+
+ bb3: {
+ _11 = _3[_12];
+ _10 = opaque::(move _11) -> [return: bb4, unwind unreachable];
+ }
+
+ bb4: {
+ StorageDead(_11);
+ StorageDead(_12);
+ StorageDead(_10);
+ _0 = const ();
+ StorageDead(_3);
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.repeated_index.GVN.panic-unwind.diff b/tests/mir-opt/gvn.repeated_index.GVN.panic-unwind.diff
new file mode 100644
index 00000000000..e44f54cf3cf
--- /dev/null
+++ b/tests/mir-opt/gvn.repeated_index.GVN.panic-unwind.diff
@@ -0,0 +1,76 @@
+- // MIR for `repeated_index` before GVN
++ // MIR for `repeated_index` after GVN
+
+ fn repeated_index(_1: T, _2: usize) -> () {
+ debug x => _1;
+ debug idx => _2;
+ let mut _0: ();
+ let _3: [T; N];
+ let mut _4: T;
+ let _5: ();
+ let mut _6: T;
+ let _7: usize;
+ let mut _8: usize;
+ let mut _9: bool;
+ let _10: ();
+ let mut _11: T;
+ let _12: usize;
+ let mut _13: usize;
+ let mut _14: bool;
+ scope 1 {
+ debug a => _3;
+ }
+
+ bb0: {
+ StorageLive(_3);
+- StorageLive(_4);
+- _4 = _1;
+- _3 = [move _4; N];
+- StorageDead(_4);
++ _3 = [_1; N];
+ StorageLive(_5);
+ StorageLive(_6);
+ StorageLive(_7);
+ _7 = const 0_usize;
+ _8 = Len(_3);
+- _9 = Lt(_7, _8);
+- assert(move _9, "index out of bounds: the length is {} but the index is {}", move _8, _7) -> [success: bb1, unwind continue];
++ _9 = Lt(const 0_usize, _8);
++ assert(move _9, "index out of bounds: the length is {} but the index is {}", _8, const 0_usize) -> [success: bb1, unwind continue];
+ }
+
+ bb1: {
+ _6 = _3[_7];
+ _5 = opaque::(move _6) -> [return: bb2, unwind continue];
+ }
+
+ bb2: {
+ StorageDead(_6);
+ StorageDead(_7);
+ StorageDead(_5);
+ StorageLive(_10);
+ StorageLive(_11);
+ StorageLive(_12);
+ _12 = _2;
+- _13 = Len(_3);
+- _14 = Lt(_12, _13);
+- assert(move _14, "index out of bounds: the length is {} but the index is {}", move _13, _12) -> [success: bb3, unwind continue];
++ _14 = Lt(_2, _8);
++ assert(move _14, "index out of bounds: the length is {} but the index is {}", _8, _2) -> [success: bb3, unwind continue];
+ }
+
+ bb3: {
+ _11 = _3[_12];
+ _10 = opaque::(move _11) -> [return: bb4, unwind continue];
+ }
+
+ bb4: {
+ StorageDead(_11);
+ StorageDead(_12);
+ StorageDead(_10);
+ _0 = const ();
+ StorageDead(_3);
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.rs b/tests/mir-opt/gvn.rs
new file mode 100644
index 00000000000..a85e2ae368b
--- /dev/null
+++ b/tests/mir-opt/gvn.rs
@@ -0,0 +1,253 @@
+// unit-test: GVN
+// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
+
+#![feature(raw_ref_op)]
+#![feature(rustc_attrs)]
+#![allow(unconditional_panic)]
+
+struct S(T);
+
+fn subexpression_elimination(x: u64, y: u64, mut z: u64) {
+ opaque(x + y);
+ opaque(x * y);
+ opaque(x - y);
+ opaque(x / y);
+ opaque(x % y);
+ opaque(x & y);
+ opaque(x | y);
+ opaque(x ^ y);
+ opaque(x << y);
+ opaque(x >> y);
+ opaque(x as u32);
+ opaque(x as f32);
+ opaque(S(x));
+ opaque(S(x).0);
+
+ // Those are duplicates to substitute somehow.
+ opaque((x + y) + z);
+ opaque((x * y) + z);
+ opaque((x - y) + z);
+ opaque((x / y) + z);
+ opaque((x % y) + z);
+ opaque((x & y) + z);
+ opaque((x | y) + z);
+ opaque((x ^ y) + z);
+ opaque((x << y) + z);
+ opaque((x >> y) + z);
+ opaque(S(x));
+ opaque(S(x).0);
+
+ // We can substitute through an immutable reference too.
+ let a = &z;
+ opaque(*a + x);
+ opaque(*a + x);
+
+ // But not through a mutable reference or a pointer.
+ let b = &mut z;
+ opaque(*b + x);
+ opaque(*b + x);
+ unsafe {
+ let c = &raw const z;
+ opaque(*c + x);
+ opaque(*c + x);
+ let d = &raw mut z;
+ opaque(*d + x);
+ opaque(*d + x);
+ }
+
+ // We can substitute again, but not with the earlier computations.
+ // Important: `e` is not `a`!
+ let e = &z;
+ opaque(*e + x);
+ opaque(*e + x);
+
+}
+
+fn wrap_unwrap(x: T) -> T {
+ match Some(x) {
+ Some(y) => y,
+ None => panic!(),
+ }
+}
+
+fn repeated_index(x: T, idx: usize) {
+ let a = [x; N];
+ opaque(a[0]);
+ opaque(a[idx]);
+}
+
+fn arithmetic(x: u64) {
+ opaque(x + 0);
+ opaque(x - 0);
+ opaque(x * 0);
+ opaque(x * 1);
+ opaque(x / 0);
+ opaque(x / 1);
+ opaque(0 / x);
+ opaque(1 / x);
+ opaque(x % 0);
+ opaque(x % 1);
+ opaque(0 % x);
+ opaque(1 % x);
+ opaque(x & 0);
+ opaque(x | 0);
+ opaque(x ^ 0);
+ opaque(x >> 0);
+ opaque(x << 0);
+}
+
+#[rustc_inherit_overflow_checks]
+fn arithmetic_checked(x: u64) {
+ opaque(x + 0);
+ opaque(x - 0);
+ opaque(x * 0);
+ opaque(x * 1);
+ opaque(x / 0);
+ opaque(x / 1);
+ opaque(0 / x);
+ opaque(1 / x);
+ opaque(x % 0);
+ opaque(x % 1);
+ opaque(0 % x);
+ opaque(1 % x);
+ opaque(x & 0);
+ opaque(x | 0);
+ opaque(x ^ 0);
+ opaque(x >> 0);
+ opaque(x << 0);
+}
+
+fn arithmetic_float(x: f64) {
+ opaque(x + 0.);
+ opaque(x - 0.);
+ opaque(x * 0.);
+ opaque(x / 0.);
+ opaque(0. / x);
+ opaque(x % 0.);
+ opaque(0. % x);
+ // Those are not simplifiable to `true`/`false`, thanks to NaNs.
+ opaque(x == x);
+ opaque(x != x);
+}
+
+fn cast() {
+ let i = 1_i64;
+ let u = 1_u64;
+ let f = 1_f64;
+ opaque(i as u8);
+ opaque(i as u16);
+ opaque(i as u32);
+ opaque(i as u64);
+ opaque(i as i8);
+ opaque(i as i16);
+ opaque(i as i32);
+ opaque(i as i64);
+ opaque(i as f32);
+ opaque(i as f64);
+ opaque(u as u8);
+ opaque(u as u16);
+ opaque(u as u32);
+ opaque(u as u64);
+ opaque(u as i8);
+ opaque(u as i16);
+ opaque(u as i32);
+ opaque(u as i64);
+ opaque(u as f32);
+ opaque(u as f64);
+ opaque(f as u8);
+ opaque(f as u16);
+ opaque(f as u32);
+ opaque(f as u64);
+ opaque(f as i8);
+ opaque(f as i16);
+ opaque(f as i32);
+ opaque(f as i64);
+ opaque(f as f32);
+ opaque(f as f64);
+}
+
+fn multiple_branches(t: bool, x: u8, y: u8) {
+ if t {
+ opaque(x + y); // a
+ opaque(x + y); // should reuse a
+ } else {
+ opaque(x + y); // b
+ opaque(x + y); // shoud reuse b
+ }
+ opaque(x + y); // c
+ if t {
+ opaque(x + y); // should reuse c
+ } else {
+ opaque(x + y); // should reuse c
+ }
+}
+
+fn references(mut x: impl Sized) {
+ opaque(&x);
+ opaque(&x); // should not reuse a
+ opaque(&mut x);
+ opaque(&mut x); // should not reuse a
+ opaque(&raw const x);
+ opaque(&raw const x); // should not reuse a
+ opaque(&raw mut x);
+ opaque(&raw mut x); // should not reuse a
+}
+
+fn dereferences(t: &mut u32, u: &impl Copy, s: &S) {
+ opaque(*t);
+ opaque(*t); // this cannot reuse a, as x is &mut.
+ let z = &raw const *t;
+ unsafe { opaque(*z) };
+ unsafe { opaque(*z) }; // this cannot reuse a, as x is *const.
+ let z = &raw mut *t;
+ unsafe { opaque(*z) };
+ unsafe { opaque(*z) }; // this cannot reuse a, as x is *mut.
+ let z = &*t;
+ opaque(*z);
+ opaque(*z); // this can reuse, as `z` is immutable ref, Freeze and Copy.
+ opaque(&*z); // but not for a reborrow.
+ opaque(*u);
+ opaque(*u); // this cannot reuse, as `z` is not Freeze.
+ opaque(s.0);
+ opaque(s.0); // *s is not Copy, by (*s).0 is, so we can reuse.
+}
+
+fn slices() {
+ let s = "my favourite slice"; // This is a `Const::Slice` in MIR.
+ opaque(s);
+ let t = s; // This should be the same pointer, so cannot be a `Const::Slice`.
+ opaque(t);
+ assert_eq!(s.as_ptr(), t.as_ptr());
+ let u = unsafe { std::mem::transmute::<&str, &[u8]>(s) };
+ opaque(u);
+ assert_eq!(s.as_ptr(), u.as_ptr());
+}
+
+fn main() {
+ subexpression_elimination(2, 4, 5);
+ wrap_unwrap(5);
+ repeated_index::(5, 3);
+ arithmetic(5);
+ arithmetic_checked(5);
+ arithmetic_float(5.);
+ cast();
+ multiple_branches(true, 5, 9);
+ references(5);
+ dereferences(&mut 5, &6, &S(7));
+ slices();
+}
+
+#[inline(never)]
+fn opaque(_: impl Sized) {}
+
+// EMIT_MIR gvn.subexpression_elimination.GVN.diff
+// EMIT_MIR gvn.wrap_unwrap.GVN.diff
+// EMIT_MIR gvn.repeated_index.GVN.diff
+// EMIT_MIR gvn.arithmetic.GVN.diff
+// EMIT_MIR gvn.arithmetic_checked.GVN.diff
+// EMIT_MIR gvn.arithmetic_float.GVN.diff
+// EMIT_MIR gvn.cast.GVN.diff
+// EMIT_MIR gvn.multiple_branches.GVN.diff
+// EMIT_MIR gvn.references.GVN.diff
+// EMIT_MIR gvn.dereferences.GVN.diff
+// EMIT_MIR gvn.slices.GVN.diff
diff --git a/tests/mir-opt/gvn.slices.GVN.panic-abort.diff b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff
new file mode 100644
index 00000000000..de3d28d0575
--- /dev/null
+++ b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff
@@ -0,0 +1,275 @@
+- // MIR for `slices` before GVN
++ // MIR for `slices` after GVN
+
+ fn slices() -> () {
+ let mut _0: ();
+ let _1: &str;
+ let _2: ();
+ let mut _3: &str;
+ let _5: ();
+ let mut _6: &str;
+ let _7: ();
+ let mut _8: (&*const u8, &*const u8);
+ let mut _9: &*const u8;
+ let _10: *const u8;
+ let mut _11: &str;
+ let mut _12: &*const u8;
+ let _13: *const u8;
+ let mut _14: &str;
+ let mut _17: bool;
+ let mut _18: *const u8;
+ let mut _19: *const u8;
+ let mut _20: !;
+ let _22: !;
+ let mut _23: core::panicking::AssertKind;
+ let mut _24: &*const u8;
+ let _25: &*const u8;
+ let mut _26: &*const u8;
+ let _27: &*const u8;
+ let mut _28: std::option::Option>;
+ let mut _30: &str;
+ let _31: ();
+ let mut _32: &[u8];
+ let _33: ();
+ let mut _34: (&*const u8, &*const u8);
+ let mut _35: &*const u8;
+ let _36: *const u8;
+ let mut _37: &str;
+ let mut _38: &*const u8;
+ let _39: *const u8;
+ let mut _40: &[u8];
+ let mut _43: bool;
+ let mut _44: *const u8;
+ let mut _45: *const u8;
+ let mut _46: !;
+ let _48: !;
+ let mut _49: core::panicking::AssertKind;
+ let mut _50: &*const u8;
+ let _51: &*const u8;
+ let mut _52: &*const u8;
+ let _53: &*const u8;
+ let mut _54: std::option::Option>;
+ scope 1 {
+ debug s => _1;
+ let _4: &str;
+ scope 2 {
+ debug t => _4;
+ let _15: &*const u8;
+ let _16: &*const u8;
+ let _29: &[u8];
+ scope 3 {
+ debug left_val => _15;
+ debug right_val => _16;
+ let _21: core::panicking::AssertKind;
+ scope 4 {
+ debug kind => _21;
+ }
+ }
+ scope 5 {
+ debug u => _29;
+ let _41: &*const u8;
+ let _42: &*const u8;
+ scope 7 {
+ debug left_val => _41;
+ debug right_val => _42;
+ let _47: core::panicking::AssertKind;
+ scope 8 {
+ debug kind => _47;
+ }
+ }
+ }
+ scope 6 {
+ }
+ }
+ }
+
+ bb0: {
+- StorageLive(_1);
+ _1 = const "my favourite slice";
+ StorageLive(_2);
+- StorageLive(_3);
+- _3 = _1;
+- _2 = opaque::<&str>(move _3) -> [return: bb1, unwind unreachable];
++ _2 = opaque::<&str>(_1) -> [return: bb1, unwind unreachable];
+ }
+
+ bb1: {
+- StorageDead(_3);
+ StorageDead(_2);
+ StorageLive(_4);
+ _4 = _1;
+ StorageLive(_5);
+- StorageLive(_6);
+- _6 = _4;
+- _5 = opaque::<&str>(move _6) -> [return: bb2, unwind unreachable];
++ _5 = opaque::<&str>(_1) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
+- StorageDead(_6);
+ StorageDead(_5);
+- StorageLive(_7);
+ StorageLive(_8);
+ StorageLive(_9);
+ StorageLive(_10);
+ StorageLive(_11);
+ _11 = &(*_1);
+ _10 = core::str::::as_ptr(move _11) -> [return: bb3, unwind unreachable];
+ }
+
+ bb3: {
+ StorageDead(_11);
+ _9 = &_10;
+ StorageLive(_12);
+ StorageLive(_13);
+ StorageLive(_14);
+ _14 = &(*_4);
+ _13 = core::str::::as_ptr(move _14) -> [return: bb4, unwind unreachable];
+ }
+
+ bb4: {
+ StorageDead(_14);
+ _12 = &_13;
+ _8 = (move _9, move _12);
+ StorageDead(_12);
+ StorageDead(_9);
+ StorageLive(_15);
+ _15 = (_8.0: &*const u8);
+ StorageLive(_16);
+ _16 = (_8.1: &*const u8);
+ StorageLive(_17);
+ StorageLive(_18);
+ _18 = (*_15);
+ StorageLive(_19);
+ _19 = (*_16);
+ _17 = Eq(move _18, move _19);
+ switchInt(move _17) -> [0: bb6, otherwise: bb5];
+ }
+
+ bb5: {
+ StorageDead(_19);
+ StorageDead(_18);
+- _7 = const ();
+ StorageDead(_17);
+ StorageDead(_16);
+ StorageDead(_15);
+ StorageDead(_13);
+ StorageDead(_10);
+ StorageDead(_8);
+- StorageDead(_7);
+- StorageLive(_29);
+ StorageLive(_30);
+ _30 = &(*_1);
+ _29 = move _30 as &[u8] (Transmute);
+ StorageDead(_30);
+ StorageLive(_31);
+- StorageLive(_32);
+- _32 = _29;
+- _31 = opaque::<&[u8]>(move _32) -> [return: bb7, unwind unreachable];
++ _31 = opaque::<&[u8]>(_29) -> [return: bb7, unwind unreachable];
+ }
+
+ bb6: {
+ StorageDead(_19);
+ StorageDead(_18);
+- StorageLive(_21);
+ _21 = core::panicking::AssertKind::Eq;
+ StorageLive(_22);
+- StorageLive(_23);
+- _23 = move _21;
+ StorageLive(_24);
+ StorageLive(_25);
+ _25 = &(*_15);
+ _24 = &(*_25);
+ StorageLive(_26);
+ StorageLive(_27);
+ _27 = &(*_16);
+ _26 = &(*_27);
+ StorageLive(_28);
+ _28 = Option::>::None;
+- _22 = core::panicking::assert_failed::<*const u8, *const u8>(move _23, move _24, move _26, move _28) -> unwind unreachable;
++ _22 = core::panicking::assert_failed::<*const u8, *const u8>(_21, move _24, move _26, move _28) -> unwind unreachable;
+ }
+
+ bb7: {
+- StorageDead(_32);
+ StorageDead(_31);
+- StorageLive(_33);
+ StorageLive(_34);
+ StorageLive(_35);
+ StorageLive(_36);
+ StorageLive(_37);
+ _37 = &(*_1);
+ _36 = core::str::::as_ptr(move _37) -> [return: bb8, unwind unreachable];
+ }
+
+ bb8: {
+ StorageDead(_37);
+ _35 = &_36;
+ StorageLive(_38);
+ StorageLive(_39);
+ StorageLive(_40);
+ _40 = &(*_29);
+ _39 = core::slice::::as_ptr(move _40) -> [return: bb9, unwind unreachable];
+ }
+
+ bb9: {
+ StorageDead(_40);
+ _38 = &_39;
+ _34 = (move _35, move _38);
+ StorageDead(_38);
+ StorageDead(_35);
+ StorageLive(_41);
+ _41 = (_34.0: &*const u8);
+ StorageLive(_42);
+ _42 = (_34.1: &*const u8);
+ StorageLive(_43);
+ StorageLive(_44);
+ _44 = (*_41);
+ StorageLive(_45);
+ _45 = (*_42);
+ _43 = Eq(move _44, move _45);
+ switchInt(move _43) -> [0: bb11, otherwise: bb10];
+ }
+
+ bb10: {
+ StorageDead(_45);
+ StorageDead(_44);
+- _33 = const ();
+ StorageDead(_43);
+ StorageDead(_42);
+ StorageDead(_41);
+ StorageDead(_39);
+ StorageDead(_36);
+ StorageDead(_34);
+- StorageDead(_33);
+ _0 = const ();
+- StorageDead(_29);
+ StorageDead(_4);
+- StorageDead(_1);
+ return;
+ }
+
+ bb11: {
+ StorageDead(_45);
+ StorageDead(_44);
+- StorageLive(_47);
+ _47 = core::panicking::AssertKind::Eq;
+ StorageLive(_48);
+- StorageLive(_49);
+- _49 = move _47;
+ StorageLive(_50);
+ StorageLive(_51);
+ _51 = &(*_41);
+ _50 = &(*_51);
+ StorageLive(_52);
+ StorageLive(_53);
+ _53 = &(*_42);
+ _52 = &(*_53);
+ StorageLive(_54);
+ _54 = Option::>::None;
+- _48 = core::panicking::assert_failed::<*const u8, *const u8>(move _49, move _50, move _52, move _54) -> unwind unreachable;
++ _48 = core::panicking::assert_failed::<*const u8, *const u8>(_47, move _50, move _52, move _54) -> unwind unreachable;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff b/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff
new file mode 100644
index 00000000000..f22bb25436f
--- /dev/null
+++ b/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff
@@ -0,0 +1,275 @@
+- // MIR for `slices` before GVN
++ // MIR for `slices` after GVN
+
+ fn slices() -> () {
+ let mut _0: ();
+ let _1: &str;
+ let _2: ();
+ let mut _3: &str;
+ let _5: ();
+ let mut _6: &str;
+ let _7: ();
+ let mut _8: (&*const u8, &*const u8);
+ let mut _9: &*const u8;
+ let _10: *const u8;
+ let mut _11: &str;
+ let mut _12: &*const u8;
+ let _13: *const u8;
+ let mut _14: &str;
+ let mut _17: bool;
+ let mut _18: *const u8;
+ let mut _19: *const u8;
+ let mut _20: !;
+ let _22: !;
+ let mut _23: core::panicking::AssertKind;
+ let mut _24: &*const u8;
+ let _25: &*const u8;
+ let mut _26: &*const u8;
+ let _27: &*const u8;
+ let mut _28: std::option::Option>;
+ let mut _30: &str;
+ let _31: ();
+ let mut _32: &[u8];
+ let _33: ();
+ let mut _34: (&*const u8, &*const u8);
+ let mut _35: &*const u8;
+ let _36: *const u8;
+ let mut _37: &str;
+ let mut _38: &*const u8;
+ let _39: *const u8;
+ let mut _40: &[u8];
+ let mut _43: bool;
+ let mut _44: *const u8;
+ let mut _45: *const u8;
+ let mut _46: !;
+ let _48: !;
+ let mut _49: core::panicking::AssertKind;
+ let mut _50: &*const u8;
+ let _51: &*const u8;
+ let mut _52: &*const u8;
+ let _53: &*const u8;
+ let mut _54: std::option::Option>;
+ scope 1 {
+ debug s => _1;
+ let _4: &str;
+ scope 2 {
+ debug t => _4;
+ let _15: &*const u8;
+ let _16: &*const u8;
+ let _29: &[u8];
+ scope 3 {
+ debug left_val => _15;
+ debug right_val => _16;
+ let _21: core::panicking::AssertKind;
+ scope 4 {
+ debug kind => _21;
+ }
+ }
+ scope 5 {
+ debug u => _29;
+ let _41: &*const u8;
+ let _42: &*const u8;
+ scope 7 {
+ debug left_val => _41;
+ debug right_val => _42;
+ let _47: core::panicking::AssertKind;
+ scope 8 {
+ debug kind => _47;
+ }
+ }
+ }
+ scope 6 {
+ }
+ }
+ }
+
+ bb0: {
+- StorageLive(_1);
+ _1 = const "my favourite slice";
+ StorageLive(_2);
+- StorageLive(_3);
+- _3 = _1;
+- _2 = opaque::<&str>(move _3) -> [return: bb1, unwind continue];
++ _2 = opaque::<&str>(_1) -> [return: bb1, unwind continue];
+ }
+
+ bb1: {
+- StorageDead(_3);
+ StorageDead(_2);
+ StorageLive(_4);
+ _4 = _1;
+ StorageLive(_5);
+- StorageLive(_6);
+- _6 = _4;
+- _5 = opaque::<&str>(move _6) -> [return: bb2, unwind continue];
++ _5 = opaque::<&str>(_1) -> [return: bb2, unwind continue];
+ }
+
+ bb2: {
+- StorageDead(_6);
+ StorageDead(_5);
+- StorageLive(_7);
+ StorageLive(_8);
+ StorageLive(_9);
+ StorageLive(_10);
+ StorageLive(_11);
+ _11 = &(*_1);
+ _10 = core::str::::as_ptr(move _11) -> [return: bb3, unwind continue];
+ }
+
+ bb3: {
+ StorageDead(_11);
+ _9 = &_10;
+ StorageLive(_12);
+ StorageLive(_13);
+ StorageLive(_14);
+ _14 = &(*_4);
+ _13 = core::str::::as_ptr(move _14) -> [return: bb4, unwind continue];
+ }
+
+ bb4: {
+ StorageDead(_14);
+ _12 = &_13;
+ _8 = (move _9, move _12);
+ StorageDead(_12);
+ StorageDead(_9);
+ StorageLive(_15);
+ _15 = (_8.0: &*const u8);
+ StorageLive(_16);
+ _16 = (_8.1: &*const u8);
+ StorageLive(_17);
+ StorageLive(_18);
+ _18 = (*_15);
+ StorageLive(_19);
+ _19 = (*_16);
+ _17 = Eq(move _18, move _19);
+ switchInt(move _17) -> [0: bb6, otherwise: bb5];
+ }
+
+ bb5: {
+ StorageDead(_19);
+ StorageDead(_18);
+- _7 = const ();
+ StorageDead(_17);
+ StorageDead(_16);
+ StorageDead(_15);
+ StorageDead(_13);
+ StorageDead(_10);
+ StorageDead(_8);
+- StorageDead(_7);
+- StorageLive(_29);
+ StorageLive(_30);
+ _30 = &(*_1);
+ _29 = move _30 as &[u8] (Transmute);
+ StorageDead(_30);
+ StorageLive(_31);
+- StorageLive(_32);
+- _32 = _29;
+- _31 = opaque::<&[u8]>(move _32) -> [return: bb7, unwind continue];
++ _31 = opaque::<&[u8]>(_29) -> [return: bb7, unwind continue];
+ }
+
+ bb6: {
+ StorageDead(_19);
+ StorageDead(_18);
+- StorageLive(_21);
+ _21 = core::panicking::AssertKind::Eq;
+ StorageLive(_22);
+- StorageLive(_23);
+- _23 = move _21;
+ StorageLive(_24);
+ StorageLive(_25);
+ _25 = &(*_15);
+ _24 = &(*_25);
+ StorageLive(_26);
+ StorageLive(_27);
+ _27 = &(*_16);
+ _26 = &(*_27);
+ StorageLive(_28);
+ _28 = Option::>::None;
+- _22 = core::panicking::assert_failed::<*const u8, *const u8>(move _23, move _24, move _26, move _28) -> unwind continue;
++ _22 = core::panicking::assert_failed::<*const u8, *const u8>(_21, move _24, move _26, move _28) -> unwind continue;
+ }
+
+ bb7: {
+- StorageDead(_32);
+ StorageDead(_31);
+- StorageLive(_33);
+ StorageLive(_34);
+ StorageLive(_35);
+ StorageLive(_36);
+ StorageLive(_37);
+ _37 = &(*_1);
+ _36 = core::str::::as_ptr(move _37) -> [return: bb8, unwind continue];
+ }
+
+ bb8: {
+ StorageDead(_37);
+ _35 = &_36;
+ StorageLive(_38);
+ StorageLive(_39);
+ StorageLive(_40);
+ _40 = &(*_29);
+ _39 = core::slice::::as_ptr(move _40) -> [return: bb9, unwind continue];
+ }
+
+ bb9: {
+ StorageDead(_40);
+ _38 = &_39;
+ _34 = (move _35, move _38);
+ StorageDead(_38);
+ StorageDead(_35);
+ StorageLive(_41);
+ _41 = (_34.0: &*const u8);
+ StorageLive(_42);
+ _42 = (_34.1: &*const u8);
+ StorageLive(_43);
+ StorageLive(_44);
+ _44 = (*_41);
+ StorageLive(_45);
+ _45 = (*_42);
+ _43 = Eq(move _44, move _45);
+ switchInt(move _43) -> [0: bb11, otherwise: bb10];
+ }
+
+ bb10: {
+ StorageDead(_45);
+ StorageDead(_44);
+- _33 = const ();
+ StorageDead(_43);
+ StorageDead(_42);
+ StorageDead(_41);
+ StorageDead(_39);
+ StorageDead(_36);
+ StorageDead(_34);
+- StorageDead(_33);
+ _0 = const ();
+- StorageDead(_29);
+ StorageDead(_4);
+- StorageDead(_1);
+ return;
+ }
+
+ bb11: {
+ StorageDead(_45);
+ StorageDead(_44);
+- StorageLive(_47);
+ _47 = core::panicking::AssertKind::Eq;
+ StorageLive(_48);
+- StorageLive(_49);
+- _49 = move _47;
+ StorageLive(_50);
+ StorageLive(_51);
+ _51 = &(*_41);
+ _50 = &(*_51);
+ StorageLive(_52);
+ StorageLive(_53);
+ _53 = &(*_42);
+ _52 = &(*_53);
+ StorageLive(_54);
+ _54 = Option::>::None;
+- _48 = core::panicking::assert_failed::<*const u8, *const u8>(move _49, move _50, move _52, move _54) -> unwind continue;
++ _48 = core::panicking::assert_failed::<*const u8, *const u8>(_47, move _50, move _52, move _54) -> unwind continue;
+ }
+ }
+
diff --git a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff
new file mode 100644
index 00000000000..bf866e2f4d2
--- /dev/null
+++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff
@@ -0,0 +1,883 @@
+- // MIR for `subexpression_elimination` before GVN
++ // MIR for `subexpression_elimination` after GVN
+
+ fn subexpression_elimination(_1: u64, _2: u64, _3: u64) -> () {
+ debug x => _1;
+ debug y => _2;
+ debug z => _3;
+ let mut _0: ();
+ let _4: ();
+ let mut _5: u64;
+ let mut _6: u64;
+ let mut _7: u64;
+ let _8: ();
+ let mut _9: u64;
+ let mut _10: u64;
+ let mut _11: u64;
+ let _12: ();
+ let mut _13: u64;
+ let mut _14: u64;
+ let mut _15: u64;
+ let _16: ();
+ let mut _17: u64;
+ let mut _18: u64;
+ let mut _19: u64;
+ let mut _20: bool;
+ let _21: ();
+ let mut _22: u64;
+ let mut _23: u64;
+ let mut _24: u64;
+ let mut _25: bool;
+ let _26: ();
+ let mut _27: u64;
+ let mut _28: u64;
+ let mut _29: u64;
+ let _30: ();
+ let mut _31: u64;
+ let mut _32: u64;
+ let mut _33: u64;
+ let _34: ();
+ let mut _35: u64;
+ let mut _36: u64;
+ let mut _37: u64;
+ let _38: ();
+ let mut _39: u64;
+ let mut _40: u64;
+ let mut _41: u64;
+ let _42: ();
+ let mut _43: u64;
+ let mut _44: u64;
+ let mut _45: u64;
+ let _46: ();
+ let mut _47: u32;
+ let mut _48: u64;
+ let _49: ();
+ let mut _50: f32;
+ let mut _51: u64;
+ let _52: ();
+ let mut _53: S;
+ let mut _54: u64;
+ let _55: ();
+ let mut _56: u64;
+ let mut _57: S;
+ let mut _58: u64;
+ let _59: ();
+ let mut _60: u64;
+ let mut _61: u64;
+ let mut _62: u64;
+ let mut _63: u64;
+ let mut _64: u64;
+ let _65: ();
+ let mut _66: u64;
+ let mut _67: u64;
+ let mut _68: u64;
+ let mut _69: u64;
+ let mut _70: u64;
+ let _71: ();
+ let mut _72: u64;
+ let mut _73: u64;
+ let mut _74: u64;
+ let mut _75: u64;
+ let mut _76: u64;
+ let _77: ();
+ let mut _78: u64;
+ let mut _79: u64;
+ let mut _80: u64;
+ let mut _81: u64;
+ let mut _82: bool;
+ let mut _83: u64;
+ let _84: ();
+ let mut _85: u64;
+ let mut _86: u64;
+ let mut _87: u64;
+ let mut _88: u64;
+ let mut _89: bool;
+ let mut _90: u64;
+ let _91: ();
+ let mut _92: u64;
+ let mut _93: u64;
+ let mut _94: u64;
+ let mut _95: u64;
+ let mut _96: u64;
+ let _97: ();
+ let mut _98: u64;
+ let mut _99: u64;
+ let mut _100: u64;
+ let mut _101: u64;
+ let mut _102: u64;
+ let _103: ();
+ let mut _104: u64;
+ let mut _105: u64;
+ let mut _106: u64;
+ let mut _107: u64;
+ let mut _108: u64;
+ let _109: ();
+ let mut _110: u64;
+ let mut _111: u64;
+ let mut _112: u64;
+ let mut _113: u64;
+ let mut _114: u64;
+ let _115: ();
+ let mut _116: u64;
+ let mut _117: u64;
+ let mut _118: u64;
+ let mut _119: u64;
+ let mut _120: u64;
+ let _121: ();
+ let mut _122: S;
+ let mut _123: u64;
+ let _124: ();
+ let mut _125: u64;
+ let mut _126: S;
+ let mut _127: u64;
+ let _128: &u64;
+ let _129: ();
+ let mut _130: u64;
+ let mut _131: u64;
+ let mut _132: u64;
+ let _133: ();
+ let mut _134: u64;
+ let mut _135: u64;
+ let mut _136: u64;
+ let _138: ();
+ let mut _139: u64;
+ let mut _140: u64;
+ let mut _141: u64;
+ let _142: ();
+ let mut _143: u64;
+ let mut _144: u64;
+ let mut _145: u64;
+ let _146: ();
+ let _148: ();
+ let mut _149: u64;
+ let mut _150: u64;
+ let mut _151: u64;
+ let _152: ();
+ let mut _153: u64;
+ let mut _154: u64;
+ let mut _155: u64;
+ let _157: ();
+ let mut _158: u64;
+ let mut _159: u64;
+ let mut _160: u64;
+ let _161: ();
+ let mut _162: u64;
+ let mut _163: u64;
+ let mut _164: u64;
+ let _166: ();
+ let mut _167: u64;
+ let mut _168: u64;
+ let mut _169: u64;
+ let _170: ();
+ let mut _171: u64;
+ let mut _172: u64;
+ let mut _173: u64;
+ scope 1 {
+ debug a => _128;
+ let _137: &mut u64;
+ scope 2 {
+ debug b => _137;
+ let _165: &u64;
+ scope 3 {
+ let _147: *const u64;
+ scope 4 {
+ debug c => _147;
+ let _156: *mut u64;
+ scope 5 {
+ debug d => _156;
+ }
+ }
+ }
+ scope 6 {
+ debug e => _165;
+ }
+ }
+ }
+
+ bb0: {
+ StorageLive(_4);
+- StorageLive(_5);
+- StorageLive(_6);
+- _6 = _1;
+- StorageLive(_7);
+- _7 = _2;
+- _5 = Add(move _6, move _7);
+- StorageDead(_7);
+- StorageDead(_6);
+- _4 = opaque::(move _5) -> [return: bb1, unwind unreachable];
++ _5 = Add(_1, _2);
++ _4 = opaque::(_5) -> [return: bb1, unwind unreachable];
+ }
+
+ bb1: {
+- StorageDead(_5);
+ StorageDead(_4);
+ StorageLive(_8);
+- StorageLive(_9);
+- StorageLive(_10);
+- _10 = _1;
+- StorageLive(_11);
+- _11 = _2;
+- _9 = Mul(move _10, move _11);
+- StorageDead(_11);
+- StorageDead(_10);
+- _8 = opaque::(move _9) -> [return: bb2, unwind unreachable];
++ _9 = Mul(_1, _2);
++ _8 = opaque::(_9) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
+- StorageDead(_9);
+ StorageDead(_8);
+ StorageLive(_12);
+- StorageLive(_13);
+- StorageLive(_14);
+- _14 = _1;
+- StorageLive(_15);
+- _15 = _2;
+- _13 = Sub(move _14, move _15);
+- StorageDead(_15);
+- StorageDead(_14);
+- _12 = opaque::(move _13) -> [return: bb3, unwind unreachable];
++ _13 = Sub(_1, _2);
++ _12 = opaque::(_13) -> [return: bb3, unwind unreachable];
+ }
+
+ bb3: {
+- StorageDead(_13);
+ StorageDead(_12);
+ StorageLive(_16);
+- StorageLive(_17);
+- StorageLive(_18);
+- _18 = _1;
+- StorageLive(_19);
+- _19 = _2;
+- _20 = Eq(_19, const 0_u64);
+- assert(!move _20, "attempt to divide `{}` by zero", _18) -> [success: bb4, unwind unreachable];
++ _20 = Eq(_2, const 0_u64);
++ assert(!_20, "attempt to divide `{}` by zero", _1) -> [success: bb4, unwind unreachable];
+ }
+
+ bb4: {
+- _17 = Div(move _18, move _19);
+- StorageDead(_19);
+- StorageDead(_18);
+- _16 = opaque::(move _17) -> [return: bb5, unwind unreachable];
++ _17 = Div(_1, _2);
++ _16 = opaque::(_17) -> [return: bb5, unwind unreachable];
+ }
+
+ bb5: {
+- StorageDead(_17);
+ StorageDead(_16);
+ StorageLive(_21);
+- StorageLive(_22);
+- StorageLive(_23);
+- _23 = _1;
+- StorageLive(_24);
+- _24 = _2;
+- _25 = Eq(_24, const 0_u64);
+- assert(!move _25, "attempt to calculate the remainder of `{}` with a divisor of zero", _23) -> [success: bb6, unwind unreachable];
++ assert(!_20, "attempt to calculate the remainder of `{}` with a divisor of zero", _1) -> [success: bb6, unwind unreachable];
+ }
+
+ bb6: {
+- _22 = Rem(move _23, move _24);
+- StorageDead(_24);
+- StorageDead(_23);
+- _21 = opaque::(move _22) -> [return: bb7, unwind unreachable];
++ _22 = Rem(_1, _2);
++ _21 = opaque::