Skip to content

Commit 7770cab

Browse files
committed
Re-enable SimplifyToExp in match_branches.
1 parent 58eac70 commit 7770cab

9 files changed

+202
-160
lines changed

compiler/rustc_mir_transform/src/match_branches.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
4242
should_cleanup = true;
4343
continue;
4444
}
45-
// unsound: https://github.com/rust-lang/rust/issues/124150
46-
if tcx.sess.opts.unstable_opts.unsound_mir_opts
47-
&& SimplifyToExp::default().simplify(tcx, body, bb_idx, param_env).is_some()
48-
{
45+
if SimplifyToExp::default().simplify(tcx, body, bb_idx, param_env).is_some() {
4946
should_cleanup = true;
5047
continue;
5148
}

tests/mir-opt/matches_reduce_branches.match_i128_u128.MatchBranchSimplification.diff

+33-28
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,42 @@
55
debug i => _1;
66
let mut _0: u128;
77
let mut _2: i128;
8+
+ let mut _3: i128;
89

910
bb0: {
1011
_2 = discriminant(_1);
11-
switchInt(move _2) -> [1: bb3, 2: bb4, 3: bb5, 340282366920938463463374607431768211455: bb2, otherwise: bb1];
12-
}
13-
14-
bb1: {
15-
unreachable;
16-
}
17-
18-
bb2: {
19-
_0 = const core::num::<impl u128>::MAX;
20-
goto -> bb6;
21-
}
22-
23-
bb3: {
24-
_0 = const 1_u128;
25-
goto -> bb6;
26-
}
27-
28-
bb4: {
29-
_0 = const 2_u128;
30-
goto -> bb6;
31-
}
32-
33-
bb5: {
34-
_0 = const 3_u128;
35-
goto -> bb6;
36-
}
37-
38-
bb6: {
12+
- switchInt(move _2) -> [1: bb3, 2: bb4, 3: bb5, 340282366920938463463374607431768211455: bb2, otherwise: bb1];
13+
- }
14+
-
15+
- bb1: {
16+
- unreachable;
17+
- }
18+
-
19+
- bb2: {
20+
- _0 = const core::num::<impl u128>::MAX;
21+
- goto -> bb6;
22+
- }
23+
-
24+
- bb3: {
25+
- _0 = const 1_u128;
26+
- goto -> bb6;
27+
- }
28+
-
29+
- bb4: {
30+
- _0 = const 2_u128;
31+
- goto -> bb6;
32+
- }
33+
-
34+
- bb5: {
35+
- _0 = const 3_u128;
36+
- goto -> bb6;
37+
- }
38+
-
39+
- bb6: {
40+
+ StorageLive(_3);
41+
+ _3 = move _2;
42+
+ _0 = _3 as u128 (IntToInt);
43+
+ StorageDead(_3);
3944
return;
4045
}
4146
}

tests/mir-opt/matches_reduce_branches.match_i16_i8.MatchBranchSimplification.diff

+28-23
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,37 @@
55
debug i => _1;
66
let mut _0: i8;
77
let mut _2: i16;
8+
+ let mut _3: i16;
89

910
bb0: {
1011
_2 = discriminant(_1);
11-
switchInt(move _2) -> [65535: bb3, 2: bb4, 65533: bb2, otherwise: bb1];
12-
}
13-
14-
bb1: {
15-
unreachable;
16-
}
17-
18-
bb2: {
19-
_0 = const -3_i8;
20-
goto -> bb5;
21-
}
22-
23-
bb3: {
24-
_0 = const -1_i8;
25-
goto -> bb5;
26-
}
27-
28-
bb4: {
29-
_0 = const 2_i8;
30-
goto -> bb5;
31-
}
32-
33-
bb5: {
12+
- switchInt(move _2) -> [65535: bb3, 2: bb4, 65533: bb2, otherwise: bb1];
13+
- }
14+
-
15+
- bb1: {
16+
- unreachable;
17+
- }
18+
-
19+
- bb2: {
20+
- _0 = const -3_i8;
21+
- goto -> bb5;
22+
- }
23+
-
24+
- bb3: {
25+
- _0 = const -1_i8;
26+
- goto -> bb5;
27+
- }
28+
-
29+
- bb4: {
30+
- _0 = const 2_i8;
31+
- goto -> bb5;
32+
- }
33+
-
34+
- bb5: {
35+
+ StorageLive(_3);
36+
+ _3 = move _2;
37+
+ _0 = _3 as i8 (IntToInt);
38+
+ StorageDead(_3);
3439
return;
3540
}
3641
}

tests/mir-opt/matches_reduce_branches.match_i8_i16.MatchBranchSimplification.diff

+28-23
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,37 @@
55
debug i => _1;
66
let mut _0: i16;
77
let mut _2: i8;
8+
+ let mut _3: i8;
89

910
bb0: {
1011
_2 = discriminant(_1);
11-
switchInt(move _2) -> [255: bb3, 2: bb4, 253: bb2, otherwise: bb1];
12-
}
13-
14-
bb1: {
15-
unreachable;
16-
}
17-
18-
bb2: {
19-
_0 = const -3_i16;
20-
goto -> bb5;
21-
}
22-
23-
bb3: {
24-
_0 = const -1_i16;
25-
goto -> bb5;
26-
}
27-
28-
bb4: {
29-
_0 = const 2_i16;
30-
goto -> bb5;
31-
}
32-
33-
bb5: {
12+
- switchInt(move _2) -> [255: bb3, 2: bb4, 253: bb2, otherwise: bb1];
13+
- }
14+
-
15+
- bb1: {
16+
- unreachable;
17+
- }
18+
-
19+
- bb2: {
20+
- _0 = const -3_i16;
21+
- goto -> bb5;
22+
- }
23+
-
24+
- bb3: {
25+
- _0 = const -1_i16;
26+
- goto -> bb5;
27+
- }
28+
-
29+
- bb4: {
30+
- _0 = const 2_i16;
31+
- goto -> bb5;
32+
- }
33+
-
34+
- bb5: {
35+
+ StorageLive(_3);
36+
+ _3 = move _2;
37+
+ _0 = _3 as i16 (IntToInt);
38+
+ StorageDead(_3);
3439
return;
3540
}
3641
}

tests/mir-opt/matches_reduce_branches.match_u8_i16.MatchBranchSimplification.diff

+23-18
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,32 @@
55
debug i => _1;
66
let mut _0: i16;
77
let mut _2: u8;
8+
+ let mut _3: u8;
89

910
bb0: {
1011
_2 = discriminant(_1);
11-
switchInt(move _2) -> [1: bb3, 2: bb2, otherwise: bb1];
12-
}
13-
14-
bb1: {
15-
unreachable;
16-
}
17-
18-
bb2: {
19-
_0 = const 2_i16;
20-
goto -> bb4;
21-
}
22-
23-
bb3: {
24-
_0 = const 1_i16;
25-
goto -> bb4;
26-
}
27-
28-
bb4: {
12+
- switchInt(move _2) -> [1: bb3, 2: bb2, otherwise: bb1];
13+
- }
14+
-
15+
- bb1: {
16+
- unreachable;
17+
- }
18+
-
19+
- bb2: {
20+
- _0 = const 2_i16;
21+
- goto -> bb4;
22+
- }
23+
-
24+
- bb3: {
25+
- _0 = const 1_i16;
26+
- goto -> bb4;
27+
- }
28+
-
29+
- bb4: {
30+
+ StorageLive(_3);
31+
+ _3 = move _2;
32+
+ _0 = _3 as i16 (IntToInt);
33+
+ StorageDead(_3);
2934
return;
3035
}
3136
}

tests/mir-opt/matches_reduce_branches.match_u8_u16.MatchBranchSimplification.diff

+28-23
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,37 @@
55
debug i => _1;
66
let mut _0: u16;
77
let mut _2: u8;
8+
+ let mut _3: u8;
89

910
bb0: {
1011
_2 = discriminant(_1);
11-
switchInt(move _2) -> [1: bb3, 2: bb4, 5: bb2, otherwise: bb1];
12-
}
13-
14-
bb1: {
15-
unreachable;
16-
}
17-
18-
bb2: {
19-
_0 = const 5_u16;
20-
goto -> bb5;
21-
}
22-
23-
bb3: {
24-
_0 = const 1_u16;
25-
goto -> bb5;
26-
}
27-
28-
bb4: {
29-
_0 = const 2_u16;
30-
goto -> bb5;
31-
}
32-
33-
bb5: {
12+
- switchInt(move _2) -> [1: bb3, 2: bb4, 5: bb2, otherwise: bb1];
13+
- }
14+
-
15+
- bb1: {
16+
- unreachable;
17+
- }
18+
-
19+
- bb2: {
20+
- _0 = const 5_u16;
21+
- goto -> bb5;
22+
- }
23+
-
24+
- bb3: {
25+
- _0 = const 1_u16;
26+
- goto -> bb5;
27+
- }
28+
-
29+
- bb4: {
30+
- _0 = const 2_u16;
31+
- goto -> bb5;
32+
- }
33+
-
34+
- bb5: {
35+
+ StorageLive(_3);
36+
+ _3 = move _2;
37+
+ _0 = _3 as u16 (IntToInt);
38+
+ StorageDead(_3);
3439
return;
3540
}
3641
}

tests/mir-opt/matches_reduce_branches.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ enum EnumAu8 {
7575
// EMIT_MIR matches_reduce_branches.match_u8_i16.MatchBranchSimplification.diff
7676
fn match_u8_i16(i: EnumAu8) -> i16 {
7777
// CHECK-LABEL: fn match_u8_i16(
78-
// CHECK: switchInt
78+
// CHECK-NOT: switchInt
79+
// CHECK: _0 = _3 as i16 (IntToInt);
80+
// CHECH: return
7981
match i {
8082
EnumAu8::A => 1,
8183
EnumAu8::B => 2,
@@ -144,7 +146,9 @@ enum EnumBu8 {
144146
// EMIT_MIR matches_reduce_branches.match_u8_u16.MatchBranchSimplification.diff
145147
fn match_u8_u16(i: EnumBu8) -> u16 {
146148
// CHECK-LABEL: fn match_u8_u16(
147-
// CHECK: switchInt
149+
// CHECK-NOT: switchInt
150+
// CHECK: _0 = _3 as u16 (IntToInt);
151+
// CHECH: return
148152
match i {
149153
EnumBu8::A => 1,
150154
EnumBu8::B => 2,
@@ -200,7 +204,9 @@ enum EnumAi8 {
200204
// EMIT_MIR matches_reduce_branches.match_i8_i16.MatchBranchSimplification.diff
201205
fn match_i8_i16(i: EnumAi8) -> i16 {
202206
// CHECK-LABEL: fn match_i8_i16(
203-
// CHECK: switchInt
207+
// CHECK-NOT: switchInt
208+
// CHECK: _0 = _3 as i16 (IntToInt);
209+
// CHECH: return
204210
match i {
205211
EnumAi8::A => -1,
206212
EnumAi8::B => 2,
@@ -243,7 +249,9 @@ fn match_i8_i16_failed_2(i: EnumAi8) -> i16 {
243249
// EMIT_MIR matches_reduce_branches.match_i16_i8.MatchBranchSimplification.diff
244250
fn match_i16_i8(i: EnumAi16) -> i8 {
245251
// CHECK-LABEL: fn match_i16_i8(
246-
// CHECK: switchInt
252+
// CHECK-NOT: switchInt
253+
// CHECK: _0 = _3 as i8 (IntToInt);
254+
// CHECH: return
247255
match i {
248256
EnumAi16::A => -1,
249257
EnumAi16::B => 2,
@@ -262,7 +270,9 @@ enum EnumAi128 {
262270
// EMIT_MIR matches_reduce_branches.match_i128_u128.MatchBranchSimplification.diff
263271
fn match_i128_u128(i: EnumAi128) -> u128 {
264272
// CHECK-LABEL: fn match_i128_u128(
265-
// CHECK: switchInt
273+
// CHECK-NOT: switchInt
274+
// CHECK: _0 = _3 as u128 (IntToInt);
275+
// CHECH: return
266276
match i {
267277
EnumAi128::A => 1,
268278
EnumAi128::B => 2,

0 commit comments

Comments
 (0)