From 4fae04968eccb8797000b5a42760005b35504136 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomasz=20Mi=C4=85sko?= Date: Fri, 14 Aug 2020 00:00:00 +0000 Subject: [PATCH] MatchBranchSimplification: copy discriminant instead of moving it It might be necessary to use its value more than once. --- src/librustc_mir/transform/match_branches.rs | 2 +- ...hes_reduce_branches.foo.MatchBranchSimplification.diff.32bit | 2 +- ...hes_reduce_branches.foo.MatchBranchSimplification.diff.64bit | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_mir/transform/match_branches.rs b/src/librustc_mir/transform/match_branches.rs index e6c5845cd48..cdf181aab02 100644 --- a/src/librustc_mir/transform/match_branches.rs +++ b/src/librustc_mir/transform/match_branches.rs @@ -78,7 +78,7 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut Body<'tcx ); if let Some(c) = c.literal.try_eval_bool(tcx, param_env) { let op = if c { BinOp::Eq } else { BinOp::Ne }; - *rhs = Rvalue::BinaryOp(op, Operand::Move(discr), const_cmp); + *rhs = Rvalue::BinaryOp(op, Operand::Copy(discr), const_cmp); } } } diff --git a/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.diff.32bit b/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.diff.32bit index df94c897e92..9324762fb08 100644 --- a/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.diff.32bit +++ b/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.diff.32bit @@ -11,7 +11,7 @@ StorageLive(_2); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL _3 = discriminant(_1); // scope 0 at $DIR/matches_reduce_branches.rs:5:22: 5:26 - switchInt(move _3) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_reduce_branches.rs:5:22: 5:26 -+ _2 = Eq(move _3, const 0_isize); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL ++ _2 = Eq(_3, const 0_isize); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + // ty::Const + // + ty: isize + // + val: Value(Scalar(0x00000000)) diff --git a/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.diff.64bit b/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.diff.64bit index 06849b4a5d9..144a71228ad 100644 --- a/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.diff.64bit +++ b/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.diff.64bit @@ -11,7 +11,7 @@ StorageLive(_2); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL _3 = discriminant(_1); // scope 0 at $DIR/matches_reduce_branches.rs:5:22: 5:26 - switchInt(move _3) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_reduce_branches.rs:5:22: 5:26 -+ _2 = Eq(move _3, const 0_isize); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL ++ _2 = Eq(_3, const 0_isize); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + // ty::Const + // + ty: isize + // + val: Value(Scalar(0x0000000000000000)) -- 2.44.0