Skip to content

Commit 81f8c12

Browse files
committed
Add tests for dead_store_elimination MIR opt.
The `coverage` test checks that all the desired optimizations are performed, while the remaining tests check that a variety of other cases are not optimized. Unfortunately, const prop makes the MIR slightly less clear than it could be, but all the intended checks are still intact.
1 parent 1a01292 commit 81f8c12

5 files changed

+621
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
- // MIR for `coverage` before SimpleLocalDse
2+
+ // MIR for `coverage` after SimpleLocalDse
3+
4+
fn coverage() -> () {
5+
let mut _0: (); // return place in scope 0 at $DIR/dead_store_elimination.rs:6:19: 6:19
6+
let mut _1: i32; // in scope 0 at $DIR/dead_store_elimination.rs:7:9: 7:14
7+
let _2: (); // in scope 0 at $DIR/dead_store_elimination.rs:10:5: 10:12
8+
let mut _3: i32; // in scope 0 at $DIR/dead_store_elimination.rs:10:10: 10:11
9+
let mut _6: i32; // in scope 0 at $DIR/dead_store_elimination.rs:13:22: 13:24
10+
let mut _7: i32; // in scope 0 at $DIR/dead_store_elimination.rs:14:9: 14:11
11+
let _8: (); // in scope 0 at $DIR/dead_store_elimination.rs:16:5: 16:12
12+
let mut _9: i32; // in scope 0 at $DIR/dead_store_elimination.rs:16:10: 16:11
13+
let _11: (); // in scope 0 at $DIR/dead_store_elimination.rs:23:5: 23:12
14+
let mut _12: coverage::S; // in scope 0 at $DIR/dead_store_elimination.rs:23:10: 23:11
15+
let mut _14: coverage::S; // in scope 0 at $DIR/dead_store_elimination.rs:27:9: 27:14
16+
let _15: (); // in scope 0 at $DIR/dead_store_elimination.rs:28:5: 28:12
17+
let mut _16: coverage::S; // in scope 0 at $DIR/dead_store_elimination.rs:28:10: 28:11
18+
scope 1 {
19+
debug x => _1; // in scope 1 at $DIR/dead_store_elimination.rs:7:9: 7:14
20+
let mut _4: i32; // in scope 1 at $DIR/dead_store_elimination.rs:12:9: 12:14
21+
scope 2 {
22+
debug x => _4; // in scope 2 at $DIR/dead_store_elimination.rs:12:9: 12:14
23+
let mut _5: &mut i32; // in scope 2 at $DIR/dead_store_elimination.rs:13:9: 13:14
24+
scope 3 {
25+
debug r => _5; // in scope 3 at $DIR/dead_store_elimination.rs:13:9: 13:14
26+
let mut _10: coverage::S; // in scope 3 at $DIR/dead_store_elimination.rs:20:9: 20:14
27+
scope 4 {
28+
debug s => _10; // in scope 4 at $DIR/dead_store_elimination.rs:20:9: 20:14
29+
let mut _13: coverage::S; // in scope 4 at $DIR/dead_store_elimination.rs:25:9: 25:14
30+
scope 5 {
31+
debug s => _13; // in scope 5 at $DIR/dead_store_elimination.rs:25:9: 25:14
32+
let mut _17: i32; // in scope 5 at $DIR/dead_store_elimination.rs:30:9: 30:14
33+
scope 6 {
34+
debug x => _17; // in scope 6 at $DIR/dead_store_elimination.rs:30:9: 30:14
35+
}
36+
}
37+
}
38+
}
39+
}
40+
}
41+
42+
bb0: {
43+
StorageLive(_1); // scope 0 at $DIR/dead_store_elimination.rs:7:9: 7:14
44+
- _1 = const 0_i32; // scope 0 at $DIR/dead_store_elimination.rs:7:17: 7:18
45+
- _1 = const 1_i32; // scope 1 at $DIR/dead_store_elimination.rs:8:5: 8:10
46+
+ nop; // scope 0 at $DIR/dead_store_elimination.rs:7:17: 7:18
47+
+ nop; // scope 1 at $DIR/dead_store_elimination.rs:8:5: 8:10
48+
_1 = const 2_i32; // scope 1 at $DIR/dead_store_elimination.rs:9:5: 9:10
49+
StorageLive(_2); // scope 1 at $DIR/dead_store_elimination.rs:10:5: 10:12
50+
StorageLive(_3); // scope 1 at $DIR/dead_store_elimination.rs:10:10: 10:11
51+
_3 = const 2_i32; // scope 1 at $DIR/dead_store_elimination.rs:10:10: 10:11
52+
_2 = read::<i32>(const 2_i32) -> bb1; // scope 1 at $DIR/dead_store_elimination.rs:10:5: 10:12
53+
// mir::Constant
54+
// + span: $DIR/dead_store_elimination.rs:10:5: 10:9
55+
// + literal: Const { ty: fn(i32) {read::<i32>}, val: Value(Scalar(<ZST>)) }
56+
}
57+
58+
bb1: {
59+
StorageDead(_3); // scope 1 at $DIR/dead_store_elimination.rs:10:11: 10:12
60+
StorageDead(_2); // scope 1 at $DIR/dead_store_elimination.rs:10:12: 10:13
61+
StorageLive(_4); // scope 1 at $DIR/dead_store_elimination.rs:12:9: 12:14
62+
- _4 = const 10_i32; // scope 1 at $DIR/dead_store_elimination.rs:12:17: 12:19
63+
+ nop; // scope 1 at $DIR/dead_store_elimination.rs:12:17: 12:19
64+
StorageLive(_5); // scope 2 at $DIR/dead_store_elimination.rs:13:9: 13:14
65+
StorageLive(_6); // scope 2 at $DIR/dead_store_elimination.rs:13:22: 13:24
66+
_6 = const 11_i32; // scope 2 at $DIR/dead_store_elimination.rs:13:22: 13:24
67+
_5 = &mut _6; // scope 2 at $DIR/dead_store_elimination.rs:13:17: 13:24
68+
StorageLive(_7); // scope 3 at $DIR/dead_store_elimination.rs:14:9: 14:11
69+
- _7 = (*_5); // scope 3 at $DIR/dead_store_elimination.rs:14:9: 14:11
70+
- _4 = move _7; // scope 3 at $DIR/dead_store_elimination.rs:14:5: 14:11
71+
+ nop; // scope 3 at $DIR/dead_store_elimination.rs:14:9: 14:11
72+
+ nop; // scope 3 at $DIR/dead_store_elimination.rs:14:5: 14:11
73+
StorageDead(_7); // scope 3 at $DIR/dead_store_elimination.rs:14:10: 14:11
74+
_4 = const 12_i32; // scope 3 at $DIR/dead_store_elimination.rs:15:5: 15:11
75+
StorageLive(_8); // scope 3 at $DIR/dead_store_elimination.rs:16:5: 16:12
76+
StorageLive(_9); // scope 3 at $DIR/dead_store_elimination.rs:16:10: 16:11
77+
_9 = const 12_i32; // scope 3 at $DIR/dead_store_elimination.rs:16:10: 16:11
78+
_8 = read::<i32>(const 12_i32) -> bb2; // scope 3 at $DIR/dead_store_elimination.rs:16:5: 16:12
79+
// mir::Constant
80+
// + span: $DIR/dead_store_elimination.rs:16:5: 16:9
81+
// + literal: Const { ty: fn(i32) {read::<i32>}, val: Value(Scalar(<ZST>)) }
82+
}
83+
84+
bb2: {
85+
StorageDead(_9); // scope 3 at $DIR/dead_store_elimination.rs:16:11: 16:12
86+
StorageDead(_8); // scope 3 at $DIR/dead_store_elimination.rs:16:12: 16:13
87+
StorageLive(_10); // scope 3 at $DIR/dead_store_elimination.rs:20:9: 20:14
88+
- (_10.0: u32) = const 20_u32; // scope 3 at $DIR/dead_store_elimination.rs:20:17: 20:22
89+
- (_10.0: u32) = const 21_u32; // scope 4 at $DIR/dead_store_elimination.rs:21:5: 21:13
90+
+ nop; // scope 3 at $DIR/dead_store_elimination.rs:20:17: 20:22
91+
+ nop; // scope 4 at $DIR/dead_store_elimination.rs:21:5: 21:13
92+
(_10.0: u32) = const 22_u32; // scope 4 at $DIR/dead_store_elimination.rs:22:5: 22:13
93+
StorageLive(_11); // scope 4 at $DIR/dead_store_elimination.rs:23:5: 23:12
94+
StorageLive(_12); // scope 4 at $DIR/dead_store_elimination.rs:23:10: 23:11
95+
_12 = const S(22_u32); // scope 4 at $DIR/dead_store_elimination.rs:23:10: 23:11
96+
// ty::Const
97+
// + ty: coverage::S
98+
// + val: Value(Scalar(0x00000016))
99+
// mir::Constant
100+
// + span: $DIR/dead_store_elimination.rs:23:10: 23:11
101+
// + literal: Const { ty: coverage::S, val: Value(Scalar(0x00000016)) }
102+
_11 = read::<S>(const S(22_u32)) -> bb3; // scope 4 at $DIR/dead_store_elimination.rs:23:5: 23:12
103+
// mir::Constant
104+
// + span: $DIR/dead_store_elimination.rs:23:5: 23:9
105+
// + literal: Const { ty: fn(coverage::S) {read::<coverage::S>}, val: Value(Scalar(<ZST>)) }
106+
// ty::Const
107+
// + ty: coverage::S
108+
// + val: Value(Scalar(0x00000016))
109+
// mir::Constant
110+
// + span: $DIR/dead_store_elimination.rs:23:5: 23:12
111+
// + literal: Const { ty: coverage::S, val: Value(Scalar(0x00000016)) }
112+
}
113+
114+
bb3: {
115+
StorageDead(_12); // scope 4 at $DIR/dead_store_elimination.rs:23:11: 23:12
116+
StorageDead(_11); // scope 4 at $DIR/dead_store_elimination.rs:23:12: 23:13
117+
StorageLive(_13); // scope 4 at $DIR/dead_store_elimination.rs:25:9: 25:14
118+
- (_13.0: u32) = const 30_u32; // scope 4 at $DIR/dead_store_elimination.rs:25:17: 25:22
119+
- (_13.0: u32) = const 31_u32; // scope 5 at $DIR/dead_store_elimination.rs:26:5: 26:13
120+
+ nop; // scope 4 at $DIR/dead_store_elimination.rs:25:17: 25:22
121+
+ nop; // scope 5 at $DIR/dead_store_elimination.rs:26:5: 26:13
122+
StorageLive(_14); // scope 5 at $DIR/dead_store_elimination.rs:27:9: 27:14
123+
- (_14.0: u32) = const 32_u32; // scope 5 at $DIR/dead_store_elimination.rs:27:9: 27:14
124+
+ nop; // scope 5 at $DIR/dead_store_elimination.rs:27:9: 27:14
125+
_13 = const S(32_u32); // scope 5 at $DIR/dead_store_elimination.rs:27:5: 27:14
126+
// ty::Const
127+
// + ty: coverage::S
128+
// + val: Value(Scalar(0x00000020))
129+
// mir::Constant
130+
// + span: $DIR/dead_store_elimination.rs:27:5: 27:14
131+
// + literal: Const { ty: coverage::S, val: Value(Scalar(0x00000020)) }
132+
StorageDead(_14); // scope 5 at $DIR/dead_store_elimination.rs:27:13: 27:14
133+
StorageLive(_15); // scope 5 at $DIR/dead_store_elimination.rs:28:5: 28:12
134+
StorageLive(_16); // scope 5 at $DIR/dead_store_elimination.rs:28:10: 28:11
135+
_16 = const S(32_u32); // scope 5 at $DIR/dead_store_elimination.rs:28:10: 28:11
136+
// ty::Const
137+
// + ty: coverage::S
138+
// + val: Value(Scalar(0x00000020))
139+
// mir::Constant
140+
// + span: $DIR/dead_store_elimination.rs:28:10: 28:11
141+
// + literal: Const { ty: coverage::S, val: Value(Scalar(0x00000020)) }
142+
_15 = read::<S>(const S(32_u32)) -> bb4; // scope 5 at $DIR/dead_store_elimination.rs:28:5: 28:12
143+
// mir::Constant
144+
// + span: $DIR/dead_store_elimination.rs:28:5: 28:9
145+
// + literal: Const { ty: fn(coverage::S) {read::<coverage::S>}, val: Value(Scalar(<ZST>)) }
146+
// ty::Const
147+
// + ty: coverage::S
148+
// + val: Value(Scalar(0x00000020))
149+
// mir::Constant
150+
// + span: $DIR/dead_store_elimination.rs:28:5: 28:12
151+
// + literal: Const { ty: coverage::S, val: Value(Scalar(0x00000020)) }
152+
}
153+
154+
bb4: {
155+
StorageDead(_16); // scope 5 at $DIR/dead_store_elimination.rs:28:11: 28:12
156+
StorageDead(_15); // scope 5 at $DIR/dead_store_elimination.rs:28:12: 28:13
157+
StorageLive(_17); // scope 5 at $DIR/dead_store_elimination.rs:30:9: 30:14
158+
- _17 = const 40_i32; // scope 5 at $DIR/dead_store_elimination.rs:30:17: 30:19
159+
- _17 = const 41_i32; // scope 6 at $DIR/dead_store_elimination.rs:31:5: 31:11
160+
+ nop; // scope 5 at $DIR/dead_store_elimination.rs:30:17: 30:19
161+
+ nop; // scope 6 at $DIR/dead_store_elimination.rs:31:5: 31:11
162+
nop; // scope 0 at $DIR/dead_store_elimination.rs:6:19: 33:2
163+
StorageDead(_17); // scope 5 at $DIR/dead_store_elimination.rs:33:1: 33:2
164+
StorageDead(_13); // scope 4 at $DIR/dead_store_elimination.rs:33:1: 33:2
165+
StorageDead(_10); // scope 3 at $DIR/dead_store_elimination.rs:33:1: 33:2
166+
StorageDead(_6); // scope 2 at $DIR/dead_store_elimination.rs:33:1: 33:2
167+
StorageDead(_5); // scope 2 at $DIR/dead_store_elimination.rs:33:1: 33:2
168+
StorageDead(_4); // scope 1 at $DIR/dead_store_elimination.rs:33:1: 33:2
169+
StorageDead(_1); // scope 0 at $DIR/dead_store_elimination.rs:33:1: 33:2
170+
return; // scope 0 at $DIR/dead_store_elimination.rs:33:2: 33:2
171+
}
172+
}
173+

0 commit comments

Comments
 (0)