Skip to content

Commit 4bd3361

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 59c80d8 commit 4bd3361

8 files changed

Lines changed: 16 additions & 17 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/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: {

tests/mir-opt/if_condition_int.opt_u32.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_u32);
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.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use core::intrinsics::mir::*;
1010
// EMIT_MIR if_condition_int.opt_u32.SimplifyComparisonIntegral.diff
1111
fn opt_u32(x: u32) -> u32 {
1212
// CHECK-LABEL: fn opt_u32(
13-
// FIXME: This should be copy.
14-
// CHECK: switchInt(move _1) -> [42: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
13+
// CHECK: switchInt(copy _1) -> [42: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
1514
// CHECK: [[BB1]]:
1615
// CHECK: _0 = const 0_u32;
1716
// CHECK: [[BB2]]:
@@ -34,7 +33,7 @@ fn dont_opt_bool(x: bool) -> u32 {
3433
// EMIT_MIR if_condition_int.opt_char.SimplifyComparisonIntegral.diff
3534
fn opt_char(x: char) -> u32 {
3635
// CHECK-LABEL: fn opt_char(
37-
// CHECK: switchInt(move _1) -> [120: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
36+
// CHECK: switchInt(copy _1) -> [120: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
3837
// CHECK: [[BB1]]:
3938
// CHECK: _0 = const 0_u32;
4039
// CHECK: [[BB2]]:
@@ -45,7 +44,7 @@ fn opt_char(x: char) -> u32 {
4544
// EMIT_MIR if_condition_int.opt_i8.SimplifyComparisonIntegral.diff
4645
fn opt_i8(x: i8) -> u32 {
4746
// CHECK-LABEL: fn opt_i8(
48-
// CHECK: switchInt(move _1) -> [42: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
47+
// CHECK: switchInt(copy _1) -> [42: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
4948
// CHECK: [[BB1]]:
5049
// CHECK: _0 = const 0_u32;
5150
// CHECK: [[BB2]]:
@@ -56,7 +55,7 @@ fn opt_i8(x: i8) -> u32 {
5655
// EMIT_MIR if_condition_int.opt_negative.SimplifyComparisonIntegral.diff
5756
fn opt_negative(x: i32) -> u32 {
5857
// CHECK-LABEL: fn opt_negative(
59-
// CHECK: switchInt(move _1) -> [4294967254: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
58+
// CHECK: switchInt(copy _1) -> [4294967254: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
6059
// CHECK: [[BB1]]:
6160
// CHECK: _0 = const 0_u32;
6261
// CHECK: [[BB2]]:
@@ -67,11 +66,11 @@ fn opt_negative(x: i32) -> u32 {
6766
// EMIT_MIR if_condition_int.opt_multiple_ifs.SimplifyComparisonIntegral.diff
6867
fn opt_multiple_ifs(x: u32) -> u32 {
6968
// CHECK-LABEL: fn opt_multiple_ifs(
70-
// CHECK: switchInt(move _1) -> [42: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
69+
// CHECK: switchInt(copy _1) -> [42: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
7170
// CHECK: [[BB1]]:
7271
// CHECK: _0 = const 0_u32;
7372
// CHECK: [[BB2]]:
74-
// CHECK: switchInt(move _1) -> [21: [[BB4:bb.*]], otherwise: [[BB3:bb.*]]];
73+
// CHECK: switchInt(copy _1) -> [21: [[BB4:bb.*]], otherwise: [[BB3:bb.*]]];
7574
// CHECK: [[BB3]]:
7675
// CHECK: _0 = const 1_u32;
7776
// CHECK: [[BB4]]:
@@ -90,7 +89,7 @@ fn opt_multiple_ifs(x: u32) -> u32 {
9089
fn dont_remove_comparison(a: i8) -> i32 {
9190
// CHECK-LABEL: fn dont_remove_comparison(
9291
// CHECK: [[b:_.*]] = Eq(copy _1, const 17_i8);
93-
// CHECK: switchInt(move _1) -> [17: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
92+
// CHECK: switchInt(copy _1) -> [17: [[BB1:bb.*]], otherwise: [[BB2:bb.*]]];
9493
// CHECK: [[BB1]]:
9594
// CHECK: [[cast_1:_.*]] = copy [[b]] as i32 (IntToInt);
9695
// CHECK: _0 = Add(const 100_i32, move [[cast_1]]);
@@ -109,7 +108,7 @@ fn dont_remove_comparison(a: i8) -> i32 {
109108
fn dont_opt_floats(a: f32) -> i32 {
110109
// CHECK-LABEL: fn dont_opt_floats(
111110
// CHECK: [[cmp:_.*]] = Eq(copy _1, const -42f32);
112-
// CHECK: switchInt(move [[cmp]]) -> [0: [[BB2:bb.*]], otherwise: [[BB1:bb.*]]];
111+
// CHECK: switchInt(copy [[cmp]]) -> [0: [[BB2:bb.*]], otherwise: [[BB1:bb.*]]];
113112
// CHECK: [[BB1]]:
114113
// CHECK: _0 = const 0_i32;
115114
// CHECK: [[BB2]]:

0 commit comments

Comments
 (0)