rust/tests/mir-opt/dataflow-const-prop/struct.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

80 lines
2.5 KiB
Rust
Raw Normal View History

//@ test-mir-pass: DataflowConstProp
2023-09-09 11:47:17 -05:00
// EMIT_MIR_FOR_EACH_BIT_WIDTH
2023-05-13 09:19:31 -05:00
#[derive(Copy, Clone)]
struct S(i32);
2023-05-13 09:19:31 -05:00
#[derive(Copy, Clone)]
2023-09-17 04:35:06 -05:00
struct SmallStruct(f32, Option<S>, &'static [f32]);
#[derive(Copy, Clone)]
struct BigStruct(f32, Option<S>, &'static [f32]);
2023-05-13 07:30:40 -05:00
// EMIT_MIR struct.main.DataflowConstProp.diff
2024-01-08 22:21:06 -06:00
2024-01-12 01:22:33 -06:00
// CHECK-LABEL: fn main(
fn main() {
2024-01-12 01:22:33 -06:00
// CHECK: debug s => [[s:_.*]];
// CHECK: debug a => [[a:_.*]];
// CHECK: debug b => [[b:_.*]];
// CHECK: debug a1 => [[a1:_.*]];
// CHECK: debug b1 => [[b1:_.*]];
// CHECK: debug c1 => [[c1:_.*]];
// CHECK: debug a2 => [[a2:_.*]];
// CHECK: debug b2 => [[b2:_.*]];
// CHECK: debug c2 => [[c2:_.*]];
// CHECK: debug ss => [[ss:_.*]];
// CHECK: debug a3 => [[a3:_.*]];
// CHECK: debug b3 => [[b3:_.*]];
// CHECK: debug c3 => [[c3:_.*]];
// CHECK: debug a4 => [[a4:_.*]];
// CHECK: debug b4 => [[b4:_.*]];
// CHECK: debug c4 => [[c4:_.*]];
// CHECK: debug bs => [[bs:_.*]];
2024-01-08 22:21:06 -06:00
// CHECK: [[s]] = const S(1_i32);
let mut s = S(1);
2024-01-08 22:21:06 -06:00
// CHECK: [[a]] = const 3_i32;
let a = s.0 + 2;
s.0 = 3;
2024-01-08 22:21:06 -06:00
// CHECK: [[b]] = const 6_i32;
let b = a + s.0;
2023-05-13 07:30:40 -05:00
2023-09-17 04:35:06 -05:00
const SMALL_VAL: SmallStruct = SmallStruct(4., Some(S(1)), &[]);
2024-01-08 22:21:06 -06:00
// CHECK: [[a1]] = const 4f32;
// CHECK: [[b1]] = const Option::<S>::Some(S(1_i32));
2024-01-12 01:22:33 -06:00
// CHECK: [[c1]] = ({{_.*}}.2: &[f32]);
2024-01-08 22:21:06 -06:00
let SmallStruct(a1, b1, c1) = SMALL_VAL;
2023-09-17 04:35:06 -05:00
static SMALL_STAT: &SmallStruct = &SmallStruct(9., None, &[13.]);
2024-01-08 22:21:06 -06:00
// CHECK: [[a2]] = const 9f32;
2024-01-12 01:22:33 -06:00
// CHECK: [[b2]] = ((*{{_.*}}).1: std::option::Option<S>);
// CHECK: [[c2]] = ((*{{_.*}}).2: &[f32]);
2024-01-08 22:21:06 -06:00
let SmallStruct(a2, b2, c2) = *SMALL_STAT;
2024-01-12 01:22:33 -06:00
// CHECK: [[ss]] = SmallStruct(const 9f32, move {{_.*}}, move {{_.*}});
2024-01-08 22:21:06 -06:00
let ss = SmallStruct(a2, b2, c2);
2023-09-17 04:35:06 -05:00
const BIG_VAL: BigStruct = BigStruct(25., None, &[]);
2024-01-08 22:21:06 -06:00
// CHECK: [[a3]] = const 25f32;
2024-01-12 01:22:33 -06:00
// CHECK: [[b3]] = ({{_.*}}.1: std::option::Option<S>);
// CHECK: [[c3]] = ({{_.*}}.2: &[f32]);
2024-01-08 22:21:06 -06:00
let BigStruct(a3, b3, c3) = BIG_VAL;
2023-05-13 09:19:31 -05:00
2023-09-17 04:35:06 -05:00
static BIG_STAT: &BigStruct = &BigStruct(82., Some(S(35)), &[45., 72.]);
2024-01-08 22:21:06 -06:00
// CHECK: [[a4]] = const 82f32;
// CHECK: [[b4]] = const Option::<S>::Some(S(35_i32));
2024-01-12 01:22:33 -06:00
// CHECK: [[c4]] = ((*{{_.*}}).2: &[f32]);
2024-01-08 22:21:06 -06:00
let BigStruct(a4, b4, c4) = *BIG_STAT;
2023-09-17 04:35:06 -05:00
// We arbitrarily limit the size of synthetized values to 4 pointers.
// `BigStruct` can be read, but we will keep a MIR aggregate for this.
2024-01-12 01:22:33 -06:00
// CHECK: [[bs]] = BigStruct(const 82f32, const Option::<S>::Some(S(35_i32)), move {{_.*}});
2024-01-08 22:21:06 -06:00
let bs = BigStruct(a4, b4, c4);
}