From 9248d90d20601e9d489a4a1c21df9de686b9fd82 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Sun, 21 Jun 2020 20:55:06 -0400 Subject: [PATCH] [mir-opt] Prevent mis-optimization when SimplifyArmIdentity runs If temporaries are used beyond just the temporary chain, then we can't optimize out the reads and writes. --- src/librustc_mir/transform/simplify_try.rs | 51 ++++++++++++++++++- .../32bit/rustc.main.PreCodegen.diff | 37 +++++++------- .../32bit/rustc.main.SimplifyArmIdentity.diff | 19 ++++--- .../64bit/rustc.main.PreCodegen.diff | 37 +++++++------- .../64bit/rustc.main.SimplifyArmIdentity.diff | 19 ++++--- .../32bit/rustc.map.SimplifyLocals.diff | 4 +- .../64bit/rustc.map.SimplifyLocals.diff | 4 +- ...ustc.try_identity.SimplifyArmIdentity.diff | 48 +++++++++-------- ....try_identity.SimplifyBranchSame.after.mir | 34 +++++++++++-- ...ustc.try_identity.SimplifyLocals.after.mir | 36 +++++++++---- 10 files changed, 192 insertions(+), 97 deletions(-) diff --git a/src/librustc_mir/transform/simplify_try.rs b/src/librustc_mir/transform/simplify_try.rs index 50136ac3becca..0abaa2175e141 100644 --- a/src/librustc_mir/transform/simplify_try.rs +++ b/src/librustc_mir/transform/simplify_try.rs @@ -12,6 +12,7 @@ use crate::transform::{simplify, MirPass, MirSource}; use itertools::Itertools as _; use rustc_index::vec::IndexVec; +use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::*; use rustc_middle::ty::{Ty, TyCtxt}; use rustc_target::abi::VariantIdx; @@ -75,7 +76,9 @@ struct ArmIdentityInfo<'tcx> { stmts_to_remove: Vec, } -fn get_arm_identity_info<'a, 'tcx>(stmts: &'a [Statement<'tcx>]) -> Option> { +fn get_arm_identity_info<'a, 'tcx>( + stmts: &'a [Statement<'tcx>], +) -> Option> { // This can't possibly match unless there are at least 3 statements in the block // so fail fast on tiny blocks. if stmts.len() < 3 { @@ -249,6 +252,7 @@ fn get_arm_identity_info<'a, 'tcx>(stmts: &'a [Statement<'tcx>]) -> Option( opt_info: &ArmIdentityInfo<'tcx>, local_decls: &IndexVec>, + local_uses: &IndexVec, ) -> bool { trace!("testing if optimization applies..."); @@ -285,6 +289,26 @@ fn optimization_applies<'tcx>( last_assigned_to = *l; } + // Check that the first and last used locals are only used twice + // since they are of the form: + // + // ``` + // _first = ((_x as Variant).n: ty); + // _n = _first; + // ... + // ((_y as Variant).n: ty) = _n; + // discriminant(_y) = z; + // ``` + for (l, r) in &opt_info.field_tmp_assignments { + if local_uses[*l] != 2 { + warn!("NO: FAILED assignment chain local {:?} was used more than twice", l); + return false; + } else if local_uses[*r] != 2 { + warn!("NO: FAILED assignment chain local {:?} was used more than twice", r); + return false; + } + } + if source_local != opt_info.local_temp_0 { trace!( "NO: start of assignment chain does not match enum variant temp: {:?} != {:?}", @@ -312,11 +336,12 @@ impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity { } trace!("running SimplifyArmIdentity on {:?}", source); + let local_uses = LocalUseCounter::get_local_uses(body); let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut(); for bb in basic_blocks { if let Some(opt_info) = get_arm_identity_info(&bb.statements) { trace!("got opt_info = {:#?}", opt_info); - if !optimization_applies(&opt_info, local_decls) { + if !optimization_applies(&opt_info, local_decls, &local_uses) { debug!("optimization skipped for {:?}", source); continue; } @@ -358,6 +383,28 @@ impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity { } } +struct LocalUseCounter { + local_uses: IndexVec, +} + +impl LocalUseCounter { + fn get_local_uses<'tcx>(body: &Body<'tcx>) -> IndexVec { + let mut counter = LocalUseCounter { local_uses: IndexVec::from_elem(0, &body.local_decls) }; + counter.visit_body(body); + counter.local_uses + } +} + +impl<'tcx> Visitor<'tcx> for LocalUseCounter { + fn visit_local(&mut self, local: &Local, context: PlaceContext, _location: Location) { + if context.is_storage_marker() { + return; + } + + self.local_uses[*local] += 1; + } +} + /// Match on: /// ```rust /// _LOCAL_INTO = ((_LOCAL_FROM as Variant).FIELD: TY); diff --git a/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff b/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff index 887ebfc8c64e4..59c00e1b96f96 100644 --- a/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff +++ b/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff @@ -3,9 +3,9 @@ fn main() -> () { let mut _0: (); // return place in scope 0 at $DIR/issue-73223.rs:1:11: 1:11 - let _1: i32; // in scope 0 at $DIR/issue-73223.rs:2:9: 2:14 - let mut _2: std::option::Option; // in scope 0 at $DIR/issue-73223.rs:2:23: 2:30 - let _3: i32; // in scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + let mut _1: std::option::Option; // in scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + let _2: i32; // in scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + let mut _4: i32; // in scope 0 at $DIR/issue-73223.rs:7:22: 7:27 let mut _5: (&i32, &i32); // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL let mut _6: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL let mut _9: bool; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL @@ -28,10 +28,10 @@ let mut _28: std::fmt::ArgumentV1; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL let mut _29: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL scope 1 { - debug split => _1; // in scope 1 at $DIR/issue-73223.rs:2:9: 2:14 - let _4: std::option::Option; // in scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + debug split => _2; // in scope 1 at $DIR/issue-73223.rs:2:9: 2:14 + let _3: std::option::Option; // in scope 1 at $DIR/issue-73223.rs:7:9: 7:14 scope 3 { - debug _prev => _4; // in scope 3 at $DIR/issue-73223.rs:7:9: 7:14 + debug _prev => _3; // in scope 3 at $DIR/issue-73223.rs:7:9: 7:14 let _7: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL let _8: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL scope 4 { @@ -64,7 +64,7 @@ } } scope 2 { - debug v => _3; // in scope 2 at $DIR/issue-73223.rs:3:14: 3:15 + debug v => _2; // in scope 2 at $DIR/issue-73223.rs:3:14: 3:15 } scope 7 { } @@ -72,22 +72,26 @@ } bb0: { - StorageLive(_1); // scope 0 at $DIR/issue-73223.rs:2:9: 2:14 - StorageLive(_2); // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 - ((_2 as Some).0: i32) = const 1_i32; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + StorageLive(_1); // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + ((_1 as Some).0: i32) = const 1_i32; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) // mir::Constant // + span: $DIR/issue-73223.rs:2:28: 2:29 // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } - discriminant(_2) = 1; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 - _4 = move _2; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 - StorageDead(_2); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 - StorageLive(_4); // scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + discriminant(_1) = 1; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + _2 = ((_1 as Some).0: i32); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + StorageDead(_1); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 + StorageLive(_3); // scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + StorageLive(_4); // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 + _4 = _2; // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 + ((_3 as Some).0: i32) = move _4; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + discriminant(_3) = 1; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + StorageDead(_4); // scope 1 at $DIR/issue-73223.rs:7:27: 7:28 StorageLive(_5); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL StorageLive(_6); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL - _6 = &_1; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _6 = &_2; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL (_5.0: &i32) = move _6; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL (_5.1: &i32) = const main::promoted[1]; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const @@ -127,8 +131,7 @@ // mir::Constant // + span: $DIR/issue-73223.rs:1:11: 9:2 // + literal: Const { ty: (), val: Value(Scalar()) } - StorageDead(_4); // scope 1 at $DIR/issue-73223.rs:9:1: 9:2 - StorageDead(_1); // scope 0 at $DIR/issue-73223.rs:9:1: 9:2 + StorageDead(_3); // scope 1 at $DIR/issue-73223.rs:9:1: 9:2 return; // scope 0 at $DIR/issue-73223.rs:9:2: 9:2 } diff --git a/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff b/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff index 2c1f81f2d732d..e5b4a0328808f 100644 --- a/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff @@ -134,18 +134,17 @@ } bb2: { -- StorageLive(_4); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 -- _4 = ((_2 as Some).0: i32); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 -- _1 = _4; // scope 2 at $DIR/issue-73223.rs:3:20: 3:21 -- StorageDead(_4); // scope 0 at $DIR/issue-73223.rs:3:21: 3:22 -+ _6 = move _2; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + StorageLive(_4); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + _4 = ((_2 as Some).0: i32); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + _1 = _4; // scope 2 at $DIR/issue-73223.rs:3:20: 3:21 + StorageDead(_4); // scope 0 at $DIR/issue-73223.rs:3:21: 3:22 StorageDead(_2); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 StorageLive(_6); // scope 1 at $DIR/issue-73223.rs:7:9: 7:14 -- StorageLive(_7); // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 -- _7 = _1; // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 -- ((_6 as Some).0: i32) = move _7; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 -- discriminant(_6) = 1; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 -- StorageDead(_7); // scope 1 at $DIR/issue-73223.rs:7:27: 7:28 + StorageLive(_7); // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 + _7 = _1; // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 + ((_6 as Some).0: i32) = move _7; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + discriminant(_6) = 1; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + StorageDead(_7); // scope 1 at $DIR/issue-73223.rs:7:27: 7:28 StorageLive(_8); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL StorageLive(_9); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL StorageLive(_10); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL diff --git a/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff b/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff index 887ebfc8c64e4..59c00e1b96f96 100644 --- a/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff +++ b/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff @@ -3,9 +3,9 @@ fn main() -> () { let mut _0: (); // return place in scope 0 at $DIR/issue-73223.rs:1:11: 1:11 - let _1: i32; // in scope 0 at $DIR/issue-73223.rs:2:9: 2:14 - let mut _2: std::option::Option; // in scope 0 at $DIR/issue-73223.rs:2:23: 2:30 - let _3: i32; // in scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + let mut _1: std::option::Option; // in scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + let _2: i32; // in scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + let mut _4: i32; // in scope 0 at $DIR/issue-73223.rs:7:22: 7:27 let mut _5: (&i32, &i32); // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL let mut _6: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL let mut _9: bool; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL @@ -28,10 +28,10 @@ let mut _28: std::fmt::ArgumentV1; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL let mut _29: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL scope 1 { - debug split => _1; // in scope 1 at $DIR/issue-73223.rs:2:9: 2:14 - let _4: std::option::Option; // in scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + debug split => _2; // in scope 1 at $DIR/issue-73223.rs:2:9: 2:14 + let _3: std::option::Option; // in scope 1 at $DIR/issue-73223.rs:7:9: 7:14 scope 3 { - debug _prev => _4; // in scope 3 at $DIR/issue-73223.rs:7:9: 7:14 + debug _prev => _3; // in scope 3 at $DIR/issue-73223.rs:7:9: 7:14 let _7: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL let _8: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL scope 4 { @@ -64,7 +64,7 @@ } } scope 2 { - debug v => _3; // in scope 2 at $DIR/issue-73223.rs:3:14: 3:15 + debug v => _2; // in scope 2 at $DIR/issue-73223.rs:3:14: 3:15 } scope 7 { } @@ -72,22 +72,26 @@ } bb0: { - StorageLive(_1); // scope 0 at $DIR/issue-73223.rs:2:9: 2:14 - StorageLive(_2); // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 - ((_2 as Some).0: i32) = const 1_i32; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + StorageLive(_1); // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + ((_1 as Some).0: i32) = const 1_i32; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) // mir::Constant // + span: $DIR/issue-73223.rs:2:28: 2:29 // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } - discriminant(_2) = 1; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 - _4 = move _2; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 - StorageDead(_2); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 - StorageLive(_4); // scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + discriminant(_1) = 1; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + _2 = ((_1 as Some).0: i32); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + StorageDead(_1); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 + StorageLive(_3); // scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + StorageLive(_4); // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 + _4 = _2; // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 + ((_3 as Some).0: i32) = move _4; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + discriminant(_3) = 1; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + StorageDead(_4); // scope 1 at $DIR/issue-73223.rs:7:27: 7:28 StorageLive(_5); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL StorageLive(_6); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL - _6 = &_1; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _6 = &_2; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL (_5.0: &i32) = move _6; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL (_5.1: &i32) = const main::promoted[1]; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const @@ -127,8 +131,7 @@ // mir::Constant // + span: $DIR/issue-73223.rs:1:11: 9:2 // + literal: Const { ty: (), val: Value(Scalar()) } - StorageDead(_4); // scope 1 at $DIR/issue-73223.rs:9:1: 9:2 - StorageDead(_1); // scope 0 at $DIR/issue-73223.rs:9:1: 9:2 + StorageDead(_3); // scope 1 at $DIR/issue-73223.rs:9:1: 9:2 return; // scope 0 at $DIR/issue-73223.rs:9:2: 9:2 } diff --git a/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff b/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff index 3233cc349f70d..0c2651dc3c68d 100644 --- a/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff @@ -134,18 +134,17 @@ } bb2: { -- StorageLive(_4); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 -- _4 = ((_2 as Some).0: i32); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 -- _1 = _4; // scope 2 at $DIR/issue-73223.rs:3:20: 3:21 -- StorageDead(_4); // scope 0 at $DIR/issue-73223.rs:3:21: 3:22 -+ _6 = move _2; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + StorageLive(_4); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + _4 = ((_2 as Some).0: i32); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + _1 = _4; // scope 2 at $DIR/issue-73223.rs:3:20: 3:21 + StorageDead(_4); // scope 0 at $DIR/issue-73223.rs:3:21: 3:22 StorageDead(_2); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 StorageLive(_6); // scope 1 at $DIR/issue-73223.rs:7:9: 7:14 -- StorageLive(_7); // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 -- _7 = _1; // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 -- ((_6 as Some).0: i32) = move _7; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 -- discriminant(_6) = 1; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 -- StorageDead(_7); // scope 1 at $DIR/issue-73223.rs:7:27: 7:28 + StorageLive(_7); // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 + _7 = _1; // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 + ((_6 as Some).0: i32) = move _7; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + discriminant(_6) = 1; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + StorageDead(_7); // scope 1 at $DIR/issue-73223.rs:7:27: 7:28 StorageLive(_8); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL StorageLive(_9); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL StorageLive(_10); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL diff --git a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff index f0b696118e996..318b1b3f72a08 100644 --- a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff +++ b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff @@ -19,7 +19,9 @@ } bb1: { - _0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 + _3 = move ((_1 as Some).0: std::boxed::Box<()>); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 + ((_0 as Some).0: std::boxed::Box<()>) = move _3; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 + discriminant(_0) = 1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 goto -> bb3; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:2:5: 5:6 } diff --git a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff index 1ac6eb85441f5..ace471aaa3c82 100644 --- a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff +++ b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff @@ -19,7 +19,9 @@ } bb1: { - _0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 + _3 = move ((_1 as Some).0: std::boxed::Box<()>); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 + ((_0 as Some).0: std::boxed::Box<()>) = move _3; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 + discriminant(_0) = 1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 goto -> bb3; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:2:5: 5:6 } diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff index 7f8366309c089..2caff43bfb582 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff @@ -50,37 +50,35 @@ } bb1: { -- StorageLive(_10); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 -- _10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 -- _2 = _10; // scope 5 at $DIR/simplify_try.rs:6:13: 6:15 -- StorageDead(_10); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 -+ _0 = move _3; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 + StorageLive(_10); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 + _10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 + _2 = _10; // scope 5 at $DIR/simplify_try.rs:6:13: 6:15 + StorageDead(_10); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 -- StorageLive(_11); // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 -- _11 = _2; // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 -- ((_0 as Ok).0: u32) = move _11; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 -- discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 -- StorageDead(_11); // scope 1 at $DIR/simplify_try.rs:7:9: 7:10 + StorageLive(_11); // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 + _11 = _2; // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 + ((_0 as Ok).0: u32) = move _11; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 + discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 + StorageDead(_11); // scope 1 at $DIR/simplify_try.rs:7:9: 7:10 StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 goto -> bb3; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 } bb2: { -- StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 -- _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 -- StorageLive(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 -- StorageLive(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 -- _9 = _6; // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 -- _8 = move _9; // scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL -- StorageDead(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 -- StorageLive(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL -- _12 = move _8; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL -- ((_0 as Err).0: i32) = move _12; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL -- discriminant(_0) = 1; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL -- StorageDead(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL -- StorageDead(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 -- StorageDead(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 -+ _0 = move _3; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + StorageLive(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + StorageLive(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + _9 = _6; // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + _8 = move _9; // scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL + StorageDead(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + StorageLive(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + _12 = move _8; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + ((_0 as Err).0: i32) = move _12; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + discriminant(_0) = 1; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + StorageDead(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + StorageDead(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + StorageDead(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 goto -> bb3; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir index be61e5e2a9fff..5000a1ec36cc8 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir @@ -45,17 +45,45 @@ fn try_identity(_1: std::result::Result) -> std::result::Result bb1; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 } bb1: { - _0 = move _3; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 + StorageLive(_10); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 + _10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 + _2 = _10; // scope 5 at $DIR/simplify_try.rs:6:13: 6:15 + StorageDead(_10); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 + StorageLive(_11); // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 + _11 = _2; // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 + ((_0 as Ok).0: u32) = move _11; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 + discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 + StorageDead(_11); // scope 1 at $DIR/simplify_try.rs:7:9: 7:10 StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 - goto -> bb2; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 + goto -> bb3; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 } bb2: { + StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + StorageLive(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + StorageLive(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + _9 = _6; // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + _8 = move _9; // scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL + StorageDead(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + StorageLive(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + _12 = move _8; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + ((_0 as Err).0: i32) = move _12; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + discriminant(_0) = 1; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + StorageDead(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + StorageDead(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + StorageDead(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 + StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 + goto -> bb3; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + } + + bb3: { return; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 } } diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir index b12036f6a03e4..77804c12691ee 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir @@ -3,27 +3,25 @@ fn try_identity(_1: std::result::Result) -> std::result::Result { debug x => _1; // in scope 0 at $DIR/simplify_try.rs:5:17: 5:18 let mut _0: std::result::Result; // return place in scope 0 at $DIR/simplify_try.rs:5:41: 5:57 - let _2: u32; // in scope 0 at $DIR/simplify_try.rs:6:9: 6:10 + let mut _2: isize; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 let _3: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let mut _4: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let mut _5: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let _6: u32; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:15 + let _4: u32; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:15 scope 1 { - debug y => _2; // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 + debug y => _4; // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 } scope 2 { debug err => _3; // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 scope 3 { scope 7 { - debug t => _5; // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL + debug t => _3; // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL } scope 8 { - debug v => _4; // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + debug v => _3; // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL } } } scope 4 { - debug val => _6; // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 + debug val => _4; // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 scope 5 { } } @@ -32,9 +30,25 @@ fn try_identity(_1: std::result::Result) -> std::result::Result [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + } + + bb1: { + _4 = ((_1 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 + ((_0 as Ok).0: u32) = move _4; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 + discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 + goto -> bb3; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 + } + + bb2: { + _3 = ((_1 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + ((_0 as Err).0: i32) = move _3; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + discriminant(_0) = 1; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + goto -> bb3; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + } + + bb3: { return; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 } }