Use Copy in the SwitchInt terminator

Move can be used only when both the compared operand and the operand on switch are move operands.
This commit directly changes to Copy, because I don't know if Move has beneficial.
This commit is contained in:
dianqk 2026-01-10 20:27:08 +08:00
parent ac80ccec5f
commit 37f83fb11d
No known key found for this signature in database
16 changed files with 23 additions and 24 deletions

View file

@ -135,7 +135,7 @@ impl<'tcx> crate::MirPass<'tcx> for SimplifyComparisonIntegral {
let terminator = bb.terminator_mut();
terminator.kind =
TerminatorKind::SwitchInt { discr: Operand::Move(opt.to_switch_on), targets };
TerminatorKind::SwitchInt { discr: Operand::Copy(opt.to_switch_on), targets };
}
for (idx, bb_idx) in storage_deads_to_remove {

View file

@ -74,7 +74,7 @@
_23 = copy (((*_1).0: std::fmt::FormattingOptions).0: u32);
_22 = BitAnd(move _23, const core::fmt::flags::PRECISION_FLAG);
StorageDead(_23);
switchInt(move _22) -> [0: bb10, otherwise: bb11];
switchInt(copy _22) -> [0: bb10, otherwise: bb11];
}
bb4: {

View file

@ -74,7 +74,7 @@
_23 = copy (((*_1).0: std::fmt::FormattingOptions).0: u32);
_22 = BitAnd(move _23, const core::fmt::flags::PRECISION_FLAG);
StorageDead(_23);
switchInt(move _22) -> [0: bb10, otherwise: bb11];
switchInt(copy _22) -> [0: bb10, otherwise: bb11];
}
bb4: {

View file

@ -74,7 +74,7 @@
_23 = copy (((*_1).0: std::fmt::FormattingOptions).0: u32);
_22 = BitAnd(move _23, const core::fmt::flags::PRECISION_FLAG);
StorageDead(_23);
switchInt(move _22) -> [0: bb10, otherwise: bb11];
switchInt(copy _22) -> [0: bb10, otherwise: bb11];
}
bb4: {

View file

@ -74,7 +74,7 @@
_23 = copy (((*_1).0: std::fmt::FormattingOptions).0: u32);
_22 = BitAnd(move _23, const core::fmt::flags::PRECISION_FLAG);
StorageDead(_23);
switchInt(move _22) -> [0: bb10, otherwise: bb11];
switchInt(copy _22) -> [0: bb10, otherwise: bb11];
}
bb4: {

View file

@ -21,7 +21,7 @@
_2 = Eq(copy _1, const 17_i8);
StorageDead(_3);
- switchInt(copy _2) -> [0: bb2, otherwise: bb1];
+ switchInt(move _1) -> [17: bb1, otherwise: bb2];
+ switchInt(copy _1) -> [17: bb1, otherwise: bb2];
}
bb1: {

View file

@ -14,7 +14,7 @@
- _2 = Eq(copy _1, const 'x');
- switchInt(move _2) -> [0: bb2, otherwise: bb1];
+ nop;
+ switchInt(move _1) -> [120: bb1, otherwise: bb2];
+ switchInt(copy _1) -> [120: bb1, otherwise: bb2];
}
bb1: {

View file

@ -14,7 +14,7 @@
- _2 = Eq(copy _1, const 42_i8);
- switchInt(move _2) -> [0: bb2, otherwise: bb1];
+ nop;
+ switchInt(move _1) -> [42: bb1, otherwise: bb2];
+ switchInt(copy _1) -> [42: bb1, otherwise: bb2];
}
bb1: {

View file

@ -16,7 +16,7 @@
- _2 = Eq(copy _1, const 42_u32);
- switchInt(move _2) -> [0: bb2, otherwise: bb1];
+ nop;
+ switchInt(move _1) -> [42: bb1, otherwise: bb2];
+ switchInt(copy _1) -> [42: bb1, otherwise: bb2];
}
bb1: {
@ -33,7 +33,7 @@
- _4 = Ne(copy _1, const 21_u32);
- switchInt(move _4) -> [0: bb4, otherwise: bb3];
+ nop;
+ switchInt(move _1) -> [21: bb4, otherwise: bb3];
+ switchInt(copy _1) -> [21: bb4, otherwise: bb3];
}
bb3: {

View file

@ -14,7 +14,7 @@
- _2 = Eq(copy _1, const -42_i32);
- switchInt(move _2) -> [0: bb2, otherwise: bb1];
+ nop;
+ switchInt(move _1) -> [4294967254: bb1, otherwise: bb2];
+ switchInt(copy _1) -> [4294967254: bb1, otherwise: bb2];
}
bb1: {

View file

@ -14,7 +14,7 @@
- _2 = Eq(copy _1, const 42_u32);
- switchInt(move _2) -> [0: bb2, otherwise: bb1];
+ nop;
+ switchInt(move _1) -> [42: bb1, otherwise: bb2];
+ switchInt(copy _1) -> [42: bb1, otherwise: bb2];
}
bb1: {

View file

@ -10,8 +10,7 @@ use core::intrinsics::mir::*;
// EMIT_MIR if_condition_int.opt_u32.SimplifyComparisonIntegral.diff
fn opt_u32(x: u32) -> u32 {
// CHECK-LABEL: fn opt_u32(
// FIXME: This should be copy.
// CHECK: switchInt(move _1) -> [42: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
// CHECK: switchInt(copy _1) -> [42: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
// CHECK: [[BB1]]:
// CHECK: _0 = const 0_u32;
// CHECK: [[BB2]]:
@ -34,7 +33,7 @@ fn dont_opt_bool(x: bool) -> u32 {
// EMIT_MIR if_condition_int.opt_char.SimplifyComparisonIntegral.diff
fn opt_char(x: char) -> u32 {
// CHECK-LABEL: fn opt_char(
// CHECK: switchInt(move _1) -> [120: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
// CHECK: switchInt(copy _1) -> [120: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
// CHECK: [[BB1]]:
// CHECK: _0 = const 0_u32;
// CHECK: [[BB2]]:
@ -45,7 +44,7 @@ fn opt_char(x: char) -> u32 {
// EMIT_MIR if_condition_int.opt_i8.SimplifyComparisonIntegral.diff
fn opt_i8(x: i8) -> u32 {
// CHECK-LABEL: fn opt_i8(
// CHECK: switchInt(move _1) -> [42: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
// CHECK: switchInt(copy _1) -> [42: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
// CHECK: [[BB1]]:
// CHECK: _0 = const 0_u32;
// CHECK: [[BB2]]:
@ -56,7 +55,7 @@ fn opt_i8(x: i8) -> u32 {
// EMIT_MIR if_condition_int.opt_negative.SimplifyComparisonIntegral.diff
fn opt_negative(x: i32) -> u32 {
// CHECK-LABEL: fn opt_negative(
// CHECK: switchInt(move _1) -> [4294967254: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
// CHECK: switchInt(copy _1) -> [4294967254: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
// CHECK: [[BB1]]:
// CHECK: _0 = const 0_u32;
// CHECK: [[BB2]]:
@ -67,11 +66,11 @@ fn opt_negative(x: i32) -> u32 {
// EMIT_MIR if_condition_int.opt_multiple_ifs.SimplifyComparisonIntegral.diff
fn opt_multiple_ifs(x: u32) -> u32 {
// CHECK-LABEL: fn opt_multiple_ifs(
// CHECK: switchInt(move _1) -> [42: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
// CHECK: switchInt(copy _1) -> [42: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
// CHECK: [[BB1]]:
// CHECK: _0 = const 0_u32;
// CHECK: [[BB2]]:
// CHECK: switchInt(move _1) -> [21: [[BB4:bb.*]], otherwise: [[BB3:bb.*]]];
// CHECK: switchInt(copy _1) -> [21: [[BB4:bb.*]], otherwise: [[BB3:bb.*]]];
// CHECK: [[BB3]]:
// CHECK: _0 = const 1_u32;
// CHECK: [[BB4]]:
@ -90,7 +89,7 @@ fn opt_multiple_ifs(x: u32) -> u32 {
fn dont_remove_comparison(a: i8) -> i32 {
// CHECK-LABEL: fn dont_remove_comparison(
// CHECK: [[b:_.*]] = Eq(copy _1, const 17_i8);
// CHECK: switchInt(move _1) -> [17: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
// CHECK: switchInt(copy _1) -> [17: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
// CHECK: [[BB1]]:
// CHECK: [[cast_1:_.*]] = copy [[b]] as i32 (IntToInt);
// CHECK: _0 = Add(const 100_i32, move [[cast_1]]);

View file

@ -28,7 +28,7 @@ fn num_to_digit(_1: char) -> u32 {
StorageLive(_3);
_3 = discriminant(_2);
StorageDead(_2);
switchInt(move _3) -> [1: bb2, otherwise: bb7];
switchInt(copy _3) -> [1: bb2, otherwise: bb7];
}
bb2: {

View file

@ -28,7 +28,7 @@ fn num_to_digit(_1: char) -> u32 {
StorageLive(_3);
_3 = discriminant(_2);
StorageDead(_2);
switchInt(move _3) -> [1: bb2, otherwise: bb7];
switchInt(copy _3) -> [1: bb2, otherwise: bb7];
}
bb2: {

View file

@ -28,7 +28,7 @@ fn num_to_digit(_1: char) -> u32 {
StorageLive(_3);
_3 = discriminant(_2);
StorageDead(_2);
switchInt(move _3) -> [1: bb2, otherwise: bb7];
switchInt(copy _3) -> [1: bb2, otherwise: bb7];
}
bb2: {

View file

@ -28,7 +28,7 @@ fn num_to_digit(_1: char) -> u32 {
StorageLive(_3);
_3 = discriminant(_2);
StorageDead(_2);
switchInt(move _3) -> [1: bb2, otherwise: bb7];
switchInt(copy _3) -> [1: bb2, otherwise: bb7];
}
bb2: {