Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2c09f9f

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

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-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; 32];
7+
let mut _4: [i32; 12];
8+
let mut _5: [i32; 12];
9+
let mut _7: &[i32; 32];
10+
let _8: [i32; 32];
11+
let _9: ();
12+
let mut _10: [u16; 32];
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; 32];
21+
scope 2 {
22+
debug _barr => _2;
23+
let _3: [[i32; 12]; 2];
24+
scope 3 {
25+
debug _foo => _3;
26+
let _6: [i32; 32];
27+
let mut _17: &[i32; 32];
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, const 251_i32, const 191_i32, const 178_i32, const 9_i32, const 4_i32, const 56_i32, const 221_i32, const 193_i32, const 164_i32, const 194_i32, const 197_i32, const 6_i32, const 243_i32, const 218_i32, const 171_i32, const 87_i32, const 247_i32, const 104_i32, const 159_i32, const 22_i32, const 157_i32, const 105_i32, const 31_i32, const 96_i32, const 173_i32, const 50_i32, const 1_i32];
43+
StorageLive(_2);
44+
- _2 = [const 255_i32, const 105_i32, const 15_i32, const 39_i32, const 62_i32, const 251_i32, const 191_i32, const 178_i32, const 9_i32, const 4_i32, const 56_i32, const 221_i32, const 193_i32, const 164_i32, const 194_i32, const 197_i32, const 6_i32, const 243_i32, const 218_i32, const 171_i32, const 87_i32, const 247_i32, const 104_i32, const 159_i32, const 22_i32, const 157_i32, const 105_i32, const 31_i32, const 96_i32, const 173_i32, const 50_i32, const 1_i32];
45+
+ _2 = _1;
46+
StorageLive(_3);
47+
StorageLive(_4);
48+
_4 = [const 255_i32, const 105_i32, const 15_i32, const 39_i32, const 62_i32, const 251_i32, const 191_i32, 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, const 243_i32, const 218_i32, const 171_i32, const 87_i32, const 247_i32, const 104_i32, const 42_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 255_u16, const 105_u16, const 15_u16, const 39_u16, const 62_u16, const 251_u16, const 191_u16, const 178_u16, const 9_u16, const 4_u16, const 56_u16, const 221_u16, const 193_u16, const 164_u16, const 194_u16, const 197_u16, const 6_u16, const 243_u16, const 218_u16, const 171_u16, const 87_u16, const 247_u16, const 104_u16, const 159_u16, const 22_u16, const 157_u16, const 105_u16, const 31_u16, const 96_u16, const 173_u16, const 50_u16, const 1_u16];
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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//@ test-mir-pass: GVN
2+
#![feature(repr_simd)]
3+
4+
#[repr(simd)]
5+
struct F32x8([f32; 8]);
6+
7+
// EMIT_MIR const_array_locals.main.GVN.diff
8+
// CHECK-LABEL: fn main(
9+
#[rustfmt::skip]
10+
pub fn main() {
11+
let _arr = [
12+
255, 105, 15, 39, 62, 251, 191, 178, 9, 4, 56, 221,
13+
193, 164, 194, 197, 6, 243, 218, 171, 87, 247, 104,
14+
159, 22, 157, 105, 31, 96, 173, 50, 1,
15+
];
16+
// duplicate item
17+
let _barr = [
18+
255, 105, 15, 39, 62, 251, 191, 178, 9, 4, 56, 221,
19+
193, 164, 194, 197, 6, 243, 218, 171, 87, 247, 104,
20+
159, 22, 157, 105, 31, 96, 173, 50, 1,
21+
];
22+
let _foo = [
23+
[255, 105, 15, 39, 62, 251, 191, 178, 9, 4, 56, 221],
24+
[193, 164, 194, 197, 6, 243, 218, 171, 87, 247, 104, 42],
25+
];
26+
let _darr = *&[
27+
255, 105, 15, 39, 62, 251, 191, 178, 9, 4, 56, 221,
28+
193, 164, 194, 197, 6, 243, 218, 171, 87, 247, 104,
29+
159, 22, 157, 105, 31, 96, 173, 50, 1,
30+
];
31+
32+
consume([255, 105, 15, 39, 62, 251, 191, 178, 9, 4, 56, 221,
33+
193, 164, 194, 197, 6, 243, 218, 171, 87, 247, 104,
34+
159, 22, 157, 105, 31, 96, 173, 50, 1,]);
35+
36+
let _f = F32x8([1.0, 2.0, 3.0, 1.0, 1.0, 1.0, 1.0, 42.0]);
37+
38+
// ice
39+
[[1, 0, 0], [0, 1, 0], [0, 0, 1]]; // 2D array
40+
}
41+
42+
fn consume(_arr: [u16; 32]) {
43+
unimplemented!()
44+
}

0 commit comments

Comments
 (0)