Skip to content

Remove SimplifyBranchSame MIR optimization #77706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/rustc_mir/src/transform/mod.rs
Original file line number Diff line number Diff line change
@@ -403,7 +403,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
&early_otherwise_branch::EarlyOtherwiseBranch,
&simplify_comparison_integral::SimplifyComparisonIntegral,
&simplify_try::SimplifyArmIdentity,
&simplify_try::SimplifyBranchSame,
&dest_prop::DestinationPropagation,
&copy_prop::CopyPropagation,
&simplify_branches::SimplifyBranches::new("after-copy-prop"),
269 changes: 3 additions & 266 deletions compiler/rustc_mir/src/transform/simplify_try.rs
Original file line number Diff line number Diff line change
@@ -9,14 +9,13 @@
//!
//! into just `x`.
use crate::transform::{simplify, MirPass};
use itertools::Itertools as _;
use crate::transform::MirPass;
use rustc_index::{bit_set::BitSet, vec::IndexVec};
use rustc_middle::mir::visit::{NonUseContext, PlaceContext, Visitor};
use rustc_middle::mir::*;
use rustc_middle::ty::{self, List, Ty, TyCtxt};
use rustc_middle::ty::{List, Ty, TyCtxt};
use rustc_target::abi::VariantIdx;
use std::iter::{once, Enumerate, Peekable};
use std::iter::{Enumerate, Peekable};
use std::slice::Iter;

/// Simplifies arms of form `Variant(x) => Variant(x)` to just a move.
@@ -523,265 +522,3 @@ fn match_variant_field_place<'tcx>(place: Place<'tcx>) -> Option<(Local, VarFiel
_ => None,
}
}

/// Simplifies `SwitchInt(_) -> [targets]`,
/// where all the `targets` have the same form,
/// into `goto -> target_first`.
pub struct SimplifyBranchSame;

impl<'tcx> MirPass<'tcx> for SimplifyBranchSame {
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
trace!("Running SimplifyBranchSame on {:?}", body.source);
let finder = SimplifyBranchSameOptimizationFinder { body, tcx };
let opts = finder.find();

let did_remove_blocks = opts.len() > 0;
for opt in opts.iter() {
trace!("SUCCESS: Applying optimization {:?}", opt);
// Replace `SwitchInt(..) -> [bb_first, ..];` with a `goto -> bb_first;`.
body.basic_blocks_mut()[opt.bb_to_opt_terminator].terminator_mut().kind =
TerminatorKind::Goto { target: opt.bb_to_goto };
}

if did_remove_blocks {
// We have dead blocks now, so remove those.
simplify::remove_dead_blocks(body);
}
}
}

#[derive(Debug)]
struct SimplifyBranchSameOptimization {
/// All basic blocks are equal so go to this one
bb_to_goto: BasicBlock,
/// Basic block where the terminator can be simplified to a goto
bb_to_opt_terminator: BasicBlock,
}

struct SwitchTargetAndValue {
target: BasicBlock,
// None in case of the `otherwise` case
value: Option<u128>,
}

struct SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
body: &'a Body<'tcx>,
tcx: TyCtxt<'tcx>,
}

impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
fn find(&self) -> Vec<SimplifyBranchSameOptimization> {
self.body
.basic_blocks()
.iter_enumerated()
.filter_map(|(bb_idx, bb)| {
let (discr_switched_on, targets_and_values) = match &bb.terminator().kind {
TerminatorKind::SwitchInt { targets, discr, values, .. } => {
// if values.len() == targets.len() - 1, we need to include None where no value is present
// such that the zip does not throw away targets. If no `otherwise` case is in targets, the zip will simply throw away the added None
let values_extended = values.iter().map(|x|Some(*x)).chain(once(None));
let targets_and_values:Vec<_> = targets.iter().zip(values_extended)
.map(|(target, value)| SwitchTargetAndValue{target:*target, value})
.collect();
assert_eq!(targets.len(), targets_and_values.len());
(discr, targets_and_values)},
_ => return None,
};

// find the adt that has its discriminant read
// assuming this must be the last statement of the block
let adt_matched_on = match &bb.statements.last()?.kind {
StatementKind::Assign(box (place, rhs))
if Some(*place) == discr_switched_on.place() =>
{
match rhs {
Rvalue::Discriminant(adt_place) if adt_place.ty(self.body, self.tcx).ty.is_enum() => adt_place,
_ => {
trace!("NO: expected a discriminant read of an enum instead of: {:?}", rhs);
return None;
}
}
}
other => {
trace!("NO: expected an assignment of a discriminant read to a place. Found: {:?}", other);
return None
},
};

let mut iter_bbs_reachable = targets_and_values
.iter()
.map(|target_and_value| (target_and_value, &self.body.basic_blocks()[target_and_value.target]))
.filter(|(_, bb)| {
// Reaching `unreachable` is UB so assume it doesn't happen.
bb.terminator().kind != TerminatorKind::Unreachable
// But `asm!(...)` could abort the program,
// so we cannot assume that the `unreachable` terminator itself is reachable.
// FIXME(Centril): use a normalization pass instead of a check.
|| bb.statements.iter().any(|stmt| match stmt.kind {
StatementKind::LlvmInlineAsm(..) => true,
_ => false,
})
})
.peekable();

let bb_first = iter_bbs_reachable.peek().map(|(idx, _)| *idx).unwrap_or(&targets_and_values[0]);
let mut all_successors_equivalent = StatementEquality::TrivialEqual;

// All successor basic blocks must be equal or contain statements that are pairwise considered equal.
for ((target_and_value_l,bb_l), (target_and_value_r,bb_r)) in iter_bbs_reachable.tuple_windows() {
let trivial_checks = bb_l.is_cleanup == bb_r.is_cleanup
&& bb_l.terminator().kind == bb_r.terminator().kind
&& bb_l.statements.len() == bb_r.statements.len();
let statement_check = || {
bb_l.statements.iter().zip(&bb_r.statements).try_fold(StatementEquality::TrivialEqual, |acc,(l,r)| {
let stmt_equality = self.statement_equality(*adt_matched_on, &l, target_and_value_l, &r, target_and_value_r);
if matches!(stmt_equality, StatementEquality::NotEqual) {
// short circuit
None
} else {
Some(acc.combine(&stmt_equality))
}
})
.unwrap_or(StatementEquality::NotEqual)
};
if !trivial_checks {
all_successors_equivalent = StatementEquality::NotEqual;
break;
}
all_successors_equivalent = all_successors_equivalent.combine(&statement_check());
};

match all_successors_equivalent{
StatementEquality::TrivialEqual => {
// statements are trivially equal, so just take first
trace!("Statements are trivially equal");
Some(SimplifyBranchSameOptimization {
bb_to_goto: bb_first.target,
bb_to_opt_terminator: bb_idx,
})
}
StatementEquality::ConsideredEqual(bb_to_choose) => {
trace!("Statements are considered equal");
Some(SimplifyBranchSameOptimization {
bb_to_goto: bb_to_choose,
bb_to_opt_terminator: bb_idx,
})
}
StatementEquality::NotEqual => {
trace!("NO: not all successors of basic block {:?} were equivalent", bb_idx);
None
}
}
})
.collect()
}

/// Tests if two statements can be considered equal
///
/// Statements can be trivially equal if the kinds match.
/// But they can also be considered equal in the following case A:
/// ```
/// discriminant(_0) = 0; // bb1
/// _0 = move _1; // bb2
/// ```
/// In this case the two statements are equal iff
/// 1: _0 is an enum where the variant index 0 is fieldless, and
/// 2: bb1 was targeted by a switch where the discriminant of _1 was switched on
fn statement_equality(
&self,
adt_matched_on: Place<'tcx>,
x: &Statement<'tcx>,
x_target_and_value: &SwitchTargetAndValue,
y: &Statement<'tcx>,
y_target_and_value: &SwitchTargetAndValue,
) -> StatementEquality {
let helper = |rhs: &Rvalue<'tcx>,
place: &Place<'tcx>,
variant_index: &VariantIdx,
side_to_choose| {
let place_type = place.ty(self.body, self.tcx).ty;
let adt = match *place_type.kind() {
ty::Adt(adt, _) if adt.is_enum() => adt,
_ => return StatementEquality::NotEqual,
};
let variant_is_fieldless = adt.variants[*variant_index].fields.is_empty();
if !variant_is_fieldless {
trace!("NO: variant {:?} was not fieldless", variant_index);
return StatementEquality::NotEqual;
}

match rhs {
Rvalue::Use(operand) if operand.place() == Some(adt_matched_on) => {
StatementEquality::ConsideredEqual(side_to_choose)
}
_ => {
trace!(
"NO: RHS of assignment was {:?}, but expected it to match the adt being matched on in the switch, which is {:?}",
rhs,
adt_matched_on
);
StatementEquality::NotEqual
}
}
};
match (&x.kind, &y.kind) {
// trivial case
(x, y) if x == y => StatementEquality::TrivialEqual,

// check for case A
(
StatementKind::Assign(box (_, rhs)),
StatementKind::SetDiscriminant { place, variant_index },
)
// we need to make sure that the switch value that targets the bb with SetDiscriminant (y), is the same as the variant index
if Some(variant_index.index() as u128) == y_target_and_value.value => {
// choose basic block of x, as that has the assign
helper(rhs, place, variant_index, x_target_and_value.target)
}
(
StatementKind::SetDiscriminant { place, variant_index },
StatementKind::Assign(box (_, rhs)),
)
// we need to make sure that the switch value that targets the bb with SetDiscriminant (x), is the same as the variant index
if Some(variant_index.index() as u128) == x_target_and_value.value => {
// choose basic block of y, as that has the assign
helper(rhs, place, variant_index, y_target_and_value.target)
}
_ => {
trace!("NO: statements `{:?}` and `{:?}` not considered equal", x, y);
StatementEquality::NotEqual
}
}
}
}

#[derive(Copy, Clone, Eq, PartialEq)]
enum StatementEquality {
/// The two statements are trivially equal; same kind
TrivialEqual,
/// The two statements are considered equal, but may be of different kinds. The BasicBlock field is the basic block to jump to when performing the branch-same optimization.
/// For example, `_0 = _1` and `discriminant(_0) = discriminant(0)` are considered equal if 0 is a fieldless variant of an enum. But we don't want to jump to the basic block with the SetDiscriminant, as that is not legal if _1 is not the 0 variant index
ConsideredEqual(BasicBlock),
/// The two statements are not equal
NotEqual,
}

impl StatementEquality {
fn combine(&self, other: &StatementEquality) -> StatementEquality {
use StatementEquality::*;
match (self, other) {
(TrivialEqual, TrivialEqual) => TrivialEqual,
(TrivialEqual, ConsideredEqual(b)) | (ConsideredEqual(b), TrivialEqual) => {
ConsideredEqual(*b)
}
(ConsideredEqual(b1), ConsideredEqual(b2)) => {
if b1 == b2 {
ConsideredEqual(*b1)
} else {
NotEqual
}
}
(_, NotEqual) | (NotEqual, _) => NotEqual,
}
}
}
17 changes: 0 additions & 17 deletions src/test/codegen/try_identity.rs

This file was deleted.

28 changes: 0 additions & 28 deletions src/test/mir-opt/76803_regression.encode.SimplifyBranchSame.diff

This file was deleted.

19 changes: 0 additions & 19 deletions src/test/mir-opt/76803_regression.rs

This file was deleted.

3 changes: 0 additions & 3 deletions src/test/mir-opt/simplify-arm.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// compile-flags: -Z mir-opt-level=2 -Zunsound-mir-opts
// EMIT_MIR simplify_arm.id.SimplifyArmIdentity.diff
// EMIT_MIR simplify_arm.id.SimplifyBranchSame.diff
// EMIT_MIR simplify_arm.id_result.SimplifyArmIdentity.diff
// EMIT_MIR simplify_arm.id_result.SimplifyBranchSame.diff
// EMIT_MIR simplify_arm.id_try.SimplifyArmIdentity.diff
// EMIT_MIR simplify_arm.id_try.SimplifyBranchSame.diff

fn id(o: Option<u8>) -> Option<u8> {
match o {
46 changes: 23 additions & 23 deletions src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff
Original file line number Diff line number Diff line change
@@ -2,45 +2,45 @@
+ // MIR for `id` after SimplifyArmIdentity

fn id(_1: Option<u8>) -> Option<u8> {
debug o => _1; // in scope 0 at $DIR/simplify-arm.rs:9:7: 9:8
let mut _0: std::option::Option<u8>; // return place in scope 0 at $DIR/simplify-arm.rs:9:25: 9:35
let mut _2: isize; // in scope 0 at $DIR/simplify-arm.rs:11:9: 11:16
let _3: u8; // in scope 0 at $DIR/simplify-arm.rs:11:14: 11:15
let mut _4: u8; // in scope 0 at $DIR/simplify-arm.rs:11:25: 11:26
debug o => _1; // in scope 0 at $DIR/simplify-arm.rs:6:7: 6:8
let mut _0: std::option::Option<u8>; // return place in scope 0 at $DIR/simplify-arm.rs:6:25: 6:35
let mut _2: isize; // in scope 0 at $DIR/simplify-arm.rs:8:9: 8:16
let _3: u8; // in scope 0 at $DIR/simplify-arm.rs:8:14: 8:15
let mut _4: u8; // in scope 0 at $DIR/simplify-arm.rs:8:25: 8:26
scope 1 {
- debug v => _3; // in scope 1 at $DIR/simplify-arm.rs:11:14: 11:15
+ debug v => ((_0 as Some).0: u8); // in scope 1 at $DIR/simplify-arm.rs:11:14: 11:15
- debug v => _3; // in scope 1 at $DIR/simplify-arm.rs:8:14: 8:15
+ debug v => ((_0 as Some).0: u8); // in scope 1 at $DIR/simplify-arm.rs:8:14: 8:15
}

bb0: {
_2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16
switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16
_2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:8:9: 8:16
switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:8:9: 8:16
}

bb1: {
discriminant(_0) = 0; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
discriminant(_0) = 0; // scope 0 at $DIR/simplify-arm.rs:9:17: 9:21
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:7:5: 10:6
}

bb2: {
unreachable; // scope 0 at $DIR/simplify-arm.rs:10:11: 10:12
unreachable; // scope 0 at $DIR/simplify-arm.rs:7:11: 7:12
}

bb3: {
- StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15
- _3 = ((_1 as Some).0: u8); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15
- StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26
- _4 = _3; // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26
- ((_0 as Some).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
- discriminant(_0) = 1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
- StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:11:26: 11:27
- StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:11:26: 11:27
+ _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
- StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:8:14: 8:15
- _3 = ((_1 as Some).0: u8); // scope 0 at $DIR/simplify-arm.rs:8:14: 8:15
- StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:8:25: 8:26
- _4 = _3; // scope 1 at $DIR/simplify-arm.rs:8:25: 8:26
- ((_0 as Some).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:8:20: 8:27
- discriminant(_0) = 1; // scope 1 at $DIR/simplify-arm.rs:8:20: 8:27
- StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:8:26: 8:27
- StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:8:26: 8:27
+ _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:8:20: 8:27
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:7:5: 10:6
}

bb4: {
return; // scope 0 at $DIR/simplify-arm.rs:14:2: 14:2
return; // scope 0 at $DIR/simplify-arm.rs:11:2: 11:2
}
}

40 changes: 0 additions & 40 deletions src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff

This file was deleted.

70 changes: 35 additions & 35 deletions src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff
Original file line number Diff line number Diff line change
@@ -2,59 +2,59 @@
+ // MIR for `id_result` after SimplifyArmIdentity

fn id_result(_1: std::result::Result<u8, i32>) -> std::result::Result<u8, i32> {
debug r => _1; // in scope 0 at $DIR/simplify-arm.rs:16:14: 16:15
let mut _0: std::result::Result<u8, i32>; // return place in scope 0 at $DIR/simplify-arm.rs:16:37: 16:52
let mut _2: isize; // in scope 0 at $DIR/simplify-arm.rs:18:9: 18:14
let _3: u8; // in scope 0 at $DIR/simplify-arm.rs:18:12: 18:13
let mut _4: u8; // in scope 0 at $DIR/simplify-arm.rs:18:21: 18:22
let _5: i32; // in scope 0 at $DIR/simplify-arm.rs:19:13: 19:14
let mut _6: i32; // in scope 0 at $DIR/simplify-arm.rs:19:23: 19:24
debug r => _1; // in scope 0 at $DIR/simplify-arm.rs:13:14: 13:15
let mut _0: std::result::Result<u8, i32>; // return place in scope 0 at $DIR/simplify-arm.rs:13:37: 13:52
let mut _2: isize; // in scope 0 at $DIR/simplify-arm.rs:15:9: 15:14
let _3: u8; // in scope 0 at $DIR/simplify-arm.rs:15:12: 15:13
let mut _4: u8; // in scope 0 at $DIR/simplify-arm.rs:15:21: 15:22
let _5: i32; // in scope 0 at $DIR/simplify-arm.rs:16:13: 16:14
let mut _6: i32; // in scope 0 at $DIR/simplify-arm.rs:16:23: 16:24
scope 1 {
- debug x => _3; // in scope 1 at $DIR/simplify-arm.rs:18:12: 18:13
+ debug x => ((_0 as Ok).0: u8); // in scope 1 at $DIR/simplify-arm.rs:18:12: 18:13
- debug x => _3; // in scope 1 at $DIR/simplify-arm.rs:15:12: 15:13
+ debug x => ((_0 as Ok).0: u8); // in scope 1 at $DIR/simplify-arm.rs:15:12: 15:13
}
scope 2 {
- debug y => _5; // in scope 2 at $DIR/simplify-arm.rs:19:13: 19:14
+ debug y => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify-arm.rs:19:13: 19:14
- debug y => _5; // in scope 2 at $DIR/simplify-arm.rs:16:13: 16:14
+ debug y => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify-arm.rs:16:13: 16:14
}

bb0: {
_2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14
switchInt(move _2) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14
_2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:15:9: 15:14
switchInt(move _2) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:15:9: 15:14
}

bb1: {
- StorageLive(_5); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14
- _5 = ((_1 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14
- StorageLive(_6); // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24
- _6 = _5; // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24
- ((_0 as Err).0: i32) = move _6; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
- discriminant(_0) = 1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
- StorageDead(_6); // scope 2 at $DIR/simplify-arm.rs:19:24: 19:25
- StorageDead(_5); // scope 0 at $DIR/simplify-arm.rs:19:24: 19:25
+ _0 = move _1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
- StorageLive(_5); // scope 0 at $DIR/simplify-arm.rs:16:13: 16:14
- _5 = ((_1 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:16:13: 16:14
- StorageLive(_6); // scope 2 at $DIR/simplify-arm.rs:16:23: 16:24
- _6 = _5; // scope 2 at $DIR/simplify-arm.rs:16:23: 16:24
- ((_0 as Err).0: i32) = move _6; // scope 2 at $DIR/simplify-arm.rs:16:19: 16:25
- discriminant(_0) = 1; // scope 2 at $DIR/simplify-arm.rs:16:19: 16:25
- StorageDead(_6); // scope 2 at $DIR/simplify-arm.rs:16:24: 16:25
- StorageDead(_5); // scope 0 at $DIR/simplify-arm.rs:16:24: 16:25
+ _0 = move _1; // scope 2 at $DIR/simplify-arm.rs:16:19: 16:25
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:14:5: 17:6
}

bb2: {
unreachable; // scope 0 at $DIR/simplify-arm.rs:17:11: 17:12
unreachable; // scope 0 at $DIR/simplify-arm.rs:14:11: 14:12
}

bb3: {
- StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13
- _3 = ((_1 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13
- StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22
- _4 = _3; // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22
- ((_0 as Ok).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
- discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
- StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:18:22: 18:23
- StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:18:22: 18:23
+ _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
- StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:15:12: 15:13
- _3 = ((_1 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:15:12: 15:13
- StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:15:21: 15:22
- _4 = _3; // scope 1 at $DIR/simplify-arm.rs:15:21: 15:22
- ((_0 as Ok).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:15:18: 15:23
- discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:15:18: 15:23
- StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:15:22: 15:23
- StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:15:22: 15:23
+ _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:15:18: 15:23
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:14:5: 17:6
}

bb4: {
return; // scope 0 at $DIR/simplify-arm.rs:21:2: 21:2
return; // scope 0 at $DIR/simplify-arm.rs:18:2: 18:2
}
}

45 changes: 0 additions & 45 deletions src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff

This file was deleted.

104 changes: 52 additions & 52 deletions src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff
Original file line number Diff line number Diff line change
@@ -2,25 +2,25 @@
+ // MIR for `id_try` after SimplifyArmIdentity

fn id_try(_1: std::result::Result<u8, i32>) -> std::result::Result<u8, i32> {
debug r => _1; // in scope 0 at $DIR/simplify-arm.rs:23:11: 23:12
let mut _0: std::result::Result<u8, i32>; // return place in scope 0 at $DIR/simplify-arm.rs:23:34: 23:49
let _2: u8; // in scope 0 at $DIR/simplify-arm.rs:24:9: 24:10
let mut _3: std::result::Result<u8, i32>; // in scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
let mut _4: std::result::Result<u8, i32>; // in scope 0 at $DIR/simplify-arm.rs:24:13: 24:14
let mut _5: isize; // in scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
let _6: i32; // in scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
let mut _7: !; // in scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
let mut _8: i32; // in scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
let mut _9: i32; // in scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
let _10: u8; // in scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
let mut _11: u8; // in scope 0 at $DIR/simplify-arm.rs:25:8: 25:9
debug r => _1; // in scope 0 at $DIR/simplify-arm.rs:20:11: 20:12
let mut _0: std::result::Result<u8, i32>; // return place in scope 0 at $DIR/simplify-arm.rs:20:34: 20:49
let _2: u8; // in scope 0 at $DIR/simplify-arm.rs:21:9: 21:10
let mut _3: std::result::Result<u8, i32>; // in scope 0 at $DIR/simplify-arm.rs:21:13: 21:15
let mut _4: std::result::Result<u8, i32>; // in scope 0 at $DIR/simplify-arm.rs:21:13: 21:14
let mut _5: isize; // in scope 0 at $DIR/simplify-arm.rs:21:14: 21:15
let _6: i32; // in scope 0 at $DIR/simplify-arm.rs:21:14: 21:15
let mut _7: !; // in scope 0 at $DIR/simplify-arm.rs:21:14: 21:15
let mut _8: i32; // in scope 0 at $DIR/simplify-arm.rs:21:14: 21:15
let mut _9: i32; // in scope 0 at $DIR/simplify-arm.rs:21:14: 21:15
let _10: u8; // in scope 0 at $DIR/simplify-arm.rs:21:13: 21:15
let mut _11: u8; // in scope 0 at $DIR/simplify-arm.rs:22:8: 22:9
scope 1 {
- debug x => _2; // in scope 1 at $DIR/simplify-arm.rs:24:9: 24:10
+ debug x => ((_0 as Ok).0: u8); // in scope 1 at $DIR/simplify-arm.rs:24:9: 24:10
- debug x => _2; // in scope 1 at $DIR/simplify-arm.rs:21:9: 21:10
+ debug x => ((_0 as Ok).0: u8); // in scope 1 at $DIR/simplify-arm.rs:21:9: 21:10
}
scope 2 {
- debug err => _6; // in scope 2 at $DIR/simplify-arm.rs:24:14: 24:15
+ debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify-arm.rs:24:14: 24:15
- debug err => _6; // in scope 2 at $DIR/simplify-arm.rs:21:14: 21:15
+ debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify-arm.rs:21:14: 21:15
scope 3 {
scope 7 {
- debug t => _9; // in scope 7 at $SRC_DIR/core/src/convert/mod.rs:LL:COL
@@ -29,13 +29,13 @@
scope 8 {
- debug v => _8; // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
+ debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
let mut _12: i32; // in scope 8 at $DIR/simplify-arm.rs:24:13: 24:15
let mut _12: i32; // in scope 8 at $DIR/simplify-arm.rs:21:13: 21:15
}
}
}
scope 4 {
- debug val => _10; // in scope 4 at $DIR/simplify-arm.rs:24:13: 24:15
+ debug val => ((_0 as Ok).0: u8); // in scope 4 at $DIR/simplify-arm.rs:24:13: 24:15
- debug val => _10; // in scope 4 at $DIR/simplify-arm.rs:21:13: 21:15
+ debug val => ((_0 as Ok).0: u8); // in scope 4 at $DIR/simplify-arm.rs:21:13: 21:15
scope 5 {
}
}
@@ -44,59 +44,59 @@
}

bb0: {
StorageLive(_2); // scope 0 at $DIR/simplify-arm.rs:24:9: 24:10
StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
StorageLive(_4); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:14
_4 = _1; // scope 0 at $DIR/simplify-arm.rs:24:13: 24:14
StorageLive(_2); // scope 0 at $DIR/simplify-arm.rs:21:9: 21:10
StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:21:13: 21:15
StorageLive(_4); // scope 0 at $DIR/simplify-arm.rs:21:13: 21:14
_4 = _1; // scope 0 at $DIR/simplify-arm.rs:21:13: 21:14
_3 = move _4; // scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
StorageDead(_4); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
_5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
StorageDead(_4); // scope 0 at $DIR/simplify-arm.rs:21:14: 21:15
_5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:21:14: 21:15
switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:21:14: 21:15
}

bb1: {
- StorageLive(_10); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
- _10 = ((_3 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
- _2 = _10; // scope 5 at $DIR/simplify-arm.rs:24:13: 24:15
- StorageDead(_10); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
+ _0 = move _3; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16
- StorageLive(_11); // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9
- _11 = _2; // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9
- ((_0 as Ok).0: u8) = move _11; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
- discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
- StorageDead(_11); // scope 1 at $DIR/simplify-arm.rs:25:9: 25:10
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
- StorageLive(_10); // scope 0 at $DIR/simplify-arm.rs:21:13: 21:15
- _10 = ((_3 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:21:13: 21:15
- _2 = _10; // scope 5 at $DIR/simplify-arm.rs:21:13: 21:15
- StorageDead(_10); // scope 0 at $DIR/simplify-arm.rs:21:14: 21:15
+ _0 = move _3; // scope 1 at $DIR/simplify-arm.rs:22:5: 22:10
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:21:15: 21:16
- StorageLive(_11); // scope 1 at $DIR/simplify-arm.rs:22:8: 22:9
- _11 = _2; // scope 1 at $DIR/simplify-arm.rs:22:8: 22:9
- ((_0 as Ok).0: u8) = move _11; // scope 1 at $DIR/simplify-arm.rs:22:5: 22:10
- discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:22:5: 22:10
- StorageDead(_11); // scope 1 at $DIR/simplify-arm.rs:22:9: 22:10
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:23:1: 23:2
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:23:2: 23:2
}

bb2: {
unreachable; // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
unreachable; // scope 0 at $DIR/simplify-arm.rs:21:13: 21:15
}

bb3: {
- StorageLive(_6); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
- _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
- StorageLive(_8); // scope 3 at $DIR/simplify-arm.rs:24:14: 24:15
- StorageLive(_9); // scope 3 at $DIR/simplify-arm.rs:24:14: 24:15
- _9 = _6; // scope 3 at $DIR/simplify-arm.rs:24:14: 24:15
- StorageLive(_6); // scope 0 at $DIR/simplify-arm.rs:21:14: 21:15
- _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:21:14: 21:15
- StorageLive(_8); // scope 3 at $DIR/simplify-arm.rs:21:14: 21:15
- StorageLive(_9); // scope 3 at $DIR/simplify-arm.rs:21:14: 21:15
- _9 = _6; // scope 3 at $DIR/simplify-arm.rs:21:14: 21:15
- _8 = move _9; // scope 7 at $SRC_DIR/core/src/convert/mod.rs:LL:COL
- StorageDead(_9); // scope 3 at $DIR/simplify-arm.rs:24:14: 24:15
- StorageDead(_9); // scope 3 at $DIR/simplify-arm.rs:21:14: 21:15
- StorageLive(_12); // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
- _12 = move _8; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
- ((_0 as Err).0: i32) = move _12; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
- discriminant(_0) = 1; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
- StorageDead(_12); // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
- StorageDead(_8); // scope 3 at $DIR/simplify-arm.rs:24:14: 24:15
- StorageDead(_6); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
- StorageDead(_8); // scope 3 at $DIR/simplify-arm.rs:21:14: 21:15
- StorageDead(_6); // scope 0 at $DIR/simplify-arm.rs:21:14: 21:15
+ _0 = move _3; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:21:15: 21:16
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:23:1: 23:2
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:23:2: 23:2
}

bb4: {
return; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
return; // scope 0 at $DIR/simplify-arm.rs:23:2: 23:2
}
}

76 changes: 0 additions & 76 deletions src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff

This file was deleted.

Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
fn map(_1: Option<Box<()>>) -> Option<Box<()>> {
debug x => _1; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:8: 3:9
let mut _0: std::option::Option<std::boxed::Box<()>>; // return place in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:31: 3:46
- let mut _2: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
let mut _2: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
- let _3: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:14: 6:15
- let mut _4: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:25: 6:26
- let mut _5: bool; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:1: 8:2
@@ -17,8 +17,21 @@
bb0: {
- _5 = const false; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
- _5 = const true; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
- _2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
_2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
}

bb1: {
_0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:20: 6:27
goto -> bb3; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:5: 7:6
}

bb2: {
discriminant(_0) = 0; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:17: 5:21
goto -> bb3; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:5: 7:6
}

bb3: {
- _6 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:1: 8:2
return; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:2: 8:2
}
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
fn map(_1: Option<Box<()>>) -> Option<Box<()>> {
debug x => _1; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:8: 3:9
let mut _0: std::option::Option<std::boxed::Box<()>>; // return place in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:31: 3:46
- let mut _2: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
let mut _2: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
- let _3: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:14: 6:15
- let mut _4: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:25: 6:26
- let mut _5: bool; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:1: 8:2
@@ -17,8 +17,21 @@
bb0: {
- _5 = const false; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
- _5 = const true; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
- _2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
_2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13
}

bb1: {
_0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:20: 6:27
goto -> bb3; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:5: 7:6
}

bb2: {
discriminant(_0) = 0; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:17: 5:21
goto -> bb3; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:5: 7:6
}

bb3: {
- _6 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:1: 8:2
return; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:2: 8:2
}
1 change: 0 additions & 1 deletion src/test/mir-opt/simplify_try.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// compile-flags: -Zunsound-mir-opts
// EMIT_MIR simplify_try.try_identity.SimplifyArmIdentity.diff
// EMIT_MIR simplify_try.try_identity.SimplifyBranchSame.after.mir
// EMIT_MIR simplify_try.try_identity.SimplifyLocals.after.mir
// EMIT_MIR simplify_try.try_identity.DestinationPropagation.diff

Original file line number Diff line number Diff line change
@@ -2,35 +2,35 @@
+ // MIR for `try_identity` after DestinationPropagation

fn try_identity(_1: std::result::Result<u32, i32>) -> std::result::Result<u32, i32> {
debug x => _1; // in scope 0 at $DIR/simplify_try.rs:7:17: 7:18
let mut _0: std::result::Result<u32, i32>; // return place in scope 0 at $DIR/simplify_try.rs:7:41: 7:57
let _2: u32; // in scope 0 at $DIR/simplify_try.rs:8:9: 8:10
let mut _3: std::result::Result<u32, i32>; // in scope 0 at $DIR/simplify_try.rs:8:13: 8:15
let mut _4: std::result::Result<u32, i32>; // in scope 0 at $DIR/simplify_try.rs:8:13: 8:14
let mut _5: isize; // in scope 0 at $DIR/simplify_try.rs:8:14: 8:15
let _6: i32; // in scope 0 at $DIR/simplify_try.rs:8:14: 8:15
let mut _7: !; // in scope 0 at $DIR/simplify_try.rs:8:14: 8:15
let mut _8: i32; // in scope 0 at $DIR/simplify_try.rs:8:14: 8:15
let mut _9: i32; // in scope 0 at $DIR/simplify_try.rs:8:14: 8:15
let _10: u32; // in scope 0 at $DIR/simplify_try.rs:8:13: 8:15
let mut _11: u32; // in scope 0 at $DIR/simplify_try.rs:9:8: 9:9
debug x => _1; // in scope 0 at $DIR/simplify_try.rs:6:17: 6:18
let mut _0: std::result::Result<u32, i32>; // return place in scope 0 at $DIR/simplify_try.rs:6:41: 6:57
let _2: u32; // in scope 0 at $DIR/simplify_try.rs:7:9: 7:10
let mut _3: std::result::Result<u32, i32>; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:15
let mut _4: std::result::Result<u32, i32>; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:14
let mut _5: isize; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15
let _6: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15
let mut _7: !; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15
let mut _8: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15
let mut _9: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15
let _10: u32; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:15
let mut _11: u32; // in scope 0 at $DIR/simplify_try.rs:8:8: 8:9
scope 1 {
debug y => ((_0 as Ok).0: u32); // in scope 1 at $DIR/simplify_try.rs:8:9: 8:10
debug y => ((_0 as Ok).0: u32); // in scope 1 at $DIR/simplify_try.rs:7:9: 7:10
}
scope 2 {
debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:8:14: 8:15
debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:7:14: 7:15
scope 3 {
scope 7 {
debug t => ((_0 as Err).0: i32); // in scope 7 at $SRC_DIR/core/src/convert/mod.rs:LL:COL
}
scope 8 {
debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:13: 8:15
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:7:13: 7:15
}
}
}
scope 4 {
debug val => ((_0 as Ok).0: u32); // in scope 4 at $DIR/simplify_try.rs:8:13: 8:15
debug val => ((_0 as Ok).0: u32); // in scope 4 at $DIR/simplify_try.rs:7:13: 7:15
scope 5 {
}
}
@@ -40,29 +40,38 @@
}

bb0: {
StorageLive(_2); // scope 0 at $DIR/simplify_try.rs:8:9: 8:10
- StorageLive(_3); // scope 0 at $DIR/simplify_try.rs:8:13: 8:15
- StorageLive(_4); // scope 0 at $DIR/simplify_try.rs:8:13: 8:14
- _4 = _1; // scope 0 at $DIR/simplify_try.rs:8:13: 8:14
StorageLive(_2); // scope 0 at $DIR/simplify_try.rs:7:9: 7:10
- StorageLive(_3); // scope 0 at $DIR/simplify_try.rs:7:13: 7:15
- StorageLive(_4); // scope 0 at $DIR/simplify_try.rs:7:13: 7:14
- _4 = _1; // scope 0 at $DIR/simplify_try.rs:7:13: 7:14
- _3 = move _4; // scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
- StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:8:14: 8:15
- _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:8:14: 8:15
+ nop; // scope 0 at $DIR/simplify_try.rs:8:13: 8:15
+ nop; // scope 0 at $DIR/simplify_try.rs:8:13: 8:14
+ _0 = _1; // scope 0 at $DIR/simplify_try.rs:8:13: 8:14
- StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
- _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
+ nop; // scope 0 at $DIR/simplify_try.rs:7:13: 7:15
+ nop; // scope 0 at $DIR/simplify_try.rs:7:13: 7:14
+ _0 = _1; // scope 0 at $DIR/simplify_try.rs:7:13: 7:14
+ nop; // scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
+ nop; // scope 0 at $DIR/simplify_try.rs:8:14: 8:15
+ _5 = discriminant(_0); // scope 0 at $DIR/simplify_try.rs:8:14: 8:15
goto -> bb1; // scope 0 at $DIR/simplify_try.rs:8:14: 8:15
+ nop; // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
+ _5 = discriminant(_0); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
}

bb1: {
- _0 = move _3; // scope 1 at $DIR/simplify_try.rs:9:5: 9:10
- StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:8:15: 8:16
+ nop; // scope 1 at $DIR/simplify_try.rs:9:5: 9:10
+ nop; // scope 0 at $DIR/simplify_try.rs:8:15: 8:16
StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:10:1: 10:2
return; // scope 0 at $DIR/simplify_try.rs:10:2: 10:2
- _0 = move _3; // scope 1 at $DIR/simplify_try.rs:8:5: 8:10
- StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:7:15: 7:16
+ nop; // scope 1 at $DIR/simplify_try.rs:8:5: 8:10
+ nop; // scope 0 at $DIR/simplify_try.rs:7:15: 7:16
StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:9:1: 9:2
return; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2
}

bb2: {
- _0 = move _3; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
- StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:7:15: 7:16
+ nop; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
+ nop; // scope 0 at $DIR/simplify_try.rs:7:15: 7:16
StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:9:1: 9:2
return; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2
}
}

100 changes: 50 additions & 50 deletions src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff
Original file line number Diff line number Diff line change
@@ -2,25 +2,25 @@
+ // MIR for `try_identity` after SimplifyArmIdentity

fn try_identity(_1: std::result::Result<u32, i32>) -> std::result::Result<u32, i32> {
debug x => _1; // in scope 0 at $DIR/simplify_try.rs:7:17: 7:18
let mut _0: std::result::Result<u32, i32>; // return place in scope 0 at $DIR/simplify_try.rs:7:41: 7:57
let _2: u32; // in scope 0 at $DIR/simplify_try.rs:8:9: 8:10
let mut _3: std::result::Result<u32, i32>; // in scope 0 at $DIR/simplify_try.rs:8:13: 8:15
let mut _4: std::result::Result<u32, i32>; // in scope 0 at $DIR/simplify_try.rs:8:13: 8:14
let mut _5: isize; // in scope 0 at $DIR/simplify_try.rs:8:14: 8:15
let _6: i32; // in scope 0 at $DIR/simplify_try.rs:8:14: 8:15
let mut _7: !; // in scope 0 at $DIR/simplify_try.rs:8:14: 8:15
let mut _8: i32; // in scope 0 at $DIR/simplify_try.rs:8:14: 8:15
let mut _9: i32; // in scope 0 at $DIR/simplify_try.rs:8:14: 8:15
let _10: u32; // in scope 0 at $DIR/simplify_try.rs:8:13: 8:15
let mut _11: u32; // in scope 0 at $DIR/simplify_try.rs:9:8: 9:9
debug x => _1; // in scope 0 at $DIR/simplify_try.rs:6:17: 6:18
let mut _0: std::result::Result<u32, i32>; // return place in scope 0 at $DIR/simplify_try.rs:6:41: 6:57
let _2: u32; // in scope 0 at $DIR/simplify_try.rs:7:9: 7:10
let mut _3: std::result::Result<u32, i32>; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:15
let mut _4: std::result::Result<u32, i32>; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:14
let mut _5: isize; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15
let _6: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15
let mut _7: !; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15
let mut _8: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15
let mut _9: i32; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15
let _10: u32; // in scope 0 at $DIR/simplify_try.rs:7:13: 7:15
let mut _11: u32; // in scope 0 at $DIR/simplify_try.rs:8:8: 8:9
scope 1 {
- debug y => _2; // in scope 1 at $DIR/simplify_try.rs:8:9: 8:10
+ debug y => ((_0 as Ok).0: u32); // in scope 1 at $DIR/simplify_try.rs:8:9: 8:10
- debug y => _2; // in scope 1 at $DIR/simplify_try.rs:7:9: 7:10
+ debug y => ((_0 as Ok).0: u32); // in scope 1 at $DIR/simplify_try.rs:7:9: 7:10
}
scope 2 {
- debug err => _6; // in scope 2 at $DIR/simplify_try.rs:8:14: 8:15
+ debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:8:14: 8:15
- debug err => _6; // in scope 2 at $DIR/simplify_try.rs:7:14: 7:15
+ debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:7:14: 7:15
scope 3 {
scope 7 {
- debug t => _9; // in scope 7 at $SRC_DIR/core/src/convert/mod.rs:LL:COL
@@ -29,13 +29,13 @@
scope 8 {
- debug v => _8; // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
+ debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:13: 8:15
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:7:13: 7:15
}
}
}
scope 4 {
- debug val => _10; // in scope 4 at $DIR/simplify_try.rs:8:13: 8:15
+ debug val => ((_0 as Ok).0: u32); // in scope 4 at $DIR/simplify_try.rs:8:13: 8:15
- debug val => _10; // in scope 4 at $DIR/simplify_try.rs:7:13: 7:15
+ debug val => ((_0 as Ok).0: u32); // in scope 4 at $DIR/simplify_try.rs:7:13: 7:15
scope 5 {
}
}
@@ -44,51 +44,51 @@
}

bb0: {
StorageLive(_2); // scope 0 at $DIR/simplify_try.rs:8:9: 8:10
StorageLive(_3); // scope 0 at $DIR/simplify_try.rs:8:13: 8:15
StorageLive(_4); // scope 0 at $DIR/simplify_try.rs:8:13: 8:14
_4 = _1; // scope 0 at $DIR/simplify_try.rs:8:13: 8:14
StorageLive(_2); // scope 0 at $DIR/simplify_try.rs:7:9: 7:10
StorageLive(_3); // scope 0 at $DIR/simplify_try.rs:7:13: 7:15
StorageLive(_4); // scope 0 at $DIR/simplify_try.rs:7:13: 7:14
_4 = _1; // scope 0 at $DIR/simplify_try.rs:7:13: 7:14
_3 = move _4; // scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:8:14: 8:15
_5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:8:14: 8:15
switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:8:14: 8:15
StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
_5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
}

bb1: {
- StorageLive(_10); // scope 0 at $DIR/simplify_try.rs:8:13: 8:15
- _10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:8:13: 8:15
- _2 = _10; // scope 5 at $DIR/simplify_try.rs:8:13: 8:15
- StorageDead(_10); // scope 0 at $DIR/simplify_try.rs:8:14: 8:15
+ _0 = move _3; // scope 1 at $DIR/simplify_try.rs:9:5: 9:10
StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:8:15: 8:16
- StorageLive(_11); // scope 1 at $DIR/simplify_try.rs:9:8: 9:9
- _11 = _2; // scope 1 at $DIR/simplify_try.rs:9:8: 9:9
- ((_0 as Ok).0: u32) = move _11; // scope 1 at $DIR/simplify_try.rs:9:5: 9:10
- discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:9:5: 9:10
- StorageDead(_11); // scope 1 at $DIR/simplify_try.rs:9:9: 9:10
StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:10:1: 10:2
return; // scope 0 at $DIR/simplify_try.rs:10:2: 10:2
- StorageLive(_10); // scope 0 at $DIR/simplify_try.rs:7:13: 7:15
- _10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:7:13: 7:15
- _2 = _10; // scope 5 at $DIR/simplify_try.rs:7:13: 7:15
- StorageDead(_10); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
+ _0 = move _3; // scope 1 at $DIR/simplify_try.rs:8:5: 8:10
StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:7:15: 7:16
- StorageLive(_11); // scope 1 at $DIR/simplify_try.rs:8:8: 8:9
- _11 = _2; // scope 1 at $DIR/simplify_try.rs:8:8: 8:9
- ((_0 as Ok).0: u32) = move _11; // scope 1 at $DIR/simplify_try.rs:8:5: 8:10
- discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:8:5: 8:10
- StorageDead(_11); // scope 1 at $DIR/simplify_try.rs:8:9: 8:10
StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:9:1: 9:2
return; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2
}

bb2: {
- StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:8:14: 8:15
- _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:8:14: 8:15
- StorageLive(_8); // scope 3 at $DIR/simplify_try.rs:8:14: 8:15
- StorageLive(_9); // scope 3 at $DIR/simplify_try.rs:8:14: 8:15
- _9 = _6; // scope 3 at $DIR/simplify_try.rs:8:14: 8:15
- StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
- _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
- StorageLive(_8); // scope 3 at $DIR/simplify_try.rs:7:14: 7:15
- StorageLive(_9); // scope 3 at $DIR/simplify_try.rs:7:14: 7:15
- _9 = _6; // scope 3 at $DIR/simplify_try.rs:7:14: 7:15
- _8 = move _9; // scope 7 at $SRC_DIR/core/src/convert/mod.rs:LL:COL
- StorageDead(_9); // scope 3 at $DIR/simplify_try.rs:8:14: 8:15
- StorageDead(_9); // scope 3 at $DIR/simplify_try.rs:7:14: 7:15
- StorageLive(_12); // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
- _12 = move _8; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
- ((_0 as Err).0: i32) = move _12; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
- discriminant(_0) = 1; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
- StorageDead(_12); // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
- StorageDead(_8); // scope 3 at $DIR/simplify_try.rs:8:14: 8:15
- StorageDead(_6); // scope 0 at $DIR/simplify_try.rs:8:14: 8:15
- StorageDead(_8); // scope 3 at $DIR/simplify_try.rs:7:14: 7:15
- StorageDead(_6); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
+ _0 = move _3; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:8:15: 8:16
StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:10:1: 10:2
return; // scope 0 at $DIR/simplify_try.rs:10:2: 10:2
StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:7:15: 7:16
StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:9:1: 9:2
return; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// MIR for `try_identity` after SimplifyLocals

fn try_identity(_1: std::result::Result<u32, i32>) -> std::result::Result<u32, i32> {
debug x => _1; // in scope 0 at $DIR/simplify_try.rs:7:17: 7:18
let mut _0: std::result::Result<u32, i32>; // return place in scope 0 at $DIR/simplify_try.rs:7:41: 7:57
debug x => _1; // in scope 0 at $DIR/simplify_try.rs:6:17: 6:18
let mut _0: std::result::Result<u32, i32>; // return place in scope 0 at $DIR/simplify_try.rs:6:41: 6:57
let mut _2: isize; // in scope 0 at $DIR/simplify_try.rs:7:14: 7:15
scope 1 {
debug y => ((_0 as Ok).0: u32); // in scope 1 at $DIR/simplify_try.rs:8:9: 8:10
debug y => ((_0 as Ok).0: u32); // in scope 1 at $DIR/simplify_try.rs:7:9: 7:10
}
scope 2 {
debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:8:14: 8:15
debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:7:14: 7:15
scope 3 {
scope 7 {
debug t => ((_0 as Err).0: i32); // in scope 7 at $SRC_DIR/core/src/convert/mod.rs:LL:COL
@@ -18,7 +19,7 @@ fn try_identity(_1: std::result::Result<u32, i32>) -> std::result::Result<u32, i
}
}
scope 4 {
debug val => ((_0 as Ok).0: u32); // in scope 4 at $DIR/simplify_try.rs:8:13: 8:15
debug val => ((_0 as Ok).0: u32); // in scope 4 at $DIR/simplify_try.rs:7:13: 7:15
scope 5 {
}
}
@@ -27,7 +28,16 @@ fn try_identity(_1: std::result::Result<u32, i32>) -> std::result::Result<u32, i
}

bb0: {
_0 = _1; // scope 0 at $DIR/simplify_try.rs:8:13: 8:14
return; // scope 0 at $DIR/simplify_try.rs:10:2: 10:2
_0 = _1; // scope 0 at $DIR/simplify_try.rs:7:13: 7:14
_2 = discriminant(_0); // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
switchInt(move _2) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:7:14: 7:15
}

bb1: {
return; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2
}

bb2: {
return; // scope 0 at $DIR/simplify_try.rs:9:2: 9:2
}
}