diff options
| author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2020-08-14 00:00:00 +0000 |
|---|---|---|
| committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2020-08-14 22:21:56 +0200 |
| commit | 4fae04968eccb8797000b5a42760005b35504136 (patch) | |
| tree | 9b958512960a05e7232487fe765e9f84e2c4863e | |
| parent | 60d7d28948c1a3d5125f12a2254f6edb5077c4c9 (diff) | |
| download | rust-4fae04968eccb8797000b5a42760005b35504136.tar.gz rust-4fae04968eccb8797000b5a42760005b35504136.zip | |
MatchBranchSimplification: copy discriminant instead of moving it
It might be necessary to use its value more than once.
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 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification { ); 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)) |
