Skip to content

Commit 72ff82c

Browse files
committed
Add tests.
1 parent 758b89f commit 72ff82c

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed

tests/mir-opt/jump_threading.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,32 @@ fn identity(x: Result<i32, i32>) -> Result<i32, i32> {
7777
Ok(x?)
7878
}
7979

80+
fn two_reads() -> i32 {
81+
// CHECK-LABEL: fn two_reads(
82+
// CHECK: debug a => [[a:_.*]];
83+
// CHECK: debug b => [[b:_.*]];
84+
// CHECK: debug c => [[c:_.*]];
85+
// CHECK: bb0: {
86+
// CHECK: [[a]] = const 2_i32;
87+
// CHECK: [[b]] = copy [[a]];
88+
// CHECK: [[c]] = copy [[a]];
89+
// CHECK: [[tmp:_.*]] = copy [[c]];
90+
// CHECK: [[eq:_.*]] = Eq(move [[tmp]], const 2_i32);
91+
// CHECK: switchInt(move [[eq]]) -> [0: bb2, otherwise: bb1];
92+
// CHECK: bb1: {
93+
// CHECK: _0 = const 0_i32;
94+
// CHECK: goto -> bb3;
95+
// CHECK: bb2: {
96+
// CHECK: _0 = const 1_i32;
97+
// CHECK: goto -> bb3;
98+
// CHECK: bb3: {
99+
// CHECK: return;
100+
let a = 2;
101+
let b = a;
102+
let c = a;
103+
if c == 2 { 0 } else { 1 }
104+
}
105+
80106
enum DFA {
81107
A,
82108
B,
@@ -599,6 +625,7 @@ fn main() {
599625

600626
// EMIT_MIR jump_threading.too_complex.JumpThreading.diff
601627
// EMIT_MIR jump_threading.identity.JumpThreading.diff
628+
// EMIT_MIR jump_threading.two_reads.JumpThreading.diff
602629
// EMIT_MIR jump_threading.custom_discr.JumpThreading.diff
603630
// EMIT_MIR jump_threading.dfa.JumpThreading.diff
604631
// EMIT_MIR jump_threading.multiple_match.JumpThreading.diff
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
- // MIR for `two_reads` before JumpThreading
2+
+ // MIR for `two_reads` after JumpThreading
3+
4+
fn two_reads() -> i32 {
5+
let mut _0: i32;
6+
let _1: i32;
7+
let mut _4: bool;
8+
let mut _5: i32;
9+
scope 1 {
10+
debug a => _1;
11+
let _2: i32;
12+
scope 2 {
13+
debug b => _2;
14+
let _3: i32;
15+
scope 3 {
16+
debug c => _3;
17+
}
18+
}
19+
}
20+
21+
bb0: {
22+
StorageLive(_1);
23+
_1 = const 2_i32;
24+
StorageLive(_2);
25+
_2 = copy _1;
26+
StorageLive(_3);
27+
_3 = copy _1;
28+
StorageLive(_4);
29+
StorageLive(_5);
30+
_5 = copy _3;
31+
_4 = Eq(move _5, const 2_i32);
32+
switchInt(move _4) -> [0: bb2, otherwise: bb1];
33+
}
34+
35+
bb1: {
36+
StorageDead(_5);
37+
_0 = const 0_i32;
38+
goto -> bb3;
39+
}
40+
41+
bb2: {
42+
StorageDead(_5);
43+
_0 = const 1_i32;
44+
goto -> bb3;
45+
}
46+
47+
bb3: {
48+
StorageDead(_4);
49+
StorageDead(_3);
50+
StorageDead(_2);
51+
StorageDead(_1);
52+
return;
53+
}
54+
}
55+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
- // MIR for `two_reads` before JumpThreading
2+
+ // MIR for `two_reads` after JumpThreading
3+
4+
fn two_reads() -> i32 {
5+
let mut _0: i32;
6+
let _1: i32;
7+
let mut _4: bool;
8+
let mut _5: i32;
9+
scope 1 {
10+
debug a => _1;
11+
let _2: i32;
12+
scope 2 {
13+
debug b => _2;
14+
let _3: i32;
15+
scope 3 {
16+
debug c => _3;
17+
}
18+
}
19+
}
20+
21+
bb0: {
22+
StorageLive(_1);
23+
_1 = const 2_i32;
24+
StorageLive(_2);
25+
_2 = copy _1;
26+
StorageLive(_3);
27+
_3 = copy _1;
28+
StorageLive(_4);
29+
StorageLive(_5);
30+
_5 = copy _3;
31+
_4 = Eq(move _5, const 2_i32);
32+
switchInt(move _4) -> [0: bb2, otherwise: bb1];
33+
}
34+
35+
bb1: {
36+
StorageDead(_5);
37+
_0 = const 0_i32;
38+
goto -> bb3;
39+
}
40+
41+
bb2: {
42+
StorageDead(_5);
43+
_0 = const 1_i32;
44+
goto -> bb3;
45+
}
46+
47+
bb3: {
48+
StorageDead(_4);
49+
StorageDead(_3);
50+
StorageDead(_2);
51+
StorageDead(_1);
52+
return;
53+
}
54+
}
55+

0 commit comments

Comments
 (0)