Skip to content

Commit a7d48fc

Browse files
committed
Simplify some of the copy-like forms
1 parent f1e1d90 commit a7d48fc

13 files changed

+663
-3
lines changed

compiler/rustc_mir_transform/src/instsimplify.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,18 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
265265
}
266266
// Collect available assignments, including those transformed from `Aggregate`.
267267
if let Some(local) = dest.as_local() {
268-
assignments[local] = if let Rvalue::Use(Operand::Copy(place)) = rvalue {
269-
Some(*place)
268+
assignments[local] = if let Rvalue::Use(operand) = rvalue
269+
&& let Some(place) = operand.place()
270+
{
271+
if let Some(rvalue_local) = place.as_local() {
272+
let place = assignments[rvalue_local];
273+
if operand.is_move() {
274+
assignments[rvalue_local] = None;
275+
}
276+
place
277+
} else {
278+
Some(place)
279+
}
270280
} else {
271281
// This assignment generally comes from debuginfo (e.g., Ref),
272282
// but we still need to check if a local is being overridden.
@@ -277,7 +287,9 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
277287
assignments.reset_all(None);
278288
}
279289
}
280-
StatementKind::StorageLive(_) | StatementKind::StorageDead(_) => {}
290+
StatementKind::StorageLive(_)
291+
| StatementKind::StorageDead(_)
292+
| StatementKind::Nop => {}
281293
_ => {
282294
assignments.reset_all(None);
283295
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
- // MIR for `all_copy` before InstSimplify-after-simplifycfg
2+
+ // MIR for `all_copy` after InstSimplify-after-simplifycfg
3+
4+
fn all_copy(_1: &AllCopy) -> AllCopy {
5+
debug v => _1;
6+
let mut _0: AllCopy;
7+
let _2: i32;
8+
let mut _5: i32;
9+
let mut _6: u64;
10+
let mut _7: [i8; 3];
11+
scope 1 {
12+
debug a => _2;
13+
let _3: u64;
14+
scope 2 {
15+
debug b => _3;
16+
let _4: [i8; 3];
17+
scope 3 {
18+
debug c => _4;
19+
}
20+
}
21+
}
22+
23+
bb0: {
24+
StorageLive(_2);
25+
_2 = ((*_1).0: i32);
26+
StorageLive(_3);
27+
_3 = ((*_1).1: u64);
28+
StorageLive(_4);
29+
_4 = ((*_1).2: [i8; 3]);
30+
StorageLive(_5);
31+
_5 = _2;
32+
StorageLive(_6);
33+
_6 = _3;
34+
StorageLive(_7);
35+
_7 = _4;
36+
- _0 = AllCopy { a: move _5, b: move _6, c: move _7 };
37+
+ _0 = (*_1);
38+
StorageDead(_7);
39+
StorageDead(_6);
40+
StorageDead(_5);
41+
StorageDead(_4);
42+
StorageDead(_3);
43+
StorageDead(_2);
44+
return;
45+
}
46+
}
47+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
- // MIR for `all_copy_different_type` before InstSimplify-after-simplifycfg
2+
+ // MIR for `all_copy_different_type` after InstSimplify-after-simplifycfg
3+
4+
fn all_copy_different_type(_1: &AllCopy) -> AllCopy2 {
5+
debug v => _1;
6+
let mut _0: AllCopy2;
7+
let _2: i32;
8+
let mut _5: i32;
9+
let mut _6: u64;
10+
let mut _7: [i8; 3];
11+
scope 1 {
12+
debug a => _2;
13+
let _3: u64;
14+
scope 2 {
15+
debug b => _3;
16+
let _4: [i8; 3];
17+
scope 3 {
18+
debug c => _4;
19+
}
20+
}
21+
}
22+
23+
bb0: {
24+
StorageLive(_2);
25+
_2 = ((*_1).0: i32);
26+
StorageLive(_3);
27+
_3 = ((*_1).1: u64);
28+
StorageLive(_4);
29+
_4 = ((*_1).2: [i8; 3]);
30+
StorageLive(_5);
31+
_5 = _2;
32+
StorageLive(_6);
33+
_6 = _3;
34+
StorageLive(_7);
35+
_7 = _4;
36+
_0 = AllCopy2 { a: move _5, b: move _6, c: move _7 };
37+
StorageDead(_7);
38+
StorageDead(_6);
39+
StorageDead(_5);
40+
StorageDead(_4);
41+
StorageDead(_3);
42+
StorageDead(_2);
43+
return;
44+
}
45+
}
46+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
- // MIR for `all_copy_has_changed` before InstSimplify-after-simplifycfg
2+
+ // MIR for `all_copy_has_changed` after InstSimplify-after-simplifycfg
3+
4+
fn all_copy_has_changed(_1: &mut AllCopy) -> AllCopy {
5+
debug v => _1;
6+
let mut _0: AllCopy;
7+
let _2: i32;
8+
let mut _5: i32;
9+
let mut _6: u64;
10+
let mut _7: [i8; 3];
11+
scope 1 {
12+
debug a => _2;
13+
let _3: u64;
14+
scope 2 {
15+
debug b => _3;
16+
let _4: [i8; 3];
17+
scope 3 {
18+
debug c => _4;
19+
}
20+
}
21+
}
22+
23+
bb0: {
24+
StorageLive(_2);
25+
_2 = ((*_1).0: i32);
26+
StorageLive(_3);
27+
_3 = ((*_1).1: u64);
28+
StorageLive(_4);
29+
_4 = ((*_1).2: [i8; 3]);
30+
((*_1).0: i32) = const 1_i32;
31+
StorageLive(_5);
32+
_5 = _2;
33+
StorageLive(_6);
34+
_6 = _3;
35+
StorageLive(_7);
36+
_7 = _4;
37+
_0 = AllCopy { a: move _5, b: move _6, c: move _7 };
38+
StorageDead(_7);
39+
StorageDead(_6);
40+
StorageDead(_5);
41+
StorageDead(_4);
42+
StorageDead(_3);
43+
StorageDead(_2);
44+
return;
45+
}
46+
}
47+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
- // MIR for `all_copy_move` before InstSimplify-after-simplifycfg
2+
+ // MIR for `all_copy_move` after InstSimplify-after-simplifycfg
3+
4+
fn all_copy_move(_1: AllCopy) -> AllCopy {
5+
debug v => _1;
6+
let mut _0: AllCopy;
7+
let _2: i32;
8+
let mut _5: i32;
9+
let mut _6: u64;
10+
let mut _7: [i8; 3];
11+
scope 1 {
12+
debug a => _2;
13+
let _3: u64;
14+
scope 2 {
15+
debug b => _3;
16+
let _4: [i8; 3];
17+
scope 3 {
18+
debug c => _4;
19+
}
20+
}
21+
}
22+
23+
bb0: {
24+
StorageLive(_2);
25+
_2 = (_1.0: i32);
26+
StorageLive(_3);
27+
_3 = (_1.1: u64);
28+
StorageLive(_4);
29+
_4 = (_1.2: [i8; 3]);
30+
StorageLive(_5);
31+
_5 = _2;
32+
StorageLive(_6);
33+
_6 = _3;
34+
StorageLive(_7);
35+
_7 = _4;
36+
_0 = AllCopy { a: move _5, b: move _6, c: move _7 };
37+
StorageDead(_7);
38+
StorageDead(_6);
39+
StorageDead(_5);
40+
StorageDead(_4);
41+
StorageDead(_3);
42+
StorageDead(_2);
43+
return;
44+
}
45+
}
46+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
- // MIR for `all_copy_ret_2` before InstSimplify-after-simplifycfg
2+
+ // MIR for `all_copy_ret_2` after InstSimplify-after-simplifycfg
3+
4+
fn all_copy_ret_2(_1: &AllCopy) -> (AllCopy, AllCopy) {
5+
debug v => _1;
6+
let mut _0: (AllCopy, AllCopy);
7+
let _2: i32;
8+
let mut _5: AllCopy;
9+
let mut _6: i32;
10+
let mut _7: u64;
11+
let mut _8: [i8; 3];
12+
let mut _9: AllCopy;
13+
let mut _10: i32;
14+
let mut _11: u64;
15+
let mut _12: [i8; 3];
16+
scope 1 {
17+
debug a => _2;
18+
let _3: u64;
19+
scope 2 {
20+
debug b => _3;
21+
let _4: [i8; 3];
22+
scope 3 {
23+
debug c => _4;
24+
}
25+
}
26+
}
27+
28+
bb0: {
29+
StorageLive(_2);
30+
_2 = ((*_1).0: i32);
31+
StorageLive(_3);
32+
_3 = ((*_1).1: u64);
33+
StorageLive(_4);
34+
_4 = ((*_1).2: [i8; 3]);
35+
StorageLive(_5);
36+
StorageLive(_6);
37+
_6 = _2;
38+
StorageLive(_7);
39+
_7 = _3;
40+
StorageLive(_8);
41+
_8 = _4;
42+
- _5 = AllCopy { a: move _6, b: move _7, c: move _8 };
43+
+ _5 = (*_1);
44+
StorageDead(_8);
45+
StorageDead(_7);
46+
StorageDead(_6);
47+
StorageLive(_9);
48+
StorageLive(_10);
49+
_10 = _2;
50+
StorageLive(_11);
51+
_11 = _3;
52+
StorageLive(_12);
53+
_12 = _4;
54+
- _9 = AllCopy { a: move _10, b: move _11, c: move _12 };
55+
+ _9 = (*_1);
56+
StorageDead(_12);
57+
StorageDead(_11);
58+
StorageDead(_10);
59+
_0 = (move _5, move _9);
60+
StorageDead(_9);
61+
StorageDead(_5);
62+
StorageDead(_4);
63+
StorageDead(_3);
64+
StorageDead(_2);
65+
return;
66+
}
67+
}
68+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
- // MIR for `all_copy_use_changed` before InstSimplify-after-simplifycfg
2+
+ // MIR for `all_copy_use_changed` after InstSimplify-after-simplifycfg
3+
4+
fn all_copy_use_changed(_1: &mut AllCopy) -> AllCopy {
5+
debug v => _1;
6+
let mut _0: AllCopy;
7+
let mut _2: i32;
8+
let mut _3: i32;
9+
let mut _6: i32;
10+
let mut _7: u64;
11+
let mut _8: [i8; 3];
12+
scope 1 {
13+
debug a => _2;
14+
let _4: u64;
15+
scope 2 {
16+
debug b => _4;
17+
let _5: [i8; 3];
18+
scope 3 {
19+
debug c => _5;
20+
}
21+
}
22+
}
23+
24+
bb0: {
25+
StorageLive(_2);
26+
_2 = ((*_1).0: i32);
27+
((*_1).0: i32) = const 1_i32;
28+
StorageLive(_3);
29+
_3 = ((*_1).0: i32);
30+
_2 = move _3;
31+
StorageDead(_3);
32+
StorageLive(_4);
33+
_4 = ((*_1).1: u64);
34+
StorageLive(_5);
35+
_5 = ((*_1).2: [i8; 3]);
36+
StorageLive(_6);
37+
_6 = _2;
38+
StorageLive(_7);
39+
_7 = _4;
40+
StorageLive(_8);
41+
_8 = _5;
42+
- _0 = AllCopy { a: move _6, b: move _7, c: move _8 };
43+
+ _0 = (*_1);
44+
StorageDead(_8);
45+
StorageDead(_7);
46+
StorageDead(_6);
47+
StorageDead(_5);
48+
StorageDead(_4);
49+
StorageDead(_2);
50+
return;
51+
}
52+
}
53+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
- // MIR for `all_copy_use_changed_2` before InstSimplify-after-simplifycfg
2+
+ // MIR for `all_copy_use_changed_2` after InstSimplify-after-simplifycfg
3+
4+
fn all_copy_use_changed_2(_1: &mut AllCopy) -> AllCopy {
5+
debug v => _1;
6+
let mut _0: AllCopy;
7+
let mut _2: i32;
8+
let mut _5: i32;
9+
let mut _6: i32;
10+
let mut _7: u64;
11+
let mut _8: [i8; 3];
12+
scope 1 {
13+
debug a => _2;
14+
let _3: u64;
15+
scope 2 {
16+
debug b => _3;
17+
let _4: [i8; 3];
18+
scope 3 {
19+
debug c => _4;
20+
}
21+
}
22+
}
23+
24+
bb0: {
25+
StorageLive(_2);
26+
_2 = ((*_1).0: i32);
27+
StorageLive(_3);
28+
_3 = ((*_1).1: u64);
29+
StorageLive(_4);
30+
_4 = ((*_1).2: [i8; 3]);
31+
((*_1).0: i32) = const 1_i32;
32+
StorageLive(_5);
33+
_5 = ((*_1).0: i32);
34+
_2 = move _5;
35+
StorageDead(_5);
36+
StorageLive(_6);
37+
_6 = _2;
38+
StorageLive(_7);
39+
_7 = _3;
40+
StorageLive(_8);
41+
_8 = _4;
42+
_0 = AllCopy { a: move _6, b: move _7, c: move _8 };
43+
StorageDead(_8);
44+
StorageDead(_7);
45+
StorageDead(_6);
46+
StorageDead(_4);
47+
StorageDead(_3);
48+
StorageDead(_2);
49+
return;
50+
}
51+
}
52+

0 commit comments

Comments
 (0)