Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8b9d7b1

Browse files
committedAug 3, 2024
Simplify match based on the cast result of IntToInt.
1 parent 1df0458 commit 8b9d7b1

File tree

40 files changed

+1937
-532
lines changed

40 files changed

+1937
-532
lines changed
 

‎Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4346,6 +4346,7 @@ dependencies = [
43464346
"rustc_span",
43474347
"rustc_target",
43484348
"rustc_trait_selection",
4349+
"rustc_type_ir",
43494350
"smallvec",
43504351
"tracing",
43514352
]

‎compiler/rustc_mir_transform/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ rustc_session = { path = "../rustc_session" }
2525
rustc_span = { path = "../rustc_span" }
2626
rustc_target = { path = "../rustc_target" }
2727
rustc_trait_selection = { path = "../rustc_trait_selection" }
28+
rustc_type_ir = { path = "../rustc_type_ir" }
2829
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2930
tracing = "0.1"
3031
# tidy-alphabetical-end

‎compiler/rustc_mir_transform/src/match_branches.rs

Lines changed: 79 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ use std::iter;
33
use rustc_index::IndexSlice;
44
use rustc_middle::mir::patch::MirPatch;
55
use rustc_middle::mir::*;
6+
use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
67
use rustc_middle::ty::{ParamEnv, ScalarInt, Ty, TyCtxt};
7-
use rustc_target::abi::Size;
8+
use rustc_target::abi::Integer;
9+
use rustc_type_ir::TyKind::*;
810

911
use super::simplify::simplify_cfg;
1012

@@ -264,33 +266,56 @@ impl<'tcx> SimplifyMatch<'tcx> for SimplifyToIf {
264266
}
265267
}
266268

269+
/// Check if the cast constant using `IntToInt` is equal to the target constant.
270+
fn can_cast(
271+
tcx: TyCtxt<'_>,
272+
src_val: impl Into<u128>,
273+
src_layout: TyAndLayout<'_>,
274+
cast_ty: Ty<'_>,
275+
target_scalar: ScalarInt,
276+
) -> bool {
277+
let from_scalar = ScalarInt::try_from_uint(src_val.into(), src_layout.size).unwrap();
278+
let v = match src_layout.ty.kind() {
279+
Uint(_) => from_scalar.to_uint(src_layout.size),
280+
Int(_) => from_scalar.to_int(src_layout.size) as u128,
281+
_ => unreachable!("invalid int"),
282+
};
283+
let size = match *cast_ty.kind() {
284+
Int(t) => Integer::from_int_ty(&tcx, t).size(),
285+
Uint(t) => Integer::from_uint_ty(&tcx, t).size(),
286+
_ => unreachable!("invalid int"),
287+
};
288+
let v = size.truncate(v);
289+
let cast_scalar = ScalarInt::try_from_uint(v, size).unwrap();
290+
cast_scalar == target_scalar
291+
}
292+
267293
#[derive(Default)]
268294
struct SimplifyToExp {
269-
transfrom_types: Vec<TransfromType>,
295+
transfrom_kinds: Vec<TransfromKind>,
270296
}
271297

272298
#[derive(Clone, Copy)]
273-
enum CompareType<'tcx, 'a> {
299+
enum ExpectedTransformKind<'tcx, 'a> {
274300
/// Identical statements.
275301
Same(&'a StatementKind<'tcx>),
276302
/// Assignment statements have the same value.
277-
Eq(&'a Place<'tcx>, Ty<'tcx>, ScalarInt),
303+
SameByEq { place: &'a Place<'tcx>, ty: Ty<'tcx>, scalar: ScalarInt },
278304
/// Enum variant comparison type.
279-
Discr { place: &'a Place<'tcx>, ty: Ty<'tcx>, is_signed: bool },
305+
Cast { place: &'a Place<'tcx>, ty: Ty<'tcx> },
280306
}
281307

282-
enum TransfromType {
308+
enum TransfromKind {
283309
Same,
284-
Eq,
285-
Discr,
310+
Cast,
286311
}
287312

288-
impl From<CompareType<'_, '_>> for TransfromType {
289-
fn from(compare_type: CompareType<'_, '_>) -> Self {
313+
impl From<ExpectedTransformKind<'_, '_>> for TransfromKind {
314+
fn from(compare_type: ExpectedTransformKind<'_, '_>) -> Self {
290315
match compare_type {
291-
CompareType::Same(_) => TransfromType::Same,
292-
CompareType::Eq(_, _, _) => TransfromType::Eq,
293-
CompareType::Discr { .. } => TransfromType::Discr,
316+
ExpectedTransformKind::Same(_) => TransfromKind::Same,
317+
ExpectedTransformKind::SameByEq { .. } => TransfromKind::Same,
318+
ExpectedTransformKind::Cast { .. } => TransfromKind::Cast,
294319
}
295320
}
296321
}
@@ -354,7 +379,7 @@ impl<'tcx> SimplifyMatch<'tcx> for SimplifyToExp {
354379
return None;
355380
}
356381
let mut target_iter = targets.iter();
357-
let (first_val, first_target) = target_iter.next().unwrap();
382+
let (first_case_val, first_target) = target_iter.next().unwrap();
358383
let first_terminator_kind = &bbs[first_target].terminator().kind;
359384
// Check that destinations are identical, and if not, then don't optimize this block
360385
if !targets
@@ -364,24 +389,20 @@ impl<'tcx> SimplifyMatch<'tcx> for SimplifyToExp {
364389
return None;
365390
}
366391

367-
let discr_size = tcx.layout_of(param_env.and(discr_ty)).unwrap().size;
392+
let discr_layout = tcx.layout_of(param_env.and(discr_ty)).unwrap();
368393
let first_stmts = &bbs[first_target].statements;
369-
let (second_val, second_target) = target_iter.next().unwrap();
394+
let (second_case_val, second_target) = target_iter.next().unwrap();
370395
let second_stmts = &bbs[second_target].statements;
371396
if first_stmts.len() != second_stmts.len() {
372397
return None;
373398
}
374399

375-
fn int_equal(l: ScalarInt, r: impl Into<u128>, size: Size) -> bool {
376-
l.to_bits_unchecked() == ScalarInt::try_from_uint(r, size).unwrap().to_bits_unchecked()
377-
}
378-
379400
// We first compare the two branches, and then the other branches need to fulfill the same conditions.
380-
let mut compare_types = Vec::new();
401+
let mut expected_transform_kinds = Vec::new();
381402
for (f, s) in iter::zip(first_stmts, second_stmts) {
382403
let compare_type = match (&f.kind, &s.kind) {
383404
// If two statements are exactly the same, we can optimize.
384-
(f_s, s_s) if f_s == s_s => CompareType::Same(f_s),
405+
(f_s, s_s) if f_s == s_s => ExpectedTransformKind::Same(f_s),
385406

386407
// If two statements are assignments with the match values to the same place, we can optimize.
387408
(
@@ -395,22 +416,29 @@ impl<'tcx> SimplifyMatch<'tcx> for SimplifyToExp {
395416
f_c.const_.try_eval_scalar_int(tcx, param_env),
396417
s_c.const_.try_eval_scalar_int(tcx, param_env),
397418
) {
398-
(Some(f), Some(s)) if f == s => CompareType::Eq(lhs_f, f_c.const_.ty(), f),
399-
// Enum variants can also be simplified to an assignment statement if their values are equal.
400-
// We need to consider both unsigned and signed scenarios here.
419+
(Some(f), Some(s)) if f == s => ExpectedTransformKind::SameByEq {
420+
place: lhs_f,
421+
ty: f_c.const_.ty(),
422+
scalar: f,
423+
},
424+
// Enum variants can also be simplified to an assignment statement,
425+
// if we can use `IntToInt` cast to get an equal value.
401426
(Some(f), Some(s))
402-
if ((f_c.const_.ty().is_signed() || discr_ty.is_signed())
403-
&& int_equal(f, first_val, discr_size)
404-
&& int_equal(s, second_val, discr_size))
405-
|| (Some(f) == ScalarInt::try_from_uint(first_val, f.size())
406-
&& Some(s)
407-
== ScalarInt::try_from_uint(second_val, s.size())) =>
427+
if (can_cast(
428+
tcx,
429+
first_case_val,
430+
discr_layout,
431+
f_c.const_.ty(),
432+
f,
433+
) && can_cast(
434+
tcx,
435+
second_case_val,
436+
discr_layout,
437+
f_c.const_.ty(),
438+
s,
439+
)) =>
408440
{
409-
CompareType::Discr {
410-
place: lhs_f,
411-
ty: f_c.const_.ty(),
412-
is_signed: f_c.const_.ty().is_signed() || discr_ty.is_signed(),
413-
}
441+
ExpectedTransformKind::Cast { place: lhs_f, ty: f_c.const_.ty() }
414442
}
415443
_ => {
416444
return None;
@@ -421,47 +449,36 @@ impl<'tcx> SimplifyMatch<'tcx> for SimplifyToExp {
421449
// Otherwise we cannot optimize. Try another block.
422450
_ => return None,
423451
};
424-
compare_types.push(compare_type);
452+
expected_transform_kinds.push(compare_type);
425453
}
426454

427455
// All remaining BBs need to fulfill the same pattern as the two BBs from the previous step.
428456
for (other_val, other_target) in target_iter {
429457
let other_stmts = &bbs[other_target].statements;
430-
if compare_types.len() != other_stmts.len() {
458+
if expected_transform_kinds.len() != other_stmts.len() {
431459
return None;
432460
}
433-
for (f, s) in iter::zip(&compare_types, other_stmts) {
461+
for (f, s) in iter::zip(&expected_transform_kinds, other_stmts) {
434462
match (*f, &s.kind) {
435-
(CompareType::Same(f_s), s_s) if f_s == s_s => {}
463+
(ExpectedTransformKind::Same(f_s), s_s) if f_s == s_s => {}
436464
(
437-
CompareType::Eq(lhs_f, f_ty, val),
465+
ExpectedTransformKind::SameByEq { place: lhs_f, ty: f_ty, scalar },
438466
StatementKind::Assign(box (lhs_s, Rvalue::Use(Operand::Constant(s_c)))),
439467
) if lhs_f == lhs_s
440468
&& s_c.const_.ty() == f_ty
441-
&& s_c.const_.try_eval_scalar_int(tcx, param_env) == Some(val) => {}
469+
&& s_c.const_.try_eval_scalar_int(tcx, param_env) == Some(scalar) => {}
442470
(
443-
CompareType::Discr { place: lhs_f, ty: f_ty, is_signed },
471+
ExpectedTransformKind::Cast { place: lhs_f, ty: f_ty },
444472
StatementKind::Assign(box (lhs_s, Rvalue::Use(Operand::Constant(s_c)))),
445-
) if lhs_f == lhs_s && s_c.const_.ty() == f_ty => {
446-
let Some(f) = s_c.const_.try_eval_scalar_int(tcx, param_env) else {
447-
return None;
448-
};
449-
if is_signed
450-
&& s_c.const_.ty().is_signed()
451-
&& int_equal(f, other_val, discr_size)
452-
{
453-
continue;
454-
}
455-
if Some(f) == ScalarInt::try_from_uint(other_val, f.size()) {
456-
continue;
457-
}
458-
return None;
459-
}
473+
) if let Some(f) = s_c.const_.try_eval_scalar_int(tcx, param_env)
474+
&& lhs_f == lhs_s
475+
&& s_c.const_.ty() == f_ty
476+
&& can_cast(tcx, other_val, discr_layout, f_ty, f) => {}
460477
_ => return None,
461478
}
462479
}
463480
}
464-
self.transfrom_types = compare_types.into_iter().map(|c| c.into()).collect();
481+
self.transfrom_kinds = expected_transform_kinds.into_iter().map(|c| c.into()).collect();
465482
Some(())
466483
}
467484

@@ -479,13 +496,13 @@ impl<'tcx> SimplifyMatch<'tcx> for SimplifyToExp {
479496
let (_, first) = targets.iter().next().unwrap();
480497
let first = &bbs[first];
481498

482-
for (t, s) in iter::zip(&self.transfrom_types, &first.statements) {
499+
for (t, s) in iter::zip(&self.transfrom_kinds, &first.statements) {
483500
match (t, &s.kind) {
484-
(TransfromType::Same, _) | (TransfromType::Eq, _) => {
501+
(TransfromKind::Same, _) => {
485502
patch.add_statement(parent_end, s.kind.clone());
486503
}
487504
(
488-
TransfromType::Discr,
505+
TransfromKind::Cast,
489506
StatementKind::Assign(box (lhs, Rvalue::Use(Operand::Constant(f_c)))),
490507
) => {
491508
let operand = Operand::Copy(Place::from(discr_local));

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

Lines changed: 33 additions & 28 deletions
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: bb5, 2: bb4, 3: bb3, 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 3_u128;
25-
goto -> bb6;
26-
}
27-
28-
bb4: {
29-
_0 = const 2_u128;
30-
goto -> bb6;
31-
}
32-
33-
bb5: {
34-
_0 = const 1_u128;
35-
goto -> bb6;
36-
}
37-
38-
bb6: {
12+
- switchInt(move _2) -> [1: bb5, 2: bb4, 3: bb3, 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 3_u128;
26+
- goto -> bb6;
27+
- }
28+
-
29+
- bb4: {
30+
- _0 = const 2_u128;
31+
- goto -> bb6;
32+
- }
33+
-
34+
- bb5: {
35+
- _0 = const 1_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

Lines changed: 0 additions & 37 deletions
This file was deleted.

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

Lines changed: 0 additions & 37 deletions
This file was deleted.

‎tests/mir-opt/matches_reduce_branches.match_i8_i16_failed.MatchBranchSimplification.diff

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
- // MIR for `match_sext_i8_i16` before MatchBranchSimplification
2+
+ // MIR for `match_sext_i8_i16` after MatchBranchSimplification
3+
4+
fn match_sext_i8_i16(_1: EnumAi8) -> i16 {
5+
debug i => _1;
6+
let mut _0: i16;
7+
let mut _2: i8;
8+
+ let mut _3: i8;
9+
10+
bb0: {
11+
_2 = discriminant(_1);
12+
- switchInt(move _2) -> [128: bb6, 255: bb5, 0: bb4, 1: bb3, 127: bb2, otherwise: bb1];
13+
- }
14+
-
15+
- bb1: {
16+
- unreachable;
17+
- }
18+
-
19+
- bb2: {
20+
- _0 = const 127_i16;
21+
- goto -> bb7;
22+
- }
23+
-
24+
- bb3: {
25+
- _0 = const 1_i16;
26+
- goto -> bb7;
27+
- }
28+
-
29+
- bb4: {
30+
- _0 = const 0_i16;
31+
- goto -> bb7;
32+
- }
33+
-
34+
- bb5: {
35+
- _0 = const -1_i16;
36+
- goto -> bb7;
37+
- }
38+
-
39+
- bb6: {
40+
- _0 = const -128_i16;
41+
- goto -> bb7;
42+
- }
43+
-
44+
- bb7: {
45+
+ StorageLive(_3);
46+
+ _3 = move _2;
47+
+ _0 = _3 as i16 (IntToInt);
48+
+ StorageDead(_3);
49+
return;
50+
}
51+
}
52+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
- // MIR for `match_sext_i8_i16_failed` before MatchBranchSimplification
2+
+ // MIR for `match_sext_i8_i16_failed` after MatchBranchSimplification
3+
4+
fn match_sext_i8_i16_failed(_1: EnumAi8) -> i16 {
5+
debug i => _1;
6+
let mut _0: i16;
7+
let mut _2: i8;
8+
9+
bb0: {
10+
_2 = discriminant(_1);
11+
switchInt(move _2) -> [128: bb6, 255: bb5, 0: bb4, 1: bb3, 127: bb2, otherwise: bb1];
12+
}
13+
14+
bb1: {
15+
unreachable;
16+
}
17+
18+
bb2: {
19+
_0 = const 127_i16;
20+
goto -> bb7;
21+
}
22+
23+
bb3: {
24+
_0 = const 1_i16;
25+
goto -> bb7;
26+
}
27+
28+
bb4: {
29+
_0 = const 0_i16;
30+
goto -> bb7;
31+
}
32+
33+
bb5: {
34+
_0 = const 255_i16;
35+
goto -> bb7;
36+
}
37+
38+
bb6: {
39+
_0 = const -128_i16;
40+
goto -> bb7;
41+
}
42+
43+
bb7: {
44+
return;
45+
}
46+
}
47+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
- // MIR for `match_sext_i8_u16` before MatchBranchSimplification
2+
+ // MIR for `match_sext_i8_u16` after MatchBranchSimplification
3+
4+
fn match_sext_i8_u16(_1: EnumAi8) -> u16 {
5+
debug i => _1;
6+
let mut _0: u16;
7+
let mut _2: i8;
8+
+ let mut _3: i8;
9+
10+
bb0: {
11+
_2 = discriminant(_1);
12+
- switchInt(move _2) -> [128: bb6, 255: bb5, 0: bb4, 1: bb3, 127: bb2, otherwise: bb1];
13+
- }
14+
-
15+
- bb1: {
16+
- unreachable;
17+
- }
18+
-
19+
- bb2: {
20+
- _0 = const 127_u16;
21+
- goto -> bb7;
22+
- }
23+
-
24+
- bb3: {
25+
- _0 = const 1_u16;
26+
- goto -> bb7;
27+
- }
28+
-
29+
- bb4: {
30+
- _0 = const 0_u16;
31+
- goto -> bb7;
32+
- }
33+
-
34+
- bb5: {
35+
- _0 = const u16::MAX;
36+
- goto -> bb7;
37+
- }
38+
-
39+
- bb6: {
40+
- _0 = const 65408_u16;
41+
- goto -> bb7;
42+
- }
43+
-
44+
- bb7: {
45+
+ StorageLive(_3);
46+
+ _3 = move _2;
47+
+ _0 = _3 as u16 (IntToInt);
48+
+ StorageDead(_3);
49+
return;
50+
}
51+
}
52+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
- // MIR for `match_sext_i8_u16_failed` before MatchBranchSimplification
2+
+ // MIR for `match_sext_i8_u16_failed` after MatchBranchSimplification
3+
4+
fn match_sext_i8_u16_failed(_1: EnumAi8) -> u16 {
5+
debug i => _1;
6+
let mut _0: u16;
7+
let mut _2: i8;
8+
9+
bb0: {
10+
_2 = discriminant(_1);
11+
switchInt(move _2) -> [128: bb6, 255: bb5, 0: bb4, 1: bb3, 127: bb2, otherwise: bb1];
12+
}
13+
14+
bb1: {
15+
unreachable;
16+
}
17+
18+
bb2: {
19+
_0 = const 127_u16;
20+
goto -> bb7;
21+
}
22+
23+
bb3: {
24+
_0 = const 1_u16;
25+
goto -> bb7;
26+
}
27+
28+
bb4: {
29+
_0 = const 0_u16;
30+
goto -> bb7;
31+
}
32+
33+
bb5: {
34+
_0 = const 255_u16;
35+
goto -> bb7;
36+
}
37+
38+
bb6: {
39+
_0 = const 65408_u16;
40+
goto -> bb7;
41+
}
42+
43+
bb7: {
44+
return;
45+
}
46+
}
47+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
- // MIR for `match_trunc_i16_i8` before MatchBranchSimplification
2+
+ // MIR for `match_trunc_i16_i8` after MatchBranchSimplification
3+
4+
fn match_trunc_i16_i8(_1: EnumAi16) -> i8 {
5+
debug i => _1;
6+
let mut _0: i8;
7+
let mut _2: i16;
8+
+ let mut _3: i16;
9+
10+
bb0: {
11+
_2 = discriminant(_1);
12+
- switchInt(move _2) -> [128: bb11, 255: bb10, 0: bb9, 1: bb8, 127: bb7, 65408: bb6, 65535: bb5, 65280: bb4, 65281: bb3, 65407: bb2, otherwise: bb1];
13+
- }
14+
-
15+
- bb1: {
16+
- unreachable;
17+
- }
18+
-
19+
- bb2: {
20+
- _0 = const i8::MAX;
21+
- goto -> bb12;
22+
- }
23+
-
24+
- bb3: {
25+
- _0 = const 1_i8;
26+
- goto -> bb12;
27+
- }
28+
-
29+
- bb4: {
30+
- _0 = const 0_i8;
31+
- goto -> bb12;
32+
- }
33+
-
34+
- bb5: {
35+
- _0 = const -1_i8;
36+
- goto -> bb12;
37+
- }
38+
-
39+
- bb6: {
40+
- _0 = const i8::MIN;
41+
- goto -> bb12;
42+
- }
43+
-
44+
- bb7: {
45+
- _0 = const i8::MAX;
46+
- goto -> bb12;
47+
- }
48+
-
49+
- bb8: {
50+
- _0 = const 1_i8;
51+
- goto -> bb12;
52+
- }
53+
-
54+
- bb9: {
55+
- _0 = const 0_i8;
56+
- goto -> bb12;
57+
- }
58+
-
59+
- bb10: {
60+
- _0 = const -1_i8;
61+
- goto -> bb12;
62+
- }
63+
-
64+
- bb11: {
65+
- _0 = const i8::MIN;
66+
- goto -> bb12;
67+
- }
68+
-
69+
- bb12: {
70+
+ StorageLive(_3);
71+
+ _3 = move _2;
72+
+ _0 = _3 as i8 (IntToInt);
73+
+ StorageDead(_3);
74+
return;
75+
}
76+
}
77+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
- // MIR for `match_trunc_i16_i8_failed` before MatchBranchSimplification
2+
+ // MIR for `match_trunc_i16_i8_failed` after MatchBranchSimplification
3+
4+
fn match_trunc_i16_i8_failed(_1: EnumAi16) -> i8 {
5+
debug i => _1;
6+
let mut _0: i8;
7+
let mut _2: i16;
8+
9+
bb0: {
10+
_2 = discriminant(_1);
11+
switchInt(move _2) -> [128: bb11, 255: bb10, 0: bb9, 1: bb8, 127: bb7, 65408: bb6, 65535: bb5, 65280: bb4, 65281: bb3, 65407: bb2, otherwise: bb1];
12+
}
13+
14+
bb1: {
15+
unreachable;
16+
}
17+
18+
bb2: {
19+
_0 = const -127_i8;
20+
goto -> bb12;
21+
}
22+
23+
bb3: {
24+
_0 = const 1_i8;
25+
goto -> bb12;
26+
}
27+
28+
bb4: {
29+
_0 = const 0_i8;
30+
goto -> bb12;
31+
}
32+
33+
bb5: {
34+
_0 = const -1_i8;
35+
goto -> bb12;
36+
}
37+
38+
bb6: {
39+
_0 = const i8::MIN;
40+
goto -> bb12;
41+
}
42+
43+
bb7: {
44+
_0 = const i8::MAX;
45+
goto -> bb12;
46+
}
47+
48+
bb8: {
49+
_0 = const 1_i8;
50+
goto -> bb12;
51+
}
52+
53+
bb9: {
54+
_0 = const 0_i8;
55+
goto -> bb12;
56+
}
57+
58+
bb10: {
59+
_0 = const -1_i8;
60+
goto -> bb12;
61+
}
62+
63+
bb11: {
64+
_0 = const i8::MIN;
65+
goto -> bb12;
66+
}
67+
68+
bb12: {
69+
return;
70+
}
71+
}
72+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
- // MIR for `match_trunc_i16_u8` before MatchBranchSimplification
2+
+ // MIR for `match_trunc_i16_u8` after MatchBranchSimplification
3+
4+
fn match_trunc_i16_u8(_1: EnumAi16) -> u8 {
5+
debug i => _1;
6+
let mut _0: u8;
7+
let mut _2: i16;
8+
+ let mut _3: i16;
9+
10+
bb0: {
11+
_2 = discriminant(_1);
12+
- switchInt(move _2) -> [128: bb11, 255: bb10, 0: bb9, 1: bb8, 127: bb7, 65408: bb6, 65535: bb5, 65280: bb4, 65281: bb3, 65407: bb2, otherwise: bb1];
13+
- }
14+
-
15+
- bb1: {
16+
- unreachable;
17+
- }
18+
-
19+
- bb2: {
20+
- _0 = const 127_u8;
21+
- goto -> bb12;
22+
- }
23+
-
24+
- bb3: {
25+
- _0 = const 1_u8;
26+
- goto -> bb12;
27+
- }
28+
-
29+
- bb4: {
30+
- _0 = const 0_u8;
31+
- goto -> bb12;
32+
- }
33+
-
34+
- bb5: {
35+
- _0 = const u8::MAX;
36+
- goto -> bb12;
37+
- }
38+
-
39+
- bb6: {
40+
- _0 = const 128_u8;
41+
- goto -> bb12;
42+
- }
43+
-
44+
- bb7: {
45+
- _0 = const 127_u8;
46+
- goto -> bb12;
47+
- }
48+
-
49+
- bb8: {
50+
- _0 = const 1_u8;
51+
- goto -> bb12;
52+
- }
53+
-
54+
- bb9: {
55+
- _0 = const 0_u8;
56+
- goto -> bb12;
57+
- }
58+
-
59+
- bb10: {
60+
- _0 = const u8::MAX;
61+
- goto -> bb12;
62+
- }
63+
-
64+
- bb11: {
65+
- _0 = const 128_u8;
66+
- goto -> bb12;
67+
- }
68+
-
69+
- bb12: {
70+
+ StorageLive(_3);
71+
+ _3 = move _2;
72+
+ _0 = _3 as u8 (IntToInt);
73+
+ StorageDead(_3);
74+
return;
75+
}
76+
}
77+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
- // MIR for `match_trunc_i16_u8_failed` before MatchBranchSimplification
2+
+ // MIR for `match_trunc_i16_u8_failed` after MatchBranchSimplification
3+
4+
fn match_trunc_i16_u8_failed(_1: EnumAi16) -> u8 {
5+
debug i => _1;
6+
let mut _0: u8;
7+
let mut _2: i16;
8+
9+
bb0: {
10+
_2 = discriminant(_1);
11+
switchInt(move _2) -> [128: bb11, 255: bb10, 0: bb9, 1: bb8, 127: bb7, 65408: bb6, 65535: bb5, 65280: bb4, 65281: bb3, 65407: bb2, otherwise: bb1];
12+
}
13+
14+
bb1: {
15+
unreachable;
16+
}
17+
18+
bb2: {
19+
_0 = const -127_i8 as u8 (IntToInt);
20+
goto -> bb12;
21+
}
22+
23+
bb3: {
24+
_0 = const 1_u8;
25+
goto -> bb12;
26+
}
27+
28+
bb4: {
29+
_0 = const 0_u8;
30+
goto -> bb12;
31+
}
32+
33+
bb5: {
34+
_0 = const u8::MAX;
35+
goto -> bb12;
36+
}
37+
38+
bb6: {
39+
_0 = const 128_u8;
40+
goto -> bb12;
41+
}
42+
43+
bb7: {
44+
_0 = const 127_u8;
45+
goto -> bb12;
46+
}
47+
48+
bb8: {
49+
_0 = const 1_u8;
50+
goto -> bb12;
51+
}
52+
53+
bb9: {
54+
_0 = const 0_u8;
55+
goto -> bb12;
56+
}
57+
58+
bb10: {
59+
_0 = const u8::MAX;
60+
goto -> bb12;
61+
}
62+
63+
bb11: {
64+
_0 = const 128_u8;
65+
goto -> bb12;
66+
}
67+
68+
bb12: {
69+
return;
70+
}
71+
}
72+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
- // MIR for `match_trunc_u16_i8` before MatchBranchSimplification
2+
+ // MIR for `match_trunc_u16_i8` after MatchBranchSimplification
3+
4+
fn match_trunc_u16_i8(_1: EnumAu16) -> i8 {
5+
debug i => _1;
6+
let mut _0: i8;
7+
let mut _2: u16;
8+
+ let mut _3: u16;
9+
10+
bb0: {
11+
_2 = discriminant(_1);
12+
- switchInt(move _2) -> [0: bb9, 127: bb8, 128: bb7, 255: bb6, 65280: bb5, 65407: bb4, 65408: bb3, 65535: bb2, otherwise: bb1];
13+
- }
14+
-
15+
- bb1: {
16+
- unreachable;
17+
- }
18+
-
19+
- bb2: {
20+
- _0 = const -1_i8;
21+
- goto -> bb10;
22+
- }
23+
-
24+
- bb3: {
25+
- _0 = const i8::MIN;
26+
- goto -> bb10;
27+
- }
28+
-
29+
- bb4: {
30+
- _0 = const i8::MAX;
31+
- goto -> bb10;
32+
- }
33+
-
34+
- bb5: {
35+
- _0 = const 0_i8;
36+
- goto -> bb10;
37+
- }
38+
-
39+
- bb6: {
40+
- _0 = const -1_i8;
41+
- goto -> bb10;
42+
- }
43+
-
44+
- bb7: {
45+
- _0 = const i8::MIN;
46+
- goto -> bb10;
47+
- }
48+
-
49+
- bb8: {
50+
- _0 = const i8::MAX;
51+
- goto -> bb10;
52+
- }
53+
-
54+
- bb9: {
55+
- _0 = const 0_i8;
56+
- goto -> bb10;
57+
- }
58+
-
59+
- bb10: {
60+
+ StorageLive(_3);
61+
+ _3 = move _2;
62+
+ _0 = _3 as i8 (IntToInt);
63+
+ StorageDead(_3);
64+
return;
65+
}
66+
}
67+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
- // MIR for `match_trunc_u16_i8_failed` before MatchBranchSimplification
2+
+ // MIR for `match_trunc_u16_i8_failed` after MatchBranchSimplification
3+
4+
fn match_trunc_u16_i8_failed(_1: EnumAu16) -> i8 {
5+
debug i => _1;
6+
let mut _0: i8;
7+
let mut _2: u16;
8+
9+
bb0: {
10+
_2 = discriminant(_1);
11+
switchInt(move _2) -> [0: bb9, 127: bb8, 128: bb7, 255: bb6, 65280: bb5, 65407: bb4, 65408: bb3, 65535: bb2, otherwise: bb1];
12+
}
13+
14+
bb1: {
15+
unreachable;
16+
}
17+
18+
bb2: {
19+
_0 = const 1_i8;
20+
goto -> bb10;
21+
}
22+
23+
bb3: {
24+
_0 = const i8::MIN;
25+
goto -> bb10;
26+
}
27+
28+
bb4: {
29+
_0 = const i8::MAX;
30+
goto -> bb10;
31+
}
32+
33+
bb5: {
34+
_0 = const 0_i8;
35+
goto -> bb10;
36+
}
37+
38+
bb6: {
39+
_0 = const -1_i8;
40+
goto -> bb10;
41+
}
42+
43+
bb7: {
44+
_0 = const i8::MIN;
45+
goto -> bb10;
46+
}
47+
48+
bb8: {
49+
_0 = const i8::MAX;
50+
goto -> bb10;
51+
}
52+
53+
bb9: {
54+
_0 = const 0_i8;
55+
goto -> bb10;
56+
}
57+
58+
bb10: {
59+
return;
60+
}
61+
}
62+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
- // MIR for `match_trunc_u16_u8` before MatchBranchSimplification
2+
+ // MIR for `match_trunc_u16_u8` after MatchBranchSimplification
3+
4+
fn match_trunc_u16_u8(_1: EnumAu16) -> u8 {
5+
debug i => _1;
6+
let mut _0: u8;
7+
let mut _2: u16;
8+
+ let mut _3: u16;
9+
10+
bb0: {
11+
_2 = discriminant(_1);
12+
- switchInt(move _2) -> [0: bb9, 127: bb8, 128: bb7, 255: bb6, 65280: bb5, 65407: bb4, 65408: bb3, 65535: bb2, otherwise: bb1];
13+
- }
14+
-
15+
- bb1: {
16+
- unreachable;
17+
- }
18+
-
19+
- bb2: {
20+
- _0 = const u8::MAX;
21+
- goto -> bb10;
22+
- }
23+
-
24+
- bb3: {
25+
- _0 = const 128_u8;
26+
- goto -> bb10;
27+
- }
28+
-
29+
- bb4: {
30+
- _0 = const 127_u8;
31+
- goto -> bb10;
32+
- }
33+
-
34+
- bb5: {
35+
- _0 = const 0_u8;
36+
- goto -> bb10;
37+
- }
38+
-
39+
- bb6: {
40+
- _0 = const u8::MAX;
41+
- goto -> bb10;
42+
- }
43+
-
44+
- bb7: {
45+
- _0 = const 128_u8;
46+
- goto -> bb10;
47+
- }
48+
-
49+
- bb8: {
50+
- _0 = const 127_u8;
51+
- goto -> bb10;
52+
- }
53+
-
54+
- bb9: {
55+
- _0 = const 0_u8;
56+
- goto -> bb10;
57+
- }
58+
-
59+
- bb10: {
60+
+ StorageLive(_3);
61+
+ _3 = move _2;
62+
+ _0 = _3 as u8 (IntToInt);
63+
+ StorageDead(_3);
64+
return;
65+
}
66+
}
67+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
- // MIR for `match_trunc_u16_u8_failed` before MatchBranchSimplification
2+
+ // MIR for `match_trunc_u16_u8_failed` after MatchBranchSimplification
3+
4+
fn match_trunc_u16_u8_failed(_1: EnumAu16) -> u8 {
5+
debug i => _1;
6+
let mut _0: u8;
7+
let mut _2: u16;
8+
9+
bb0: {
10+
_2 = discriminant(_1);
11+
switchInt(move _2) -> [0: bb9, 127: bb8, 128: bb7, 255: bb6, 65280: bb5, 65407: bb4, 65408: bb3, 65535: bb2, otherwise: bb1];
12+
}
13+
14+
bb1: {
15+
unreachable;
16+
}
17+
18+
bb2: {
19+
_0 = const 127_u8;
20+
goto -> bb10;
21+
}
22+
23+
bb3: {
24+
_0 = const 128_u8;
25+
goto -> bb10;
26+
}
27+
28+
bb4: {
29+
_0 = const 127_u8;
30+
goto -> bb10;
31+
}
32+
33+
bb5: {
34+
_0 = const 0_u8;
35+
goto -> bb10;
36+
}
37+
38+
bb6: {
39+
_0 = const u8::MAX;
40+
goto -> bb10;
41+
}
42+
43+
bb7: {
44+
_0 = const 128_u8;
45+
goto -> bb10;
46+
}
47+
48+
bb8: {
49+
_0 = const 127_u8;
50+
goto -> bb10;
51+
}
52+
53+
bb9: {
54+
_0 = const 0_u8;
55+
goto -> bb10;
56+
}
57+
58+
bb10: {
59+
return;
60+
}
61+
}
62+

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

Lines changed: 0 additions & 32 deletions
This file was deleted.

‎tests/mir-opt/matches_reduce_branches.match_u8_i16_2.MatchBranchSimplification.diff

Lines changed: 0 additions & 26 deletions
This file was deleted.

‎tests/mir-opt/matches_reduce_branches.match_u8_i16_failed.MatchBranchSimplification.diff

Lines changed: 0 additions & 32 deletions
This file was deleted.

‎tests/mir-opt/matches_reduce_branches.match_u8_i16_fallback.MatchBranchSimplification.diff

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
- // MIR for `match_u8_i8` before MatchBranchSimplification
2+
+ // MIR for `match_u8_i8` after MatchBranchSimplification
3+
4+
fn match_u8_i8(_1: EnumAu8) -> i8 {
5+
debug i => _1;
6+
let mut _0: i8;
7+
let mut _2: u8;
8+
+ let mut _3: u8;
9+
10+
bb0: {
11+
_2 = discriminant(_1);
12+
- switchInt(move _2) -> [0: bb5, 127: bb4, 128: bb3, 255: bb2, otherwise: bb1];
13+
- }
14+
-
15+
- bb1: {
16+
- unreachable;
17+
- }
18+
-
19+
- bb2: {
20+
- _0 = const -1_i8;
21+
- goto -> bb6;
22+
- }
23+
-
24+
- bb3: {
25+
- _0 = const i8::MIN;
26+
- goto -> bb6;
27+
- }
28+
-
29+
- bb4: {
30+
- _0 = const i8::MAX;
31+
- goto -> bb6;
32+
- }
33+
-
34+
- bb5: {
35+
- _0 = const 0_i8;
36+
- goto -> bb6;
37+
- }
38+
-
39+
- bb6: {
40+
+ StorageLive(_3);
41+
+ _3 = move _2;
42+
+ _0 = _3 as i8 (IntToInt);
43+
+ StorageDead(_3);
44+
return;
45+
}
46+
}
47+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
- // MIR for `match_u8_i8_2` before MatchBranchSimplification
2+
+ // MIR for `match_u8_i8_2` after MatchBranchSimplification
3+
4+
fn match_u8_i8_2(_1: EnumAu8) -> (i8, i8) {
5+
debug i => _1;
6+
let mut _0: (i8, i8);
7+
let _2: i8;
8+
let _4: ();
9+
let mut _5: u8;
10+
let mut _6: i8;
11+
let mut _7: i8;
12+
+ let mut _8: u8;
13+
scope 1 {
14+
debug a => _2;
15+
let _3: i8;
16+
scope 2 {
17+
debug b => _3;
18+
}
19+
}
20+
21+
bb0: {
22+
StorageLive(_2);
23+
StorageLive(_3);
24+
StorageLive(_4);
25+
_5 = discriminant(_1);
26+
- switchInt(move _5) -> [0: bb5, 127: bb4, 128: bb3, 255: bb2, otherwise: bb1];
27+
- }
28+
-
29+
- bb1: {
30+
- unreachable;
31+
- }
32+
-
33+
- bb2: {
34+
- _2 = const -1_i8;
35+
- _3 = const -1_i8;
36+
+ StorageLive(_8);
37+
+ _8 = move _5;
38+
+ _2 = _8 as i8 (IntToInt);
39+
+ _3 = _8 as i8 (IntToInt);
40+
_4 = ();
41+
- goto -> bb6;
42+
- }
43+
-
44+
- bb3: {
45+
- _2 = const i8::MIN;
46+
- _3 = const i8::MIN;
47+
- _4 = ();
48+
- goto -> bb6;
49+
- }
50+
-
51+
- bb4: {
52+
- _2 = const i8::MAX;
53+
- _3 = const i8::MAX;
54+
- _4 = ();
55+
- goto -> bb6;
56+
- }
57+
-
58+
- bb5: {
59+
- _2 = const 0_i8;
60+
- _3 = const 0_i8;
61+
- _4 = ();
62+
- goto -> bb6;
63+
- }
64+
-
65+
- bb6: {
66+
+ StorageDead(_8);
67+
StorageDead(_4);
68+
StorageLive(_6);
69+
_6 = _2;
70+
StorageLive(_7);
71+
_7 = _3;
72+
_0 = (move _6, move _7);
73+
StorageDead(_7);
74+
StorageDead(_6);
75+
StorageDead(_3);
76+
StorageDead(_2);
77+
return;
78+
}
79+
}
80+
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
- // MIR for `match_u8_i8_2_failed` before MatchBranchSimplification
2+
+ // MIR for `match_u8_i8_2_failed` after MatchBranchSimplification
3+
4+
fn match_u8_i8_2_failed(_1: EnumAu8) -> (i8, i8) {
5+
debug i => _1;
6+
let mut _0: (i8, i8);
7+
let _2: i8;
8+
let _4: ();
9+
let mut _5: u8;
10+
let mut _6: i8;
11+
let mut _7: i8;
12+
scope 1 {
13+
debug a => _2;
14+
let _3: i8;
15+
scope 2 {
16+
debug b => _3;
17+
}
18+
}
19+
20+
bb0: {
21+
StorageLive(_2);
22+
StorageLive(_3);
23+
StorageLive(_4);
24+
_5 = discriminant(_1);
25+
switchInt(move _5) -> [0: bb5, 127: bb4, 128: bb3, 255: bb2, otherwise: bb1];
26+
}
27+
28+
bb1: {
29+
unreachable;
30+
}
31+
32+
bb2: {
33+
_2 = const -1_i8;
34+
_3 = const 1_i8;
35+
_4 = ();
36+
goto -> bb6;
37+
}
38+
39+
bb3: {
40+
_2 = const i8::MIN;
41+
_3 = const i8::MIN;
42+
_4 = ();
43+
goto -> bb6;
44+
}
45+
46+
bb4: {
47+
_2 = const i8::MAX;
48+
_3 = const i8::MAX;
49+
_4 = ();
50+
goto -> bb6;
51+
}
52+
53+
bb5: {
54+
_2 = const 0_i8;
55+
_3 = const 0_i8;
56+
_4 = ();
57+
goto -> bb6;
58+
}
59+
60+
bb6: {
61+
StorageDead(_4);
62+
StorageLive(_6);
63+
_6 = _2;
64+
StorageLive(_7);
65+
_7 = _3;
66+
_0 = (move _6, move _7);
67+
StorageDead(_7);
68+
StorageDead(_6);
69+
StorageDead(_3);
70+
StorageDead(_2);
71+
return;
72+
}
73+
}
74+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
- // MIR for `match_u8_i8_failed` before MatchBranchSimplification
2+
+ // MIR for `match_u8_i8_failed` after MatchBranchSimplification
3+
4+
fn match_u8_i8_failed(_1: EnumAu8) -> i8 {
5+
debug i => _1;
6+
let mut _0: i8;
7+
let mut _2: u8;
8+
9+
bb0: {
10+
_2 = discriminant(_1);
11+
switchInt(move _2) -> [0: bb5, 127: bb4, 128: bb3, 255: bb2, otherwise: bb1];
12+
}
13+
14+
bb1: {
15+
unreachable;
16+
}
17+
18+
bb2: {
19+
_0 = const 1_i8;
20+
goto -> bb6;
21+
}
22+
23+
bb3: {
24+
_0 = const i8::MIN;
25+
goto -> bb6;
26+
}
27+
28+
bb4: {
29+
_0 = const i8::MAX;
30+
goto -> bb6;
31+
}
32+
33+
bb5: {
34+
_0 = const 0_i8;
35+
goto -> bb6;
36+
}
37+
38+
bb6: {
39+
return;
40+
}
41+
}
42+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
- // MIR for `match_u8_i8_failed_len_1` before MatchBranchSimplification
2+
+ // MIR for `match_u8_i8_failed_len_1` after MatchBranchSimplification
3+
4+
fn match_u8_i8_failed_len_1(_1: EnumAu8) -> i8 {
5+
let mut _0: i8;
6+
let mut _2: u8;
7+
8+
bb0: {
9+
_2 = discriminant(_1);
10+
switchInt(_2) -> [0: bb1, 127: bb2, 128: bb3, 255: bb4, otherwise: bb5];
11+
}
12+
13+
bb1: {
14+
_0 = const 0_i8;
15+
goto -> bb6;
16+
}
17+
18+
bb2: {
19+
_0 = const i8::MAX;
20+
_0 = const i8::MAX;
21+
goto -> bb6;
22+
}
23+
24+
bb3: {
25+
_0 = const i8::MIN;
26+
goto -> bb6;
27+
}
28+
29+
bb4: {
30+
_0 = const -1_i8;
31+
goto -> bb6;
32+
}
33+
34+
bb5: {
35+
unreachable;
36+
}
37+
38+
bb6: {
39+
return;
40+
}
41+
}
42+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
- // MIR for `match_u8_i8_failed_len_2` before MatchBranchSimplification
2+
+ // MIR for `match_u8_i8_failed_len_2` after MatchBranchSimplification
3+
4+
fn match_u8_i8_failed_len_2(_1: EnumAu8) -> i8 {
5+
let mut _0: i8;
6+
let mut _2: u8;
7+
8+
bb0: {
9+
_2 = discriminant(_1);
10+
switchInt(_2) -> [0: bb1, 127: bb2, 128: bb3, 255: bb4, otherwise: bb5];
11+
}
12+
13+
bb1: {
14+
_0 = const 0_i8;
15+
goto -> bb6;
16+
}
17+
18+
bb2: {
19+
_0 = const i8::MAX;
20+
goto -> bb6;
21+
}
22+
23+
bb3: {
24+
_0 = const i8::MIN;
25+
goto -> bb6;
26+
}
27+
28+
bb4: {
29+
_0 = const -1_i8;
30+
_0 = const -1_i8;
31+
goto -> bb6;
32+
}
33+
34+
bb5: {
35+
unreachable;
36+
}
37+
38+
bb6: {
39+
return;
40+
}
41+
}
42+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
- // MIR for `match_u8_i8_fallback` before MatchBranchSimplification
2+
+ // MIR for `match_u8_i8_fallback` after MatchBranchSimplification
3+
4+
fn match_u8_i8_fallback(_1: EnumAu8) -> i8 {
5+
debug i => _1;
6+
let mut _0: i8;
7+
let mut _2: u8;
8+
9+
bb0: {
10+
_2 = discriminant(_1);
11+
switchInt(move _2) -> [0: bb4, 127: bb3, 128: bb2, otherwise: bb1];
12+
}
13+
14+
bb1: {
15+
_0 = const -1_i8;
16+
goto -> bb5;
17+
}
18+
19+
bb2: {
20+
_0 = const i8::MIN;
21+
goto -> bb5;
22+
}
23+
24+
bb3: {
25+
_0 = const i8::MAX;
26+
goto -> bb5;
27+
}
28+
29+
bb4: {
30+
_0 = const 0_i8;
31+
goto -> bb5;
32+
}
33+
34+
bb5: {
35+
return;
36+
}
37+
}
38+

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

Lines changed: 0 additions & 37 deletions
This file was deleted.

‎tests/mir-opt/matches_reduce_branches.match_u8_u16_2.MatchBranchSimplification.diff

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
- // MIR for `match_zext_u8_i16` before MatchBranchSimplification
2+
+ // MIR for `match_zext_u8_i16` after MatchBranchSimplification
3+
4+
fn match_zext_u8_i16(_1: EnumAu8) -> i16 {
5+
debug i => _1;
6+
let mut _0: i16;
7+
let mut _2: u8;
8+
+ let mut _3: u8;
9+
10+
bb0: {
11+
_2 = discriminant(_1);
12+
- switchInt(move _2) -> [0: bb5, 127: bb4, 128: bb3, 255: bb2, otherwise: bb1];
13+
- }
14+
-
15+
- bb1: {
16+
- unreachable;
17+
- }
18+
-
19+
- bb2: {
20+
- _0 = const 255_i16;
21+
- goto -> bb6;
22+
- }
23+
-
24+
- bb3: {
25+
- _0 = const 128_i16;
26+
- goto -> bb6;
27+
- }
28+
-
29+
- bb4: {
30+
- _0 = const 127_i16;
31+
- goto -> bb6;
32+
- }
33+
-
34+
- bb5: {
35+
- _0 = const 0_i16;
36+
- goto -> bb6;
37+
- }
38+
-
39+
- bb6: {
40+
+ StorageLive(_3);
41+
+ _3 = move _2;
42+
+ _0 = _3 as i16 (IntToInt);
43+
+ StorageDead(_3);
44+
return;
45+
}
46+
}
47+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
- // MIR for `match_zext_u8_i16_failed` before MatchBranchSimplification
2+
+ // MIR for `match_zext_u8_i16_failed` after MatchBranchSimplification
3+
4+
fn match_zext_u8_i16_failed(_1: EnumAu8) -> i16 {
5+
debug i => _1;
6+
let mut _0: i16;
7+
let mut _2: u8;
8+
9+
bb0: {
10+
_2 = discriminant(_1);
11+
switchInt(move _2) -> [0: bb5, 127: bb4, 128: bb3, 255: bb2, otherwise: bb1];
12+
}
13+
14+
bb1: {
15+
unreachable;
16+
}
17+
18+
bb2: {
19+
_0 = const 255_i16;
20+
goto -> bb6;
21+
}
22+
23+
bb3: {
24+
_0 = const 128_i16;
25+
goto -> bb6;
26+
}
27+
28+
bb4: {
29+
_0 = const -127_i16;
30+
goto -> bb6;
31+
}
32+
33+
bb5: {
34+
_0 = const 0_i16;
35+
goto -> bb6;
36+
}
37+
38+
bb6: {
39+
return;
40+
}
41+
}
42+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
- // MIR for `match_zext_u8_u16` before MatchBranchSimplification
2+
+ // MIR for `match_zext_u8_u16` after MatchBranchSimplification
3+
4+
fn match_zext_u8_u16(_1: EnumAu8) -> u16 {
5+
debug i => _1;
6+
let mut _0: u16;
7+
let mut _2: u8;
8+
+ let mut _3: u8;
9+
10+
bb0: {
11+
_2 = discriminant(_1);
12+
- switchInt(move _2) -> [0: bb5, 127: bb4, 128: bb3, 255: bb2, otherwise: bb1];
13+
- }
14+
-
15+
- bb1: {
16+
- unreachable;
17+
- }
18+
-
19+
- bb2: {
20+
- _0 = const 255_u16;
21+
- goto -> bb6;
22+
- }
23+
-
24+
- bb3: {
25+
- _0 = const 128_u16;
26+
- goto -> bb6;
27+
- }
28+
-
29+
- bb4: {
30+
- _0 = const 127_u16;
31+
- goto -> bb6;
32+
- }
33+
-
34+
- bb5: {
35+
- _0 = const 0_u16;
36+
- goto -> bb6;
37+
- }
38+
-
39+
- bb6: {
40+
+ StorageLive(_3);
41+
+ _3 = move _2;
42+
+ _0 = _3 as u16 (IntToInt);
43+
+ StorageDead(_3);
44+
return;
45+
}
46+
}
47+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
- // MIR for `match_zext_u8_u16_failed` before MatchBranchSimplification
2+
+ // MIR for `match_zext_u8_u16_failed` after MatchBranchSimplification
3+
4+
fn match_zext_u8_u16_failed(_1: EnumAu8) -> u16 {
5+
debug i => _1;
6+
let mut _0: u16;
7+
let mut _2: u8;
8+
9+
bb0: {
10+
_2 = discriminant(_1);
11+
switchInt(move _2) -> [0: bb5, 127: bb4, 128: bb3, 255: bb2, otherwise: bb1];
12+
}
13+
14+
bb1: {
15+
unreachable;
16+
}
17+
18+
bb2: {
19+
_0 = const 255_u16;
20+
goto -> bb6;
21+
}
22+
23+
bb3: {
24+
_0 = const 128_u16;
25+
goto -> bb6;
26+
}
27+
28+
bb4: {
29+
_0 = const 65407_u16;
30+
goto -> bb6;
31+
}
32+
33+
bb5: {
34+
_0 = const 0_u16;
35+
goto -> bb6;
36+
}
37+
38+
bb6: {
39+
return;
40+
}
41+
}
42+

‎tests/mir-opt/matches_reduce_branches.rs

Lines changed: 479 additions & 100 deletions
Large diffs are not rendered by default.

‎tests/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.diff

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,32 @@
55
debug e => _1;
66
let mut _0: u8;
77
let mut _2: isize;
8+
+ let mut _3: isize;
89

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

‎tests/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.diff

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,32 @@
55
debug e => _1;
66
let mut _0: i8;
77
let mut _2: isize;
8+
+ let mut _3: isize;
89

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

‎tests/mir-opt/matches_u8.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// skip-filecheck
22
//@ test-mir-pass: MatchBranchSimplification
3+
//@ compile-flags: -Zunsound-mir-opts
34

45
// EMIT_MIR matches_u8.exhaustive_match.MatchBranchSimplification.diff
56
// EMIT_MIR matches_u8.exhaustive_match_i8.MatchBranchSimplification.diff

0 commit comments

Comments
 (0)