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

Lines changed: 14 additions & 11 deletions
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 1 deletion
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

0 commit comments

Comments
 (0)