Skip to content

Commit 6956d2c

Browse files
committed
Count drops as moves in MIR SSA opts.
1 parent ed6a743 commit 6956d2c

8 files changed

+57
-31
lines changed

compiler/rustc_mir_transform/src/ssa.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ impl<'tcx> Visitor<'tcx> for SsaVisitor<'_, 'tcx> {
228228
match ctxt {
229229
PlaceContext::MutatingUse(MutatingUseContext::Projection)
230230
| PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection) => bug!(),
231+
// Count drops as moves.
232+
PlaceContext::MutatingUse(MutatingUseContext::Drop) => {
233+
self.check_dominates(local, loc);
234+
self.direct_uses[local] += 1;
235+
}
231236
// Anything can happen with raw pointers, so remove them.
232237
PlaceContext::NonMutatingUse(NonMutatingUseContext::RawBorrow)
233238
| PlaceContext::MutatingUse(_) => {

tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,21 @@
3030
}
3131

3232
bb1: {
33-
StorageLive(_7);
33+
- StorageLive(_7);
34+
+ nop;
3435
_7 = ShallowInitBox(move _6, i32);
3536
_8 = copy ((_7.0: std::ptr::Unique<i32>).0: std::ptr::NonNull<i32>) as *const i32 (Transmute);
3637
(*_8) = const 42_i32;
37-
_3 = move _7;
38-
StorageDead(_7);
39-
_9 = copy ((_3.0: std::ptr::Unique<i32>).0: std::ptr::NonNull<i32>) as *const i32 (Transmute);
40-
_2 = copy (*_9);
38+
- _3 = move _7;
39+
- StorageDead(_7);
40+
- _9 = copy ((_3.0: std::ptr::Unique<i32>).0: std::ptr::NonNull<i32>) as *const i32 (Transmute);
41+
- _2 = copy (*_9);
4142
- _1 = Add(move _2, const 0_i32);
4243
- StorageDead(_2);
44+
+ _3 = copy _7;
45+
+ nop;
46+
+ _9 = copy _8;
47+
+ _2 = copy (*_8);
4348
+ _1 = copy _2;
4449
+ nop;
4550
drop(_3) -> [return: bb2, unwind unreachable];

tests/mir-opt/const_prop/boxes.main.GVN.panic-unwind.diff

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,21 @@
3030
}
3131

3232
bb1: {
33-
StorageLive(_7);
33+
- StorageLive(_7);
34+
+ nop;
3435
_7 = ShallowInitBox(move _6, i32);
3536
_8 = copy ((_7.0: std::ptr::Unique<i32>).0: std::ptr::NonNull<i32>) as *const i32 (Transmute);
3637
(*_8) = const 42_i32;
37-
_3 = move _7;
38-
StorageDead(_7);
39-
_9 = copy ((_3.0: std::ptr::Unique<i32>).0: std::ptr::NonNull<i32>) as *const i32 (Transmute);
40-
_2 = copy (*_9);
38+
- _3 = move _7;
39+
- StorageDead(_7);
40+
- _9 = copy ((_3.0: std::ptr::Unique<i32>).0: std::ptr::NonNull<i32>) as *const i32 (Transmute);
41+
- _2 = copy (*_9);
4142
- _1 = Add(move _2, const 0_i32);
4243
- StorageDead(_2);
44+
+ _3 = copy _7;
45+
+ nop;
46+
+ _9 = copy _8;
47+
+ _2 = copy (*_8);
4348
+ _1 = copy _2;
4449
+ nop;
4550
drop(_3) -> [return: bb2, unwind: bb3];

tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-abort.diff

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
bb0: {
7171
StorageLive(_1);
7272
StorageLive(_2);
73-
StorageLive(_3);
73+
- StorageLive(_3);
74+
+ nop;
7475
StorageLive(_11);
7576
StorageLive(_12);
7677
StorageLive(_13);
@@ -88,7 +89,8 @@
8889
}
8990

9091
bb1: {
91-
StorageDead(_3);
92+
- StorageDead(_3);
93+
+ nop;
9294
StorageDead(_1);
9395
return;
9496
}
@@ -121,8 +123,9 @@
121123
StorageDead(_2);
122124
StorageLive(_4);
123125
- _9 = deref_copy _3;
126+
- _10 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute);
124127
+ _9 = copy _3;
125-
_10 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute);
128+
+ _10 = copy ((_3.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute);
126129
_4 = copy _10;
127130
- StorageLive(_5);
128131
+ nop;
@@ -139,7 +142,7 @@
139142
StorageLive(_8);
140143
_8 = copy _5;
141144
- _7 = copy _8 as *mut () (PtrToPtr);
142-
+ _7 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *mut () (Transmute);
145+
+ _7 = copy ((_3.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *mut () (Transmute);
143146
StorageDead(_8);
144147
StorageDead(_7);
145148
- StorageDead(_5);

tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-unwind.diff

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
bb0: {
3737
StorageLive(_1);
3838
StorageLive(_2);
39-
StorageLive(_3);
39+
- StorageLive(_3);
40+
+ nop;
4041
_3 = Box::<()>::new(const ()) -> [return: bb1, unwind continue];
4142
}
4243

@@ -46,8 +47,9 @@
4647
StorageDead(_2);
4748
StorageLive(_4);
4849
- _9 = deref_copy _3;
50+
- _10 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute);
4951
+ _9 = copy _3;
50-
_10 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute);
52+
+ _10 = copy ((_3.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute);
5153
_4 = copy _10;
5254
- StorageLive(_5);
5355
+ nop;
@@ -64,7 +66,7 @@
6466
StorageLive(_8);
6567
_8 = copy _5;
6668
- _7 = copy _8 as *mut () (PtrToPtr);
67-
+ _7 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *mut () (Transmute);
69+
+ _7 = copy ((_3.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *mut () (Transmute);
6870
StorageDead(_8);
6971
StorageDead(_7);
7072
- StorageDead(_5);
@@ -74,7 +76,8 @@
7476
}
7577

7678
bb2: {
77-
StorageDead(_3);
79+
- StorageDead(_3);
80+
+ nop;
7881
StorageDead(_1);
7982
return;
8083
}

tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-abort.diff

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
bb0: {
7171
StorageLive(_1);
7272
StorageLive(_2);
73-
StorageLive(_3);
73+
- StorageLive(_3);
74+
+ nop;
7475
StorageLive(_11);
7576
StorageLive(_12);
7677
StorageLive(_13);
@@ -88,7 +89,8 @@
8889
}
8990

9091
bb1: {
91-
StorageDead(_3);
92+
- StorageDead(_3);
93+
+ nop;
9294
StorageDead(_1);
9395
return;
9496
}
@@ -121,8 +123,9 @@
121123
StorageDead(_2);
122124
StorageLive(_4);
123125
- _9 = deref_copy _3;
126+
- _10 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute);
124127
+ _9 = copy _3;
125-
_10 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute);
128+
+ _10 = copy ((_3.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute);
126129
_4 = copy _10;
127130
- StorageLive(_5);
128131
+ nop;
@@ -139,7 +142,7 @@
139142
StorageLive(_8);
140143
_8 = copy _5;
141144
- _7 = copy _8 as *mut () (PtrToPtr);
142-
+ _7 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *mut () (Transmute);
145+
+ _7 = copy ((_3.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *mut () (Transmute);
143146
StorageDead(_8);
144147
StorageDead(_7);
145148
- StorageDead(_5);

tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-unwind.diff

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
bb0: {
3737
StorageLive(_1);
3838
StorageLive(_2);
39-
StorageLive(_3);
39+
- StorageLive(_3);
40+
+ nop;
4041
_3 = Box::<()>::new(const ()) -> [return: bb1, unwind continue];
4142
}
4243

@@ -46,8 +47,9 @@
4647
StorageDead(_2);
4748
StorageLive(_4);
4849
- _9 = deref_copy _3;
50+
- _10 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute);
4951
+ _9 = copy _3;
50-
_10 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute);
52+
+ _10 = copy ((_3.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute);
5153
_4 = copy _10;
5254
- StorageLive(_5);
5355
+ nop;
@@ -64,7 +66,7 @@
6466
StorageLive(_8);
6567
_8 = copy _5;
6668
- _7 = copy _8 as *mut () (PtrToPtr);
67-
+ _7 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *mut () (Transmute);
69+
+ _7 = copy ((_3.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *mut () (Transmute);
6870
StorageDead(_8);
6971
StorageDead(_7);
7072
- StorageDead(_5);
@@ -74,7 +76,8 @@
7476
}
7577

7678
bb2: {
77-
StorageDead(_3);
79+
- StorageDead(_3);
80+
+ nop;
7881
StorageDead(_1);
7982
return;
8083
}

tests/mir-opt/inline/inline_diverging.h.Inline.panic-unwind.diff

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
let mut _0: ();
66
let _1: (!, !);
77
+ let mut _2: fn() -> ! {sleep};
8+
+ let mut _7: ();
89
+ let mut _8: ();
9-
+ let mut _9: ();
1010
+ scope 1 (inlined call_twice::<!, fn() -> ! {sleep}>) {
1111
+ debug f => _2;
1212
+ let mut _3: &fn() -> ! {sleep};
1313
+ let _4: !;
1414
+ let mut _5: &fn() -> ! {sleep};
15-
+ let mut _7: !;
1615
+ scope 2 {
1716
+ debug a => _4;
1817
+ let _6: !;
@@ -35,12 +34,12 @@
3534
- _1 = call_twice::<!, fn() -> ! {sleep}>(sleep) -> unwind continue;
3635
+ StorageLive(_2);
3736
+ _2 = sleep;
38-
+ StorageLive(_6);
3937
+ StorageLive(_4);
38+
+ StorageLive(_6);
4039
+ StorageLive(_3);
4140
+ _3 = &_2;
42-
+ StorageLive(_8);
43-
+ _8 = const ();
41+
+ StorageLive(_7);
42+
+ _7 = const ();
4443
+ goto -> bb1;
4544
+ }
4645
+

0 commit comments

Comments
 (0)