Skip to content

Commit 40e2c96

Browse files
committed
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.
1 parent 1b98353 commit 40e2c96

16 files changed

Lines changed: 23 additions & 24 deletions

compiler/rustc_mir_transform/src/simplify_comparison_integral.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl<'tcx> crate::MirPass<'tcx> for SimplifyComparisonIntegral {
136136

137137
let terminator = bb.terminator_mut();
138138
terminator.kind =
139-
TerminatorKind::SwitchInt { discr: Operand::Move(opt.to_switch_on), targets };
139+
TerminatorKind::SwitchInt { discr: Operand::Copy(opt.to_switch_on), targets };
140140
}
141141

142142
for (idx, bb_idx) in storage_deads_to_remove {

tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-abort.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
_23 = copy (((*_1).0: std::fmt::FormattingOptions).0: u32);
7575
_22 = BitAnd(move _23, const core::fmt::flags::PRECISION_FLAG);
7676
StorageDead(_23);
77-
switchInt(move _22) -> [0: bb10, otherwise: bb11];
77+
switchInt(copy _22) -> [0: bb10, otherwise: bb11];
7878
}
7979

8080
bb4: {

tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-unwind.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
_23 = copy (((*_1).0: std::fmt::FormattingOptions).0: u32);
7575
_22 = BitAnd(move _23, const core::fmt::flags::PRECISION_FLAG);
7676
StorageDead(_23);
77-
switchInt(move _22) -> [0: bb10, otherwise: bb11];
77+
switchInt(copy _22) -> [0: bb10, otherwise: bb11];
7878
}
7979

8080
bb4: {

tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-abort.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
_23 = copy (((*_1).0: std::fmt::FormattingOptions).0: u32);
7575
_22 = BitAnd(move _23, const core::fmt::flags::PRECISION_FLAG);
7676
StorageDead(_23);
77-
switchInt(move _22) -> [0: bb10, otherwise: bb11];
77+
switchInt(copy _22) -> [0: bb10, otherwise: bb11];
7878
}
7979

8080
bb4: {

tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-unwind.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
_23 = copy (((*_1).0: std::fmt::FormattingOptions).0: u32);
7575
_22 = BitAnd(move _23, const core::fmt::flags::PRECISION_FLAG);
7676
StorageDead(_23);
77-
switchInt(move _22) -> [0: bb10, otherwise: bb11];
77+
switchInt(copy _22) -> [0: bb10, otherwise: bb11];
7878
}
7979

8080
bb4: {

tests/mir-opt/if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
_2 = Eq(copy _1, const 17_i8);
2222
StorageDead(_3);
2323
- switchInt(copy _2) -> [0: bb2, otherwise: bb1];
24-
+ switchInt(move _1) -> [17: bb1, otherwise: bb2];
24+
+ switchInt(copy _1) -> [17: bb1, otherwise: bb2];
2525
}
2626

2727
bb1: {

tests/mir-opt/if_condition_int.opt_char.SimplifyComparisonIntegral.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
- _2 = Eq(copy _1, const 'x');
1515
- switchInt(move _2) -> [0: bb2, otherwise: bb1];
1616
+ nop;
17-
+ switchInt(move _1) -> [120: bb1, otherwise: bb2];
17+
+ switchInt(copy _1) -> [120: bb1, otherwise: bb2];
1818
}
1919

2020
bb1: {

tests/mir-opt/if_condition_int.opt_i8.SimplifyComparisonIntegral.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
- _2 = Eq(copy _1, const 42_i8);
1515
- switchInt(move _2) -> [0: bb2, otherwise: bb1];
1616
+ nop;
17-
+ switchInt(move _1) -> [42: bb1, otherwise: bb2];
17+
+ switchInt(copy _1) -> [42: bb1, otherwise: bb2];
1818
}
1919

2020
bb1: {

tests/mir-opt/if_condition_int.opt_multiple_ifs.SimplifyComparisonIntegral.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
- _2 = Eq(copy _1, const 42_u32);
1717
- switchInt(move _2) -> [0: bb2, otherwise: bb1];
1818
+ nop;
19-
+ switchInt(move _1) -> [42: bb1, otherwise: bb2];
19+
+ switchInt(copy _1) -> [42: bb1, otherwise: bb2];
2020
}
2121

2222
bb1: {
@@ -33,7 +33,7 @@
3333
- _4 = Ne(copy _1, const 21_u32);
3434
- switchInt(move _4) -> [0: bb4, otherwise: bb3];
3535
+ nop;
36-
+ switchInt(move _1) -> [21: bb4, otherwise: bb3];
36+
+ switchInt(copy _1) -> [21: bb4, otherwise: bb3];
3737
}
3838

3939
bb3: {

tests/mir-opt/if_condition_int.opt_negative.SimplifyComparisonIntegral.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
- _2 = Eq(copy _1, const -42_i32);
1515
- switchInt(move _2) -> [0: bb2, otherwise: bb1];
1616
+ nop;
17-
+ switchInt(move _1) -> [4294967254: bb1, otherwise: bb2];
17+
+ switchInt(copy _1) -> [4294967254: bb1, otherwise: bb2];
1818
}
1919

2020
bb1: {

0 commit comments

Comments
 (0)