MatchBranchSimplification: copy discriminant instead of moving it

It might be necessary to use its value more than once.
This commit is contained in:
Tomasz Miąsko 2020-08-14 00:00:00 +00:00
parent 60d7d28948
commit 4fae04968e
3 changed files with 3 additions and 3 deletions

View File

@ -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);
}
}
}

View File

@ -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))

View File

@ -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))