Skip to content

Commit 0bfa706

Browse files
committed
Added a storage usage inverse order test
1 parent 8b5a70c commit 0bfa706

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
- // MIR for `g` before CopyProp
2+
+ // MIR for `g` after CopyProp
3+
4+
fn g() -> usize {
5+
let mut _0: usize;
6+
let mut _1: usize;
7+
let mut _2: usize;
8+
let mut _3: usize;
9+
10+
bb0: {
11+
- StorageLive(_2);
12+
StorageLive(_1);
13+
_1 = const 0_usize;
14+
- _2 = copy _1;
15+
- _3 = copy _2;
16+
- _0 = Add(copy _3, copy _3);
17+
+ _0 = Add(copy _1, copy _1);
18+
StorageDead(_1);
19+
- StorageDead(_2);
20+
return;
21+
}
22+
}
23+

tests/mir-opt/copy-prop/copy_prop_storage_preserve_head.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use std::intrinsics::mir::*;
66

77
// EMIT_MIR copy_prop_storage_preserve_head.f.CopyProp.diff
8+
// EMIT_MIR copy_prop_storage_preserve_head.g.CopyProp.diff
89

910
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
1011
pub fn f(_1: &mut usize) {
@@ -27,3 +28,29 @@ pub fn f(_1: &mut usize) {
2728
}
2829
}
2930
}
31+
32+
#[custom_mir(dialect = "runtime")]
33+
pub fn g() -> usize {
34+
// CHECK-LABEL: fn g(
35+
mir! {
36+
let _1: usize;
37+
let _2: usize;
38+
let _3: usize;
39+
// CHECK: bb0: {
40+
{
41+
// CHECK: StorageLive(_1);
42+
// CHECK: _0 = Add(copy _1, copy _1);
43+
// CHECK: StorageDead(_1);
44+
StorageLive(_2);
45+
StorageLive(_1);
46+
_1 = 0;
47+
_2 = _1;
48+
_3 = _2;
49+
RET = _3 + _3;
50+
// Even though the storage statements are in reverse order, we should be able to keep the ones for _1.
51+
StorageDead(_1);
52+
StorageDead(_2);
53+
Return()
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)