Skip to content

Commit 83173c6

Browse files
committed
Add partial propagation test.
1 parent 10ec949 commit 83173c6

5 files changed

+162
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
- // MIR for `foo` before ConstProp
2+
+ // MIR for `foo` after ConstProp
3+
4+
fn foo(_1: u8) -> () {
5+
debug x => _1; // in scope 0 at $DIR/aggregate.rs:+0:8: +0:9
6+
let mut _0: (); // return place in scope 0 at $DIR/aggregate.rs:+0:15: +0:15
7+
let _2: i32; // in scope 0 at $DIR/aggregate.rs:+2:9: +2:14
8+
let mut _3: i32; // in scope 0 at $DIR/aggregate.rs:+2:17: +2:25
9+
let mut _4: (i32, u8); // in scope 0 at $DIR/aggregate.rs:+2:17: +2:23
10+
let mut _5: u8; // in scope 0 at $DIR/aggregate.rs:+2:21: +2:22
11+
let mut _7: i32; // in scope 0 at $DIR/aggregate.rs:+3:18: +3:26
12+
let mut _8: (u8, i32); // in scope 0 at $DIR/aggregate.rs:+3:18: +3:24
13+
let mut _9: u8; // in scope 0 at $DIR/aggregate.rs:+3:19: +3:20
14+
scope 1 {
15+
debug first => _2; // in scope 1 at $DIR/aggregate.rs:+2:9: +2:14
16+
let _6: i32; // in scope 1 at $DIR/aggregate.rs:+3:9: +3:15
17+
scope 2 {
18+
debug second => _6; // in scope 2 at $DIR/aggregate.rs:+3:9: +3:15
19+
}
20+
}
21+
22+
bb0: {
23+
StorageLive(_2); // scope 0 at $DIR/aggregate.rs:+2:9: +2:14
24+
StorageLive(_3); // scope 0 at $DIR/aggregate.rs:+2:17: +2:25
25+
StorageLive(_4); // scope 0 at $DIR/aggregate.rs:+2:17: +2:23
26+
StorageLive(_5); // scope 0 at $DIR/aggregate.rs:+2:21: +2:22
27+
_5 = _1; // scope 0 at $DIR/aggregate.rs:+2:21: +2:22
28+
_4 = (const 0_i32, move _5); // scope 0 at $DIR/aggregate.rs:+2:17: +2:23
29+
StorageDead(_5); // scope 0 at $DIR/aggregate.rs:+2:22: +2:23
30+
- _3 = (_4.0: i32); // scope 0 at $DIR/aggregate.rs:+2:17: +2:25
31+
- _2 = Add(move _3, const 1_i32); // scope 0 at $DIR/aggregate.rs:+2:17: +2:29
32+
+ _3 = const 0_i32; // scope 0 at $DIR/aggregate.rs:+2:17: +2:25
33+
+ _2 = const 1_i32; // scope 0 at $DIR/aggregate.rs:+2:17: +2:29
34+
StorageDead(_3); // scope 0 at $DIR/aggregate.rs:+2:28: +2:29
35+
StorageDead(_4); // scope 0 at $DIR/aggregate.rs:+2:29: +2:30
36+
StorageLive(_6); // scope 1 at $DIR/aggregate.rs:+3:9: +3:15
37+
StorageLive(_7); // scope 1 at $DIR/aggregate.rs:+3:18: +3:26
38+
StorageLive(_8); // scope 1 at $DIR/aggregate.rs:+3:18: +3:24
39+
StorageLive(_9); // scope 1 at $DIR/aggregate.rs:+3:19: +3:20
40+
_9 = _1; // scope 1 at $DIR/aggregate.rs:+3:19: +3:20
41+
_8 = (move _9, const 1_i32); // scope 1 at $DIR/aggregate.rs:+3:18: +3:24
42+
StorageDead(_9); // scope 1 at $DIR/aggregate.rs:+3:23: +3:24
43+
- _7 = (_8.1: i32); // scope 1 at $DIR/aggregate.rs:+3:18: +3:26
44+
- _6 = Add(move _7, const 2_i32); // scope 1 at $DIR/aggregate.rs:+3:18: +3:30
45+
+ _7 = const 1_i32; // scope 1 at $DIR/aggregate.rs:+3:18: +3:26
46+
+ _6 = const 3_i32; // scope 1 at $DIR/aggregate.rs:+3:18: +3:30
47+
StorageDead(_7); // scope 1 at $DIR/aggregate.rs:+3:29: +3:30
48+
StorageDead(_8); // scope 1 at $DIR/aggregate.rs:+3:30: +3:31
49+
_0 = const (); // scope 0 at $DIR/aggregate.rs:+0:15: +4:2
50+
StorageDead(_6); // scope 1 at $DIR/aggregate.rs:+4:1: +4:2
51+
StorageDead(_2); // scope 0 at $DIR/aggregate.rs:+4:1: +4:2
52+
return; // scope 0 at $DIR/aggregate.rs:+4:2: +4:2
53+
}
54+
}
55+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// MIR for `foo` after PreCodegen
2+
3+
fn foo(_1: u8) -> () {
4+
debug x => _1; // in scope 0 at $DIR/aggregate.rs:+0:8: +0:9
5+
let mut _0: (); // return place in scope 0 at $DIR/aggregate.rs:+0:15: +0:15
6+
let _2: i32; // in scope 0 at $DIR/aggregate.rs:+2:9: +2:14
7+
let mut _3: i32; // in scope 0 at $DIR/aggregate.rs:+2:17: +2:25
8+
let mut _4: (i32, u8); // in scope 0 at $DIR/aggregate.rs:+2:17: +2:23
9+
let mut _5: u8; // in scope 0 at $DIR/aggregate.rs:+2:21: +2:22
10+
let mut _7: i32; // in scope 0 at $DIR/aggregate.rs:+3:18: +3:26
11+
let mut _8: (u8, i32); // in scope 0 at $DIR/aggregate.rs:+3:18: +3:24
12+
let mut _9: u8; // in scope 0 at $DIR/aggregate.rs:+3:19: +3:20
13+
scope 1 {
14+
debug first => _2; // in scope 1 at $DIR/aggregate.rs:+2:9: +2:14
15+
let _6: i32; // in scope 1 at $DIR/aggregate.rs:+3:9: +3:15
16+
scope 2 {
17+
debug second => _6; // in scope 2 at $DIR/aggregate.rs:+3:9: +3:15
18+
}
19+
}
20+
21+
bb0: {
22+
StorageLive(_2); // scope 0 at $DIR/aggregate.rs:+2:9: +2:14
23+
StorageLive(_3); // scope 0 at $DIR/aggregate.rs:+2:17: +2:25
24+
StorageLive(_4); // scope 0 at $DIR/aggregate.rs:+2:17: +2:23
25+
StorageLive(_5); // scope 0 at $DIR/aggregate.rs:+2:21: +2:22
26+
_5 = _1; // scope 0 at $DIR/aggregate.rs:+2:21: +2:22
27+
_4 = (const 0_i32, move _5); // scope 0 at $DIR/aggregate.rs:+2:17: +2:23
28+
StorageDead(_5); // scope 0 at $DIR/aggregate.rs:+2:22: +2:23
29+
_3 = const 0_i32; // scope 0 at $DIR/aggregate.rs:+2:17: +2:25
30+
_2 = const 1_i32; // scope 0 at $DIR/aggregate.rs:+2:17: +2:29
31+
StorageDead(_3); // scope 0 at $DIR/aggregate.rs:+2:28: +2:29
32+
StorageDead(_4); // scope 0 at $DIR/aggregate.rs:+2:29: +2:30
33+
StorageLive(_6); // scope 1 at $DIR/aggregate.rs:+3:9: +3:15
34+
StorageLive(_7); // scope 1 at $DIR/aggregate.rs:+3:18: +3:26
35+
StorageLive(_8); // scope 1 at $DIR/aggregate.rs:+3:18: +3:24
36+
StorageLive(_9); // scope 1 at $DIR/aggregate.rs:+3:19: +3:20
37+
_9 = _1; // scope 1 at $DIR/aggregate.rs:+3:19: +3:20
38+
_8 = (move _9, const 1_i32); // scope 1 at $DIR/aggregate.rs:+3:18: +3:24
39+
StorageDead(_9); // scope 1 at $DIR/aggregate.rs:+3:23: +3:24
40+
_7 = const 1_i32; // scope 1 at $DIR/aggregate.rs:+3:18: +3:26
41+
_6 = const 3_i32; // scope 1 at $DIR/aggregate.rs:+3:18: +3:30
42+
StorageDead(_7); // scope 1 at $DIR/aggregate.rs:+3:29: +3:30
43+
StorageDead(_8); // scope 1 at $DIR/aggregate.rs:+3:30: +3:31
44+
_0 = const (); // scope 0 at $DIR/aggregate.rs:+0:15: +4:2
45+
StorageDead(_6); // scope 1 at $DIR/aggregate.rs:+4:1: +4:2
46+
StorageDead(_2); // scope 0 at $DIR/aggregate.rs:+4:1: +4:2
47+
return; // scope 0 at $DIR/aggregate.rs:+4:2: +4:2
48+
}
49+
}

tests/mir-opt/const_prop/aggregate.main.ConstProp.diff

+26-11
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
fn main() -> () {
55
let mut _0: (); // return place in scope 0 at $DIR/aggregate.rs:+0:11: +0:11
6-
let _1: i32; // in scope 0 at $DIR/aggregate.rs:+1:9: +1:10
7-
let mut _2: i32; // in scope 0 at $DIR/aggregate.rs:+1:13: +1:24
8-
let mut _3: (i32, i32, i32); // in scope 0 at $DIR/aggregate.rs:+1:13: +1:22
6+
let _1: u8; // in scope 0 at $DIR/aggregate.rs:+1:9: +1:10
7+
let mut _2: u8; // in scope 0 at $DIR/aggregate.rs:+1:13: +1:24
8+
let mut _3: (i32, u8, i32); // in scope 0 at $DIR/aggregate.rs:+1:13: +1:22
9+
let _4: (); // in scope 0 at $DIR/aggregate.rs:+2:5: +2:11
10+
let mut _5: u8; // in scope 0 at $DIR/aggregate.rs:+2:9: +2:10
911
scope 1 {
1012
debug x => _1; // in scope 1 at $DIR/aggregate.rs:+1:9: +1:10
1113
}
@@ -14,16 +16,29 @@
1416
StorageLive(_1); // scope 0 at $DIR/aggregate.rs:+1:9: +1:10
1517
StorageLive(_2); // scope 0 at $DIR/aggregate.rs:+1:13: +1:24
1618
StorageLive(_3); // scope 0 at $DIR/aggregate.rs:+1:13: +1:22
17-
_3 = (const 0_i32, const 1_i32, const 2_i32); // scope 0 at $DIR/aggregate.rs:+1:13: +1:22
18-
- _2 = (_3.1: i32); // scope 0 at $DIR/aggregate.rs:+1:13: +1:24
19-
- _1 = Add(move _2, const 0_i32); // scope 0 at $DIR/aggregate.rs:+1:13: +1:28
20-
+ _2 = const 1_i32; // scope 0 at $DIR/aggregate.rs:+1:13: +1:24
21-
+ _1 = const 1_i32; // scope 0 at $DIR/aggregate.rs:+1:13: +1:28
19+
_3 = (const 0_i32, const 1_u8, const 2_i32); // scope 0 at $DIR/aggregate.rs:+1:13: +1:22
20+
- _2 = (_3.1: u8); // scope 0 at $DIR/aggregate.rs:+1:13: +1:24
21+
- _1 = Add(move _2, const 0_u8); // scope 0 at $DIR/aggregate.rs:+1:13: +1:28
22+
+ _2 = const 1_u8; // scope 0 at $DIR/aggregate.rs:+1:13: +1:24
23+
+ _1 = const 1_u8; // scope 0 at $DIR/aggregate.rs:+1:13: +1:28
2224
StorageDead(_2); // scope 0 at $DIR/aggregate.rs:+1:27: +1:28
2325
StorageDead(_3); // scope 0 at $DIR/aggregate.rs:+1:28: +1:29
24-
_0 = const (); // scope 0 at $DIR/aggregate.rs:+0:11: +2:2
25-
StorageDead(_1); // scope 0 at $DIR/aggregate.rs:+2:1: +2:2
26-
return; // scope 0 at $DIR/aggregate.rs:+2:2: +2:2
26+
StorageLive(_4); // scope 1 at $DIR/aggregate.rs:+2:5: +2:11
27+
StorageLive(_5); // scope 1 at $DIR/aggregate.rs:+2:9: +2:10
28+
- _5 = _1; // scope 1 at $DIR/aggregate.rs:+2:9: +2:10
29+
+ _5 = const 1_u8; // scope 1 at $DIR/aggregate.rs:+2:9: +2:10
30+
_4 = foo(move _5) -> bb1; // scope 1 at $DIR/aggregate.rs:+2:5: +2:11
31+
// mir::Constant
32+
// + span: $DIR/aggregate.rs:8:5: 8:8
33+
// + literal: Const { ty: fn(u8) {foo}, val: Value(<ZST>) }
34+
}
35+
36+
bb1: {
37+
StorageDead(_5); // scope 1 at $DIR/aggregate.rs:+2:10: +2:11
38+
StorageDead(_4); // scope 1 at $DIR/aggregate.rs:+2:11: +2:12
39+
_0 = const (); // scope 0 at $DIR/aggregate.rs:+0:11: +3:2
40+
StorageDead(_1); // scope 0 at $DIR/aggregate.rs:+3:1: +3:2
41+
return; // scope 0 at $DIR/aggregate.rs:+3:2: +3:2
2742
}
2843
}
2944

tests/mir-opt/const_prop/aggregate.main.PreCodegen.after.mir

+23-9
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
fn main() -> () {
44
let mut _0: (); // return place in scope 0 at $DIR/aggregate.rs:+0:11: +0:11
5-
let _1: i32; // in scope 0 at $DIR/aggregate.rs:+1:9: +1:10
6-
let mut _2: i32; // in scope 0 at $DIR/aggregate.rs:+1:13: +1:24
7-
let mut _3: (i32, i32, i32); // in scope 0 at $DIR/aggregate.rs:+1:13: +1:22
5+
let _1: u8; // in scope 0 at $DIR/aggregate.rs:+1:9: +1:10
6+
let mut _2: u8; // in scope 0 at $DIR/aggregate.rs:+1:13: +1:24
7+
let mut _3: (i32, u8, i32); // in scope 0 at $DIR/aggregate.rs:+1:13: +1:22
8+
let _4: (); // in scope 0 at $DIR/aggregate.rs:+2:5: +2:11
9+
let mut _5: u8; // in scope 0 at $DIR/aggregate.rs:+2:9: +2:10
810
scope 1 {
911
debug x => _1; // in scope 1 at $DIR/aggregate.rs:+1:9: +1:10
1012
}
@@ -13,13 +15,25 @@ fn main() -> () {
1315
StorageLive(_1); // scope 0 at $DIR/aggregate.rs:+1:9: +1:10
1416
StorageLive(_2); // scope 0 at $DIR/aggregate.rs:+1:13: +1:24
1517
StorageLive(_3); // scope 0 at $DIR/aggregate.rs:+1:13: +1:22
16-
_3 = (const 0_i32, const 1_i32, const 2_i32); // scope 0 at $DIR/aggregate.rs:+1:13: +1:22
17-
_2 = const 1_i32; // scope 0 at $DIR/aggregate.rs:+1:13: +1:24
18-
_1 = const 1_i32; // scope 0 at $DIR/aggregate.rs:+1:13: +1:28
18+
_3 = (const 0_i32, const 1_u8, const 2_i32); // scope 0 at $DIR/aggregate.rs:+1:13: +1:22
19+
_2 = const 1_u8; // scope 0 at $DIR/aggregate.rs:+1:13: +1:24
20+
_1 = const 1_u8; // scope 0 at $DIR/aggregate.rs:+1:13: +1:28
1921
StorageDead(_2); // scope 0 at $DIR/aggregate.rs:+1:27: +1:28
2022
StorageDead(_3); // scope 0 at $DIR/aggregate.rs:+1:28: +1:29
21-
_0 = const (); // scope 0 at $DIR/aggregate.rs:+0:11: +2:2
22-
StorageDead(_1); // scope 0 at $DIR/aggregate.rs:+2:1: +2:2
23-
return; // scope 0 at $DIR/aggregate.rs:+2:2: +2:2
23+
StorageLive(_4); // scope 1 at $DIR/aggregate.rs:+2:5: +2:11
24+
StorageLive(_5); // scope 1 at $DIR/aggregate.rs:+2:9: +2:10
25+
_5 = const 1_u8; // scope 1 at $DIR/aggregate.rs:+2:9: +2:10
26+
_4 = foo(move _5) -> bb1; // scope 1 at $DIR/aggregate.rs:+2:5: +2:11
27+
// mir::Constant
28+
// + span: $DIR/aggregate.rs:8:5: 8:8
29+
// + literal: Const { ty: fn(u8) {foo}, val: Value(<ZST>) }
30+
}
31+
32+
bb1: {
33+
StorageDead(_5); // scope 1 at $DIR/aggregate.rs:+2:10: +2:11
34+
StorageDead(_4); // scope 1 at $DIR/aggregate.rs:+2:11: +2:12
35+
_0 = const (); // scope 0 at $DIR/aggregate.rs:+0:11: +3:2
36+
StorageDead(_1); // scope 0 at $DIR/aggregate.rs:+3:1: +3:2
37+
return; // scope 0 at $DIR/aggregate.rs:+3:2: +3:2
2438
}
2539
}

tests/mir-opt/const_prop/aggregate.rs

+9
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,13 @@
55
// EMIT_MIR aggregate.main.PreCodegen.after.mir
66
fn main() {
77
let x = (0, 1, 2).1 + 0;
8+
foo(x);
9+
}
10+
11+
// EMIT_MIR aggregate.foo.ConstProp.diff
12+
// EMIT_MIR aggregate.foo.PreCodegen.after.mir
13+
fn foo(x: u8) {
14+
// Verify that we still propagate if part of the aggregate is not known.
15+
let first = (0, x).0 + 1;
16+
let second = (x, 1).1 + 2;
817
}

0 commit comments

Comments
 (0)