Skip to content

Commit cd2784f

Browse files
committed
fixup! mir-opt: Eliminate dead ref statements
Add a test case with the same local. ``` // DBG: _1 = &_2 _1 = &_3 ```
1 parent e9a76fe commit cd2784f

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
- // MIR for `dead_first` before DeadStoreElimination-initial
2+
+ // MIR for `dead_first` after DeadStoreElimination-initial
3+
4+
fn dead_first(_1: &Foo) -> &i32 {
5+
debug v => _1;
6+
let mut _0: &i32;
7+
let mut _2: &i32;
8+
let mut _3: &i32;
9+
let _4: &i32;
10+
scope 1 {
11+
debug a => _2;
12+
}
13+
14+
bb0: {
15+
StorageLive(_2);
16+
- _2 = &((*_1).2: i32);
17+
+ // DBG: _2 = &((*_1).2: i32)
18+
StorageLive(_3);
19+
StorageLive(_4);
20+
_4 = &((*_1).0: i32);
21+
_3 = &(*_4);
22+
_2 = move _3;
23+
StorageDead(_3);
24+
StorageDead(_4);
25+
_0 = &(*_2);
26+
StorageDead(_2);
27+
return;
28+
}
29+
}
30+

tests/mir-opt/dead-store-elimination/ref.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,17 @@ pub fn tuple(v: (i32, &Foo)) -> i32 {
1515
let _dead = &v.1.c;
1616
v.1.a
1717
}
18+
19+
// EMIT_MIR ref.dead_first.DeadStoreElimination-initial.diff
20+
pub fn dead_first(v: &Foo) -> &i32 {
21+
// CHECK-LABEL: fn dead_first
22+
// CHECK: debug a => [[var_a:_[0-9]+]];
23+
// CHECK: bb0:
24+
// CHECK: DBG: [[var_a]] = &((*_1).2: i32)
25+
// CHECK: [[tmp_4:_[0-9]+]] = &((*_1).0: i32)
26+
// CHECK: [[tmp_3:_[0-9]+]] = &(*[[tmp_4]])
27+
// CHECK: [[var_a]] = move [[tmp_3]]
28+
let mut a = &v.c;
29+
a = &v.a;
30+
a
31+
}

0 commit comments

Comments
 (0)