Skip to content

Commit 023838f

Browse files
committed
add regression tests for gvn of local arrays
1 parent 336e89b commit 023838f

File tree

2 files changed

+143
-0
lines changed

2 files changed

+143
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
- // MIR for `main` before GVN
2+
+ // MIR for `main` after GVN
3+
4+
fn main() -> () {
5+
let mut _0: ();
6+
let _1: [i32; 5];
7+
let mut _4: [i32; 5];
8+
let mut _5: [i32; 5];
9+
let mut _7: &[i32; 5];
10+
let _8: [i32; 5];
11+
let _9: ();
12+
let mut _10: [u32; 5];
13+
let mut _12: [f32; 8];
14+
let _13: [[i32; 3]; 3];
15+
let mut _14: [i32; 3];
16+
let mut _15: [i32; 3];
17+
let mut _16: [i32; 3];
18+
scope 1 {
19+
debug _arr => _1;
20+
let _2: [i32; 5];
21+
scope 2 {
22+
debug _duplicated_arr => _2;
23+
let _3: [[i32; 5]; 2];
24+
scope 3 {
25+
debug _foo => _3;
26+
let _6: [i32; 5];
27+
let mut _17: &[i32; 5];
28+
scope 4 {
29+
debug _darr => _6;
30+
let _11: F32x8;
31+
scope 5 {
32+
debug _f => _11;
33+
}
34+
}
35+
}
36+
}
37+
}
38+
39+
bb0: {
40+
- StorageLive(_1);
41+
+ nop;
42+
_1 = [const 255_i32, const 105_i32, const 15_i32, const 39_i32, const 62_i32];
43+
StorageLive(_2);
44+
- _2 = [const 255_i32, const 105_i32, const 15_i32, const 39_i32, const 62_i32];
45+
+ _2 = _1;
46+
StorageLive(_3);
47+
StorageLive(_4);
48+
_4 = [const 178_i32, const 9_i32, const 4_i32, const 56_i32, const 221_i32];
49+
StorageLive(_5);
50+
_5 = [const 193_i32, const 164_i32, const 194_i32, const 197_i32, const 6_i32];
51+
_3 = [move _4, move _5];
52+
StorageDead(_5);
53+
StorageDead(_4);
54+
StorageLive(_6);
55+
StorageLive(_7);
56+
_17 = const main::promoted[0];
57+
_7 = &(*_17);
58+
- _6 = (*_7);
59+
+ _6 = (*_17);
60+
StorageDead(_7);
61+
StorageLive(_9);
62+
StorageLive(_10);
63+
_10 = [const 31_u32, const 96_u32, const 173_u32, const 50_u32, const 1_u32];
64+
_9 = consume(move _10) -> [return: bb1, unwind continue];
65+
}
66+
67+
bb1: {
68+
StorageDead(_10);
69+
StorageDead(_9);
70+
StorageLive(_11);
71+
StorageLive(_12);
72+
_12 = [const 1f32, const 2f32, const 3f32, const 1f32, const 1f32, const 1f32, const 1f32, const 42f32];
73+
_11 = F32x8(move _12);
74+
StorageDead(_12);
75+
StorageLive(_13);
76+
StorageLive(_14);
77+
_14 = [const 1_i32, const 0_i32, const 0_i32];
78+
StorageLive(_15);
79+
_15 = [const 0_i32, const 1_i32, const 0_i32];
80+
StorageLive(_16);
81+
_16 = [const 0_i32, const 0_i32, const 1_i32];
82+
_13 = [move _14, move _15, move _16];
83+
StorageDead(_16);
84+
StorageDead(_15);
85+
StorageDead(_14);
86+
StorageDead(_13);
87+
_0 = const ();
88+
StorageDead(_11);
89+
StorageDead(_6);
90+
StorageDead(_3);
91+
StorageDead(_2);
92+
- StorageDead(_1);
93+
+ nop;
94+
return;
95+
}
96+
}
97+

tests/mir-opt/const_array_locals.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//@ test-mir-pass: GVN
2+
//@ compile-flags: -Zdump-mir-exclude-alloc-bytes
3+
#![feature(repr_simd)]
4+
5+
#[repr(simd)]
6+
struct F32x8([f32; 8]);
7+
8+
// EMIT_MIR const_array_locals.main.GVN.diff
9+
// CHECK-LABEL: fn main(
10+
// CHECK: debug _arr => [[_arr:_[0-9]+]];
11+
// CHECK: debug _duplicated_arr => [[_duplicated_arr:_[0-9]+]];
12+
// CHECK: debug _foo => [[_foo:_[0-9]+]];
13+
// CHECK: debug _darr => [[_darr:_[0-9]+]];
14+
// CHECK: debug _f => [[_f:_[0-9]+]];
15+
pub fn main() {
16+
// CHECK: [[_arr]] = const [255_i32, 105_i32, 15_i32, 39_i32, 62_i32];
17+
let _arr = [255, 105, 15, 39, 62];
18+
// CHECK: [[_duplicated_arr]] = const [255_i32, 105_i32, 15_i32, 39_i32, 62_i32];
19+
let _duplicated_arr = [255, 105, 15, 39, 62];
20+
// CHECK: [[subarray1:_[0-9]+]] = const [178_i32, 9_i32, 4_i32, 56_i32, 221_i32];
21+
// CHECK: [[subarray2:_[0-9]+]] = const [193_i32, 164_i32, 194_i32, 197_i32, 6_i32];
22+
// CHECK{LITERAL}: const [[178_i32, 9_i32, 4_i32, 56_i32, 221_i32], [193_i32, 164_i32, 194_i32, 197_i32, 6_i32]];
23+
let _foo = [[178, 9, 4, 56, 221], [193, 164, 194, 197, 6]];
24+
// CHECK: [[PROMOTED:_[0-9]+]] = const main::promoted[0];
25+
// CHECK: [[_darr]] = const [254_i32, 42_i32, 15_i32, 39_i32, 62_i32];
26+
let _darr = *&[254, 42, 15, 39, 62];
27+
28+
// CHECK: [[ARG:_[0-9]+]] = const [31_u32, 96_u32, 173_u32, 50_u32, 1_u32];
29+
// CHECK: consume(const [31_u32, 96_u32, 173_u32, 50_u32, 1_u32])
30+
consume([31, 96, 173, 50, 1]);
31+
32+
// CHECK: [[OP:_[0-9]+]] = const [1f32, 2f32, 3f32, 1f32, 1f32, 1f32, 1f32, 42f32];
33+
// CHECK: [[_f]] = F32x8(const [1f32, 2f32, 3f32, 1f32, 1f32, 1f32, 1f32, 42f32]);
34+
let _f = F32x8([1.0, 2.0, 3.0, 1.0, 1.0, 1.0, 1.0, 42.0]);
35+
36+
// ice with small arrays
37+
// CHECK: [[A:_[0-9]+]] = const [1_i32, 0_i32, 0_i32];
38+
// CHECK: [[B:_[0-9]+]] = const [0_i32, 1_i32, 0_i32];
39+
// CHECK: [[C:_[0-9]+]] = const [0_i32, 0_i32, 1_i32];
40+
// CHECK{LITERAL}: const [[1_i32, 0_i32, 0_i32], [0_i32, 1_i32, 0_i32], [0_i32, 0_i32, 1_i32]];
41+
[[1, 0, 0], [0, 1, 0], [0, 0, 1]]; // 2D array
42+
}
43+
44+
fn consume(_arr: [u32; 5]) {
45+
unimplemented!()
46+
}

0 commit comments

Comments
 (0)