Skip to content

Commit 80fce82

Browse files
committed
Improve GVN storage tests
1 parent ce2e9b6 commit 80fce82

8 files changed

+111
-276
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
- // MIR for `f` before GVN
2+
+ // MIR for `f` after GVN
3+
4+
fn f(_1: u32) -> () {
5+
let mut _0: ();
6+
let mut _2: S;
7+
let mut _3: S;
8+
9+
bb0: {
10+
StorageLive(_2);
11+
_2 = S(copy _1, const 2_u32);
12+
StorageLive(_3);
13+
- _3 = S(copy _1, const 2_u32);
14+
+ _3 = copy _2;
15+
StorageDead(_3);
16+
StorageDead(_2);
17+
return;
18+
}
19+
}
20+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//! Check that we do not remove storage statements when possible.
2+
//@ test-mir-pass: GVN
3+
// EMIT_MIR gvn_storage_issue_141649.f.GVN.diff
4+
5+
#![feature(custom_mir, core_intrinsics)]
6+
7+
use std::intrinsics::mir::*;
8+
9+
struct S(u32, u32);
10+
11+
#[custom_mir(dialect = "runtime")]
12+
pub fn f(_1: u32) {
13+
// CHECK-LABEL: fn f(
14+
mir! {
15+
let _2: S;
16+
let _3: S;
17+
{
18+
// CHECK: StorageLive(_2);
19+
// CHECK: StorageLive(_3);
20+
// CHECK: _3 = copy _2;
21+
// CHECK: StorageDead(_3);
22+
// CHECK: StorageDead(_2);
23+
StorageLive(_2);
24+
_2 = S(_1, 2);
25+
StorageLive(_3);
26+
_3 = S(_1, 2);
27+
StorageDead(_3);
28+
StorageDead(_2);
29+
Return()
30+
}
31+
}
32+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
- // MIR for `f` before GVN
2+
+ // MIR for `f` after GVN
3+
4+
fn f(_1: u32) -> () {
5+
let mut _0: ();
6+
let mut _2: S;
7+
let mut _3: S;
8+
9+
bb0: {
10+
- StorageLive(_2);
11+
+ nop;
12+
_2 = S(copy _1, const 2_u32);
13+
StorageLive(_3);
14+
- _3 = S(copy _1, const 2_u32);
15+
+ _3 = copy _2;
16+
StorageDead(_3);
17+
- StorageDead(_2);
18+
+ nop;
19+
return;
20+
}
21+
}
22+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//! In lower opt levels, we remove any storage statements of reused locals.
2+
//@ test-mir-pass: GVN
3+
//@ compile-flags: -Copt-level=0
4+
// EMIT_MIR gvn_storage_issue_141649_debug.f.GVN.diff
5+
6+
#![feature(custom_mir, core_intrinsics)]
7+
8+
use std::intrinsics::mir::*;
9+
10+
struct S(u32, u32);
11+
12+
#[custom_mir(dialect = "runtime")]
13+
pub fn f(_1: u32) {
14+
// CHECK-LABEL: fn f(
15+
mir! {
16+
let _2: S;
17+
let _3: S;
18+
{
19+
// CHECK-NOT: StorageLive(_2);
20+
// CHECK: _3 = copy _2;
21+
// CHECK-NOT: StorageDead(_2);
22+
StorageLive(_2);
23+
_2 = S(_1, 2);
24+
StorageLive(_3);
25+
_3 = S(_1, 2);
26+
StorageDead(_3);
27+
StorageDead(_2);
28+
Return()
29+
}
30+
}
31+
}

tests/mir-opt/gvn_storage_twice.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
//@ test-mir-pass: GVN
32
//@ compile-flags: -Zlint-mir=false
43

@@ -18,10 +17,12 @@ use std::intrinsics::mir::*;
1817

1918
#[custom_mir(dialect = "runtime")]
2019
pub fn repeat_local(_1: usize, _2: usize, _3: i32) -> i32 {
20+
// CHECK-LABEL: fn repeat_local(
2121
mir! {
2222
{
2323
let _4 = [_3; 5];
2424
let _5 = &_4[_1];
25+
// CHECK: _0 = copy _3;
2526
RET = *_5;
2627
Return()
2728
}
@@ -32,11 +33,13 @@ pub fn repeat_local(_1: usize, _2: usize, _3: i32) -> i32 {
3233

3334
#[custom_mir(dialect = "runtime")]
3435
pub fn repeat_local_dead(_1: usize, _2: usize, _3: i32) -> i32 {
36+
// CHECK-LABEL: fn repeat_local_dead(
3537
mir! {
3638
{
3739
let _4 = [_3; 5];
3840
let _5 = &_4[_1];
3941
StorageDead(_3);
42+
// CHECK: _0 = copy _3;
4043
RET = *_5;
4144
Return()
4245
}
@@ -47,12 +50,14 @@ pub fn repeat_local_dead(_1: usize, _2: usize, _3: i32) -> i32 {
4750

4851
#[custom_mir(dialect = "runtime")]
4952
pub fn repeat_local_dead_live(_1: usize, _2: usize, _3: i32) -> i32 {
53+
// CHECK-LABEL: fn repeat_local_dead_live(
5054
mir! {
5155
{
5256
let _4 = [_3; 5];
5357
let _5 = &_4[_1];
5458
StorageDead(_3);
5559
StorageLive(_3);
60+
// CHECK: _0 = copy _3;
5661
RET = *_5;
5762
Return()
5863
}

tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-abort.diff

Lines changed: 0 additions & 124 deletions
This file was deleted.

0 commit comments

Comments
 (0)