Skip to content

Commit 4fae049

Browse files
committed
MatchBranchSimplification: copy discriminant instead of moving it
It might be necessary to use its value more than once.
1 parent 60d7d28 commit 4fae049

3 files changed

+3
-3
lines changed

src/librustc_mir/transform/match_branches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
7878
);
7979
if let Some(c) = c.literal.try_eval_bool(tcx, param_env) {
8080
let op = if c { BinOp::Eq } else { BinOp::Ne };
81-
*rhs = Rvalue::BinaryOp(op, Operand::Move(discr), const_cmp);
81+
*rhs = Rvalue::BinaryOp(op, Operand::Copy(discr), const_cmp);
8282
}
8383
}
8484
}

src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.diff.32bit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
StorageLive(_2); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
1212
_3 = discriminant(_1); // scope 0 at $DIR/matches_reduce_branches.rs:5:22: 5:26
1313
- switchInt(move _3) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_reduce_branches.rs:5:22: 5:26
14-
+ _2 = Eq(move _3, const 0_isize); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
14+
+ _2 = Eq(_3, const 0_isize); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
1515
+ // ty::Const
1616
+ // + ty: isize
1717
+ // + val: Value(Scalar(0x00000000))

src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.diff.64bit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
StorageLive(_2); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
1212
_3 = discriminant(_1); // scope 0 at $DIR/matches_reduce_branches.rs:5:22: 5:26
1313
- switchInt(move _3) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_reduce_branches.rs:5:22: 5:26
14-
+ _2 = Eq(move _3, const 0_isize); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
14+
+ _2 = Eq(_3, const 0_isize); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
1515
+ // ty::Const
1616
+ // + ty: isize
1717
+ // + val: Value(Scalar(0x0000000000000000))

0 commit comments

Comments
 (0)