Skip to content

Commit 3c10cf0

Browse files
committed
Remove both StorageLive and StorageDead in CopyProp.
1 parent 05ee406 commit 3c10cf0

19 files changed

+24
-49
lines changed

compiler/rustc_mir_transform/src/copy_prop.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,20 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
162162
}
163163

164164
fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, loc: Location) {
165-
if let StatementKind::StorageDead(l) = stmt.kind
166-
&& self.storage_to_remove.contains(l)
167-
{
168-
stmt.make_nop();
169-
} else if let StatementKind::Assign(box (ref place, ref mut rvalue)) = stmt.kind
170-
&& place.as_local().is_some()
171-
{
172-
// Do not replace assignments.
173-
self.visit_rvalue(rvalue, loc)
174-
} else {
175-
self.super_statement(stmt, loc);
165+
match stmt.kind {
166+
// When removing storage statements, we need to remove both (#107511).
167+
StatementKind::StorageLive(l) | StatementKind::StorageDead(l)
168+
if self.storage_to_remove.contains(l) =>
169+
{
170+
stmt.make_nop()
171+
}
172+
StatementKind::Assign(box (ref place, ref mut rvalue))
173+
if place.as_local().is_some() =>
174+
{
175+
// Do not replace assignments.
176+
self.visit_rvalue(rvalue, loc)
177+
}
178+
_ => self.super_statement(stmt, loc),
176179
}
177180
}
178181
}

tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff

-3
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,8 @@
5656
}
5757

5858
bb0: {
59-
StorageLive(_1); // scope 0 at $DIR/const_debuginfo.rs:+1:9: +1:10
6059
_1 = const 1_u8; // scope 0 at $DIR/const_debuginfo.rs:+1:13: +1:16
61-
StorageLive(_2); // scope 1 at $DIR/const_debuginfo.rs:+2:9: +2:10
6260
_2 = const 2_u8; // scope 1 at $DIR/const_debuginfo.rs:+2:13: +2:16
63-
StorageLive(_3); // scope 2 at $DIR/const_debuginfo.rs:+3:9: +3:10
6461
_3 = const 3_u8; // scope 2 at $DIR/const_debuginfo.rs:+3:13: +3:16
6562
StorageLive(_4); // scope 3 at $DIR/const_debuginfo.rs:+4:9: +4:12
6663
StorageLive(_5); // scope 3 at $DIR/const_debuginfo.rs:+4:15: +4:20

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

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
}
1919

2020
bb0: {
21-
StorageLive(_1); // scope 0 at $DIR/bad_op_mod_by_zero.rs:+1:9: +1:10
2221
_1 = const 0_i32; // scope 0 at $DIR/bad_op_mod_by_zero.rs:+1:13: +1:14
2322
StorageLive(_2); // scope 1 at $DIR/bad_op_mod_by_zero.rs:+2:9: +2:11
2423
- _4 = Eq(_1, const 0_i32); // scope 1 at $DIR/bad_op_mod_by_zero.rs:+2:14: +2:19

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

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
}
1212

1313
bb0: {
14-
StorageLive(_1); // scope 0 at $DIR/scalar_literal_propagation.rs:+1:9: +1:10
1514
_1 = const 1_u32; // scope 0 at $DIR/scalar_literal_propagation.rs:+1:13: +1:14
1615
StorageLive(_2); // scope 1 at $DIR/scalar_literal_propagation.rs:+2:5: +2:15
1716
- _2 = consume(_1) -> bb1; // scope 1 at $DIR/scalar_literal_propagation.rs:+2:5: +2:15

tests/mir-opt/copy-prop/cycle.main.CopyProp.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
}
3030

3131
bb1: {
32-
StorageLive(_2); // scope 1 at $DIR/cycle.rs:+2:9: +2:10
32+
- StorageLive(_2); // scope 1 at $DIR/cycle.rs:+2:9: +2:10
3333
_2 = _1; // scope 1 at $DIR/cycle.rs:+2:13: +2:14
3434
- StorageLive(_3); // scope 2 at $DIR/cycle.rs:+3:9: +3:10
3535
- _3 = _2; // scope 2 at $DIR/cycle.rs:+3:13: +3:14

tests/mir-opt/copy-prop/dead_stores_79191.f.CopyProp.after.mir

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ fn f(_1: usize) -> usize {
1111
}
1212

1313
bb0: {
14-
StorageLive(_2); // scope 0 at $DIR/dead_stores_79191.rs:+1:9: +1:10
1514
_2 = _1; // scope 0 at $DIR/dead_stores_79191.rs:+1:13: +1:14
1615
_1 = const 5_usize; // scope 1 at $DIR/dead_stores_79191.rs:+2:5: +2:10
1716
_1 = _2; // scope 1 at $DIR/dead_stores_79191.rs:+3:5: +3:10

tests/mir-opt/copy-prop/dead_stores_better.f.CopyProp.after.mir

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ fn f(_1: usize) -> usize {
1111
}
1212

1313
bb0: {
14-
StorageLive(_2); // scope 0 at $DIR/dead_stores_better.rs:+1:9: +1:10
1514
_2 = _1; // scope 0 at $DIR/dead_stores_better.rs:+1:13: +1:14
1615
_1 = const 5_usize; // scope 1 at $DIR/dead_stores_better.rs:+2:5: +2:10
1716
_1 = _2; // scope 1 at $DIR/dead_stores_better.rs:+3:5: +3:10

tests/mir-opt/copy-prop/issue_107511.main.CopyProp.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
}
9999

100100
bb5: {
101-
StorageLive(_17); // scope 3 at $DIR/issue_107511.rs:+6:9: +6:10
101+
- StorageLive(_17); // scope 3 at $DIR/issue_107511.rs:+6:9: +6:10
102102
_17 = ((_12 as Some).0: usize); // scope 3 at $DIR/issue_107511.rs:+6:9: +6:10
103103
StorageLive(_18); // scope 4 at $DIR/issue_107511.rs:+7:16: +7:20
104104
- StorageLive(_19); // scope 4 at $DIR/issue_107511.rs:+7:18: +7:19

tests/mir-opt/dataflow-const-prop/inherit_overflow.main.DataflowConstProp.diff

-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
}
1717

1818
bb0: {
19-
StorageLive(_1); // scope 0 at $DIR/inherit_overflow.rs:+3:13: +3:47
2019
_1 = const u8::MAX; // scope 0 at $DIR/inherit_overflow.rs:+3:13: +3:47
21-
StorageLive(_2); // scope 0 at $DIR/inherit_overflow.rs:+3:13: +3:47
2220
_2 = const 1_u8; // scope 0 at $DIR/inherit_overflow.rs:+3:13: +3:47
2321
_5 = CheckedAdd(const u8::MAX, const 1_u8); // scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
2422
assert(!move (_5.1: bool), "attempt to compute `{} + {}`, which would overflow", const u8::MAX, const 1_u8) -> bb1; // scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL

tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
}
8080

8181
bb6: {
82-
StorageLive(_10); // scope 3 at $DIR/funky_arms.rs:+13:17: +13:26
8382
_10 = ((_7 as Some).0: usize); // scope 3 at $DIR/funky_arms.rs:+13:17: +13:26
8483
StorageLive(_11); // scope 3 at $DIR/funky_arms.rs:+15:43: +15:46
8584
_11 = &mut (*_1); // scope 3 at $DIR/funky_arms.rs:+15:43: +15:46

tests/mir-opt/issue_101973.inner.ConstProp.diff

-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
bb0: {
3434
StorageLive(_2); // scope 0 at $DIR/issue_101973.rs:+1:5: +1:65
3535
StorageLive(_3); // scope 0 at $DIR/issue_101973.rs:+1:5: +1:58
36-
StorageLive(_4); // scope 0 at $DIR/issue_101973.rs:+1:5: +1:17
3736
StorageLive(_12); // scope 2 at $DIR/issue_101973.rs:7:12: 7:27
3837
StorageLive(_13); // scope 2 at $DIR/issue_101973.rs:7:12: 7:20
3938
_14 = CheckedShr(_1, const 0_i32); // scope 2 at $DIR/issue_101973.rs:7:12: 7:20
@@ -63,7 +62,6 @@
6362
StorageDead(_13); // scope 2 at $DIR/issue_101973.rs:7:26: 7:27
6463
_4 = BitOr(const 0_u32, move _12); // scope 2 at $DIR/issue_101973.rs:7:5: 7:27
6564
StorageDead(_12); // scope 2 at $DIR/issue_101973.rs:7:26: 7:27
66-
StorageLive(_6); // scope 0 at $DIR/issue_101973.rs:+1:31: +1:57
6765
StorageLive(_7); // scope 0 at $DIR/issue_101973.rs:+1:31: +1:52
6866
StorageLive(_8); // scope 0 at $DIR/issue_101973.rs:+1:32: +1:45
6967
_10 = CheckedShr(_1, const 8_i32); // scope 0 at $DIR/issue_101973.rs:+1:32: +1:45

tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.diff

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
bb0: {
3131
StorageLive(_2); // scope 0 at $DIR/issue_76432.rs:+1:9: +1:10
32-
StorageLive(_4); // scope 0 at $DIR/issue_76432.rs:+1:19: +1:29
3332
StorageLive(_5); // scope 0 at $DIR/issue_76432.rs:+1:20: +1:29
3433
_5 = [_1, _1, _1]; // scope 0 at $DIR/issue_76432.rs:+1:20: +1:29
3534
_4 = &_5; // scope 0 at $DIR/issue_76432.rs:+1:19: +1:29

tests/mir-opt/simplify_match.main.ConstProp.diff

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
}
1111

1212
bb0: {
13-
StorageLive(_2); // scope 0 at $DIR/simplify_match.rs:+1:17: +1:18
1413
_2 = const false; // scope 0 at $DIR/simplify_match.rs:+1:21: +1:26
1514
- switchInt(_2) -> [0: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_match.rs:+1:5: +1:31
1615
+ switchInt(const false) -> [0: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_match.rs:+1:5: +1:31

tests/mir-opt/slice_filter.variant_a-{closure#0}.CopyProp.diff

+4-4
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@
101101
}
102102

103103
bb0: {
104-
StorageLive(_3); // scope 0 at $DIR/slice_filter.rs:+0:27: +0:28
104+
- StorageLive(_3); // scope 0 at $DIR/slice_filter.rs:+0:27: +0:28
105105
_25 = deref_copy (*_2); // scope 0 at $DIR/slice_filter.rs:+0:27: +0:28
106106
_3 = &((*_25).0: usize); // scope 0 at $DIR/slice_filter.rs:+0:27: +0:28
107-
StorageLive(_4); // scope 0 at $DIR/slice_filter.rs:+0:30: +0:31
107+
- StorageLive(_4); // scope 0 at $DIR/slice_filter.rs:+0:30: +0:31
108108
_26 = deref_copy (*_2); // scope 0 at $DIR/slice_filter.rs:+0:30: +0:31
109109
_4 = &((*_26).1: usize); // scope 0 at $DIR/slice_filter.rs:+0:30: +0:31
110-
StorageLive(_5); // scope 0 at $DIR/slice_filter.rs:+0:33: +0:34
110+
- StorageLive(_5); // scope 0 at $DIR/slice_filter.rs:+0:33: +0:34
111111
_27 = deref_copy (*_2); // scope 0 at $DIR/slice_filter.rs:+0:33: +0:34
112112
_5 = &((*_27).2: usize); // scope 0 at $DIR/slice_filter.rs:+0:33: +0:34
113-
StorageLive(_6); // scope 0 at $DIR/slice_filter.rs:+0:36: +0:37
113+
- StorageLive(_6); // scope 0 at $DIR/slice_filter.rs:+0:36: +0:37
114114
_28 = deref_copy (*_2); // scope 0 at $DIR/slice_filter.rs:+0:36: +0:37
115115
_6 = &((*_28).3: usize); // scope 0 at $DIR/slice_filter.rs:+0:36: +0:37
116116
StorageLive(_7); // scope 1 at $DIR/slice_filter.rs:+0:40: +0:56

tests/mir-opt/slice_filter.variant_a-{closure#0}.DestinationPropagation.diff

-4
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,12 @@
8585
}
8686

8787
bb0: {
88-
StorageLive(_3); // scope 0 at $DIR/slice_filter.rs:+0:27: +0:28
8988
_25 = deref_copy (*_2); // scope 0 at $DIR/slice_filter.rs:+0:27: +0:28
9089
_3 = &((*_25).0: usize); // scope 0 at $DIR/slice_filter.rs:+0:27: +0:28
91-
StorageLive(_4); // scope 0 at $DIR/slice_filter.rs:+0:30: +0:31
9290
_26 = deref_copy (*_2); // scope 0 at $DIR/slice_filter.rs:+0:30: +0:31
9391
_4 = &((*_26).1: usize); // scope 0 at $DIR/slice_filter.rs:+0:30: +0:31
94-
StorageLive(_5); // scope 0 at $DIR/slice_filter.rs:+0:33: +0:34
9592
_27 = deref_copy (*_2); // scope 0 at $DIR/slice_filter.rs:+0:33: +0:34
9693
_5 = &((*_27).2: usize); // scope 0 at $DIR/slice_filter.rs:+0:33: +0:34
97-
StorageLive(_6); // scope 0 at $DIR/slice_filter.rs:+0:36: +0:37
9894
_28 = deref_copy (*_2); // scope 0 at $DIR/slice_filter.rs:+0:36: +0:37
9995
_6 = &((*_28).3: usize); // scope 0 at $DIR/slice_filter.rs:+0:36: +0:37
10096
- StorageLive(_7); // scope 1 at $DIR/slice_filter.rs:+0:40: +0:56

tests/mir-opt/slice_filter.variant_b-{closure#0}.CopyProp.diff

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@
3333
}
3434

3535
bb0: {
36-
StorageLive(_3); // scope 0 at $DIR/slice_filter.rs:+0:29: +0:30
36+
- StorageLive(_3); // scope 0 at $DIR/slice_filter.rs:+0:29: +0:30
3737
_21 = deref_copy (*_2); // scope 0 at $DIR/slice_filter.rs:+0:29: +0:30
3838
_3 = ((*_21).0: usize); // scope 0 at $DIR/slice_filter.rs:+0:29: +0:30
39-
StorageLive(_4); // scope 0 at $DIR/slice_filter.rs:+0:32: +0:33
39+
- StorageLive(_4); // scope 0 at $DIR/slice_filter.rs:+0:32: +0:33
4040
_22 = deref_copy (*_2); // scope 0 at $DIR/slice_filter.rs:+0:32: +0:33
4141
_4 = ((*_22).1: usize); // scope 0 at $DIR/slice_filter.rs:+0:32: +0:33
42-
StorageLive(_5); // scope 0 at $DIR/slice_filter.rs:+0:35: +0:36
42+
- StorageLive(_5); // scope 0 at $DIR/slice_filter.rs:+0:35: +0:36
4343
_23 = deref_copy (*_2); // scope 0 at $DIR/slice_filter.rs:+0:35: +0:36
4444
_5 = ((*_23).2: usize); // scope 0 at $DIR/slice_filter.rs:+0:35: +0:36
45-
StorageLive(_6); // scope 0 at $DIR/slice_filter.rs:+0:38: +0:39
45+
- StorageLive(_6); // scope 0 at $DIR/slice_filter.rs:+0:38: +0:39
4646
_24 = deref_copy (*_2); // scope 0 at $DIR/slice_filter.rs:+0:38: +0:39
4747
_6 = ((*_24).3: usize); // scope 0 at $DIR/slice_filter.rs:+0:38: +0:39
4848
StorageLive(_7); // scope 1 at $DIR/slice_filter.rs:+0:42: +0:58

tests/mir-opt/slice_filter.variant_b-{closure#0}.DestinationPropagation.diff

-4
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,12 @@
2525
}
2626

2727
bb0: {
28-
StorageLive(_3); // scope 0 at $DIR/slice_filter.rs:+0:29: +0:30
2928
_13 = deref_copy (*_2); // scope 0 at $DIR/slice_filter.rs:+0:29: +0:30
3029
_3 = ((*_13).0: usize); // scope 0 at $DIR/slice_filter.rs:+0:29: +0:30
31-
StorageLive(_4); // scope 0 at $DIR/slice_filter.rs:+0:32: +0:33
3230
_14 = deref_copy (*_2); // scope 0 at $DIR/slice_filter.rs:+0:32: +0:33
3331
_4 = ((*_14).1: usize); // scope 0 at $DIR/slice_filter.rs:+0:32: +0:33
34-
StorageLive(_5); // scope 0 at $DIR/slice_filter.rs:+0:35: +0:36
3532
_15 = deref_copy (*_2); // scope 0 at $DIR/slice_filter.rs:+0:35: +0:36
3633
_5 = ((*_15).2: usize); // scope 0 at $DIR/slice_filter.rs:+0:35: +0:36
37-
StorageLive(_6); // scope 0 at $DIR/slice_filter.rs:+0:38: +0:39
3834
_16 = deref_copy (*_2); // scope 0 at $DIR/slice_filter.rs:+0:38: +0:39
3935
_6 = ((*_16).3: usize); // scope 0 at $DIR/slice_filter.rs:+0:38: +0:39
4036
- StorageLive(_7); // scope 1 at $DIR/slice_filter.rs:+0:42: +0:58

tests/mir-opt/try_identity_e2e.new.PreCodegen.after.mir

-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ fn new(_1: Result<T, E>) -> Result<T, E> {
3030
}
3131

3232
bb1: {
33-
StorageLive(_5); // scope 0 at $DIR/try_identity_e2e.rs:+5:21: +5:22
3433
_5 = move ((_1 as Err).0: E); // scope 0 at $DIR/try_identity_e2e.rs:+5:21: +5:22
3534
Deinit(_2); // scope 2 at $DIR/try_identity_e2e.rs:+5:27: +5:48
3635
((_2 as Break).0: E) = move _5; // scope 2 at $DIR/try_identity_e2e.rs:+5:27: +5:48
@@ -40,7 +39,6 @@ fn new(_1: Result<T, E>) -> Result<T, E> {
4039
}
4140

4241
bb2: {
43-
StorageLive(_4); // scope 0 at $DIR/try_identity_e2e.rs:+4:20: +4:21
4442
_4 = move ((_1 as Ok).0: T); // scope 0 at $DIR/try_identity_e2e.rs:+4:20: +4:21
4543
Deinit(_2); // scope 1 at $DIR/try_identity_e2e.rs:+4:26: +4:50
4644
((_2 as Continue).0: T) = move _4; // scope 1 at $DIR/try_identity_e2e.rs:+4:26: +4:50
@@ -50,7 +48,6 @@ fn new(_1: Result<T, E>) -> Result<T, E> {
5048
}
5149

5250
bb3: {
53-
StorageLive(_8); // scope 0 at $DIR/try_identity_e2e.rs:+9:32: +9:33
5451
_8 = move ((_2 as Break).0: E); // scope 0 at $DIR/try_identity_e2e.rs:+9:32: +9:33
5552
Deinit(_0); // scope 4 at $DIR/try_identity_e2e.rs:+9:45: +9:51
5653
((_0 as Err).0: E) = move _8; // scope 4 at $DIR/try_identity_e2e.rs:+9:45: +9:51
@@ -64,7 +61,6 @@ fn new(_1: Result<T, E>) -> Result<T, E> {
6461
}
6562

6663
bb5: {
67-
StorageLive(_7); // scope 0 at $DIR/try_identity_e2e.rs:+8:35: +8:36
6864
_7 = move ((_2 as Continue).0: T); // scope 0 at $DIR/try_identity_e2e.rs:+8:35: +8:36
6965
Deinit(_0); // scope 0 at $DIR/try_identity_e2e.rs:+1:5: +11:6
7066
((_0 as Ok).0: T) = move _7; // scope 0 at $DIR/try_identity_e2e.rs:+1:5: +11:6

tests/mir-opt/try_identity_e2e.old.PreCodegen.after.mir

-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ fn old(_1: Result<T, E>) -> Result<T, E> {
1919
}
2020

2121
bb1: {
22-
StorageLive(_4); // scope 0 at $DIR/try_identity_e2e.rs:+4:17: +4:18
2322
_4 = move ((_1 as Err).0: E); // scope 0 at $DIR/try_identity_e2e.rs:+4:17: +4:18
2423
Deinit(_0); // scope 2 at $DIR/try_identity_e2e.rs:+4:30: +4:36
2524
((_0 as Err).0: E) = move _4; // scope 2 at $DIR/try_identity_e2e.rs:+4:30: +4:36
@@ -32,7 +31,6 @@ fn old(_1: Result<T, E>) -> Result<T, E> {
3231
}
3332

3433
bb3: {
35-
StorageLive(_3); // scope 0 at $DIR/try_identity_e2e.rs:+3:16: +3:17
3634
_3 = move ((_1 as Ok).0: T); // scope 0 at $DIR/try_identity_e2e.rs:+3:16: +3:17
3735
Deinit(_0); // scope 0 at $DIR/try_identity_e2e.rs:+1:5: +6:6
3836
((_0 as Ok).0: T) = move _3; // scope 0 at $DIR/try_identity_e2e.rs:+1:5: +6:6

0 commit comments

Comments
 (0)