diff options
Diffstat (limited to 'tests')
19 files changed, 856 insertions, 63 deletions
diff --git a/tests/mir-opt/dataflow-const-prop/enum.constant.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/enum.constant.DataflowConstProp.32bit.diff new file mode 100644 index 00000000000..07ac5b72e24 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/enum.constant.DataflowConstProp.32bit.diff @@ -0,0 +1,63 @@ +- // MIR for `constant` before DataflowConstProp ++ // MIR for `constant` after DataflowConstProp + + fn constant() -> () { + let mut _0: (); + let _1: E; + let mut _3: isize; + scope 1 { + debug e => _1; + let _2: i32; + let _4: i32; + let _5: i32; + scope 2 { + debug x => _2; + } + scope 3 { + debug x => _4; + } + scope 4 { + debug x => _5; + } + } + + bb0: { + StorageLive(_1); + _1 = const _; + StorageLive(_2); +- _3 = discriminant(_1); +- switchInt(move _3) -> [0: bb3, 1: bb1, otherwise: bb2]; ++ _3 = const 0_isize; ++ switchInt(const 0_isize) -> [0: bb3, 1: bb1, otherwise: bb2]; + } + + bb1: { + StorageLive(_5); + _5 = ((_1 as V2).0: i32); + _2 = _5; + StorageDead(_5); + goto -> bb4; + } + + bb2: { + unreachable; + } + + bb3: { + StorageLive(_4); +- _4 = ((_1 as V1).0: i32); +- _2 = _4; ++ _4 = const 0_i32; ++ _2 = const 0_i32; + StorageDead(_4); + goto -> bb4; + } + + bb4: { + _0 = const (); + StorageDead(_2); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/enum.constant.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/enum.constant.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..07ac5b72e24 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/enum.constant.DataflowConstProp.64bit.diff @@ -0,0 +1,63 @@ +- // MIR for `constant` before DataflowConstProp ++ // MIR for `constant` after DataflowConstProp + + fn constant() -> () { + let mut _0: (); + let _1: E; + let mut _3: isize; + scope 1 { + debug e => _1; + let _2: i32; + let _4: i32; + let _5: i32; + scope 2 { + debug x => _2; + } + scope 3 { + debug x => _4; + } + scope 4 { + debug x => _5; + } + } + + bb0: { + StorageLive(_1); + _1 = const _; + StorageLive(_2); +- _3 = discriminant(_1); +- switchInt(move _3) -> [0: bb3, 1: bb1, otherwise: bb2]; ++ _3 = const 0_isize; ++ switchInt(const 0_isize) -> [0: bb3, 1: bb1, otherwise: bb2]; + } + + bb1: { + StorageLive(_5); + _5 = ((_1 as V2).0: i32); + _2 = _5; + StorageDead(_5); + goto -> bb4; + } + + bb2: { + unreachable; + } + + bb3: { + StorageLive(_4); +- _4 = ((_1 as V1).0: i32); +- _2 = _4; ++ _4 = const 0_i32; ++ _2 = const 0_i32; + StorageDead(_4); + goto -> bb4; + } + + bb4: { + _0 = const (); + StorageDead(_2); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.32bit.diff index 775325c4d06..775325c4d06 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.diff +++ b/tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.32bit.diff diff --git a/tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..775325c4d06 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.64bit.diff @@ -0,0 +1,82 @@ +- // MIR for `multiple` before DataflowConstProp ++ // MIR for `multiple` after DataflowConstProp + + fn multiple(_1: bool, _2: u8) -> () { + debug x => _1; + debug i => _2; + let mut _0: (); + let _3: std::option::Option<u8>; + let mut _4: bool; + let mut _5: u8; + let mut _7: isize; + scope 1 { + debug e => _3; + let _6: u8; + let _8: u8; + scope 2 { + debug x => _6; + let _9: u8; + scope 4 { + debug y => _9; + } + } + scope 3 { + debug i => _8; + } + } + + bb0: { + StorageLive(_3); + StorageLive(_4); + _4 = _1; + switchInt(move _4) -> [0: bb2, otherwise: bb1]; + } + + bb1: { + StorageLive(_5); + _5 = _2; + _3 = Option::<u8>::Some(move _5); + StorageDead(_5); + goto -> bb3; + } + + bb2: { + _3 = Option::<u8>::None; + goto -> bb3; + } + + bb3: { + StorageDead(_4); + StorageLive(_6); + _7 = discriminant(_3); + switchInt(move _7) -> [0: bb4, 1: bb6, otherwise: bb5]; + } + + bb4: { + _6 = const 0_u8; + goto -> bb7; + } + + bb5: { + unreachable; + } + + bb6: { + StorageLive(_8); + _8 = ((_3 as Some).0: u8); + _6 = _8; + StorageDead(_8); + goto -> bb7; + } + + bb7: { + StorageLive(_9); + _9 = _6; + _0 = const (); + StorageDead(_9); + StorageDead(_6); + StorageDead(_3); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.32bit.diff index 960e69ee916..960e69ee916 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.diff +++ b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.32bit.diff diff --git a/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..960e69ee916 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.64bit.diff @@ -0,0 +1,26 @@ +- // MIR for `mutate_discriminant` before DataflowConstProp ++ // MIR for `mutate_discriminant` after DataflowConstProp + + fn mutate_discriminant() -> u8 { + let mut _0: u8; + let mut _1: std::option::Option<NonZeroUsize>; + let mut _2: isize; + + bb0: { + discriminant(_1) = 1; + (((_1 as variant#1).0: NonZeroUsize).0: usize) = const 0_usize; + _2 = discriminant(_1); + switchInt(_2) -> [0: bb1, otherwise: bb2]; + } + + bb1: { + _0 = const 1_u8; + return; + } + + bb2: { + _0 = const 2_u8; + unreachable; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/enum.rs b/tests/mir-opt/dataflow-const-prop/enum.rs index 79a20d7ef45..5a10e9e883d 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.rs +++ b/tests/mir-opt/dataflow-const-prop/enum.rs @@ -1,9 +1,11 @@ // unit-test: DataflowConstProp +// EMIT_MIR_FOR_EACH_BIT_WIDTH #![feature(custom_mir, core_intrinsics, rustc_attrs)] use std::intrinsics::mir::*; +#[derive(Copy, Clone)] enum E { V1(i32), V2(i32) @@ -15,6 +17,24 @@ fn simple() { let x = match e { E::V1(x) => x, E::V2(x) => x }; } +// EMIT_MIR enum.constant.DataflowConstProp.diff +fn constant() { + const C: E = E::V1(0); + let e = C; + let x = match e { E::V1(x) => x, E::V2(x) => x }; +} + +// EMIT_MIR enum.statics.DataflowConstProp.diff +fn statics() { + static C: E = E::V1(0); + let e = C; + let x = match e { E::V1(x) => x, E::V2(x) => x }; + + static RC: &E = &E::V2(4); + let e = RC; + let x = match e { E::V1(x) => x, E::V2(x) => x }; +} + #[rustc_layout_scalar_valid_range_start(1)] #[rustc_nonnull_optimization_guaranteed] struct NonZeroUsize(usize); @@ -63,6 +83,8 @@ fn multiple(x: bool, i: u8) { fn main() { simple(); + constant(); + statics(); mutate_discriminant(); multiple(false, 5); } diff --git a/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.32bit.diff index 3946e7c7d96..3946e7c7d96 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.diff +++ b/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.32bit.diff diff --git a/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..3946e7c7d96 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.64bit.diff @@ -0,0 +1,63 @@ +- // MIR for `simple` before DataflowConstProp ++ // MIR for `simple` after DataflowConstProp + + fn simple() -> () { + let mut _0: (); + let _1: E; + let mut _3: isize; + scope 1 { + debug e => _1; + let _2: i32; + let _4: i32; + let _5: i32; + scope 2 { + debug x => _2; + } + scope 3 { + debug x => _4; + } + scope 4 { + debug x => _5; + } + } + + bb0: { + StorageLive(_1); + _1 = E::V1(const 0_i32); + StorageLive(_2); +- _3 = discriminant(_1); +- switchInt(move _3) -> [0: bb3, 1: bb1, otherwise: bb2]; ++ _3 = const 0_isize; ++ switchInt(const 0_isize) -> [0: bb3, 1: bb1, otherwise: bb2]; + } + + bb1: { + StorageLive(_5); + _5 = ((_1 as V2).0: i32); + _2 = _5; + StorageDead(_5); + goto -> bb4; + } + + bb2: { + unreachable; + } + + bb3: { + StorageLive(_4); +- _4 = ((_1 as V1).0: i32); +- _2 = _4; ++ _4 = const 0_i32; ++ _2 = const 0_i32; + StorageDead(_4); + goto -> bb4; + } + + bb4: { + _0 = const (); + StorageDead(_2); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.32bit.diff new file mode 100644 index 00000000000..ae8b44c953e --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.32bit.diff @@ -0,0 +1,126 @@ +- // MIR for `statics` before DataflowConstProp ++ // MIR for `statics` after DataflowConstProp + + fn statics() -> () { + let mut _0: (); + let _1: E; + let mut _2: &E; + let mut _4: isize; + let mut _8: &&E; + let mut _10: isize; + scope 1 { + debug e => _1; + let _3: i32; + let _5: i32; + let _6: i32; + scope 2 { + debug x => _3; + let _7: &E; + scope 5 { + debug e => _7; + let _9: &i32; + let _11: &i32; + let _12: &i32; + scope 6 { + debug x => _9; + } + scope 7 { + debug x => _11; + } + scope 8 { + debug x => _12; + } + } + } + scope 3 { + debug x => _5; + } + scope 4 { + debug x => _6; + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = const {alloc1: &E}; + _1 = (*_2); + StorageDead(_2); + StorageLive(_3); +- _4 = discriminant(_1); +- switchInt(move _4) -> [0: bb3, 1: bb1, otherwise: bb2]; ++ _4 = const 0_isize; ++ switchInt(const 0_isize) -> [0: bb3, 1: bb1, otherwise: bb2]; + } + + bb1: { + StorageLive(_6); + _6 = ((_1 as V2).0: i32); + _3 = _6; + StorageDead(_6); + goto -> bb4; + } + + bb2: { + unreachable; + } + + bb3: { + StorageLive(_5); +- _5 = ((_1 as V1).0: i32); +- _3 = _5; ++ _5 = const 0_i32; ++ _3 = const 0_i32; + StorageDead(_5); + goto -> bb4; + } + + bb4: { + StorageLive(_7); + StorageLive(_8); + _8 = const {alloc2: &&E}; + _7 = (*_8); + StorageDead(_8); + StorageLive(_9); + _10 = discriminant((*_7)); + switchInt(move _10) -> [0: bb6, 1: bb5, otherwise: bb2]; + } + + bb5: { + StorageLive(_12); + _12 = &(((*_7) as V2).0: i32); + _9 = &(*_12); + StorageDead(_12); + goto -> bb7; + } + + bb6: { + StorageLive(_11); + _11 = &(((*_7) as V1).0: i32); + _9 = _11; + StorageDead(_11); + goto -> bb7; + } + + bb7: { + _0 = const (); + StorageDead(_9); + StorageDead(_7); + StorageDead(_3); + StorageDead(_1); + return; + } + } + + alloc2 (static: RC, size: 4, align: 4) { + ╾─alloc14─╼ │ ╾──╼ + } + + alloc14 (size: 8, align: 4) { + 01 00 00 00 04 00 00 00 │ ........ + } + + alloc1 (static: statics::C, size: 8, align: 4) { + 00 00 00 00 00 00 00 00 │ ........ + } + diff --git a/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..63799b3bac3 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.64bit.diff @@ -0,0 +1,126 @@ +- // MIR for `statics` before DataflowConstProp ++ // MIR for `statics` after DataflowConstProp + + fn statics() -> () { + let mut _0: (); + let _1: E; + let mut _2: &E; + let mut _4: isize; + let mut _8: &&E; + let mut _10: isize; + scope 1 { + debug e => _1; + let _3: i32; + let _5: i32; + let _6: i32; + scope 2 { + debug x => _3; + let _7: &E; + scope 5 { + debug e => _7; + let _9: &i32; + let _11: &i32; + let _12: &i32; + scope 6 { + debug x => _9; + } + scope 7 { + debug x => _11; + } + scope 8 { + debug x => _12; + } + } + } + scope 3 { + debug x => _5; + } + scope 4 { + debug x => _6; + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = const {alloc1: &E}; + _1 = (*_2); + StorageDead(_2); + StorageLive(_3); +- _4 = discriminant(_1); +- switchInt(move _4) -> [0: bb3, 1: bb1, otherwise: bb2]; ++ _4 = const 0_isize; ++ switchInt(const 0_isize) -> [0: bb3, 1: bb1, otherwise: bb2]; + } + + bb1: { + StorageLive(_6); + _6 = ((_1 as V2).0: i32); + _3 = _6; + StorageDead(_6); + goto -> bb4; + } + + bb2: { + unreachable; + } + + bb3: { + StorageLive(_5); +- _5 = ((_1 as V1).0: i32); +- _3 = _5; ++ _5 = const 0_i32; ++ _3 = const 0_i32; + StorageDead(_5); + goto -> bb4; + } + + bb4: { + StorageLive(_7); + StorageLive(_8); + _8 = const {alloc2: &&E}; + _7 = (*_8); + StorageDead(_8); + StorageLive(_9); + _10 = discriminant((*_7)); + switchInt(move _10) -> [0: bb6, 1: bb5, otherwise: bb2]; + } + + bb5: { + StorageLive(_12); + _12 = &(((*_7) as V2).0: i32); + _9 = &(*_12); + StorageDead(_12); + goto -> bb7; + } + + bb6: { + StorageLive(_11); + _11 = &(((*_7) as V1).0: i32); + _9 = _11; + StorageDead(_11); + goto -> bb7; + } + + bb7: { + _0 = const (); + StorageDead(_9); + StorageDead(_7); + StorageDead(_3); + StorageDead(_1); + return; + } + } + + alloc2 (static: RC, size: 8, align: 8) { + ╾───────alloc14───────╼ │ ╾──────╼ + } + + alloc14 (size: 8, align: 4) { + 01 00 00 00 04 00 00 00 │ ........ + } + + alloc1 (static: statics::C, size: 8, align: 4) { + 00 00 00 00 00 00 00 00 │ ........ + } + diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-abort.diff index be55d259dcf..e99b413f708 100644 --- a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-abort.diff @@ -55,11 +55,12 @@ _10 = const _; StorageLive(_11); _11 = const 1_usize; - _12 = Len((*_10)); +- _12 = Len((*_10)); - _13 = Lt(_11, _12); - assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind unreachable]; -+ _13 = Lt(const 1_usize, _12); -+ assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 1_usize) -> [success: bb2, unwind unreachable]; ++ _12 = const 3_usize; ++ _13 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb2, unwind unreachable]; } bb2: { diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-unwind.diff index f9a6c509ac8..759a793fbf3 100644 --- a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-unwind.diff @@ -55,11 +55,12 @@ _10 = const _; StorageLive(_11); _11 = const 1_usize; - _12 = Len((*_10)); +- _12 = Len((*_10)); - _13 = Lt(_11, _12); - assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind continue]; -+ _13 = Lt(const 1_usize, _12); -+ assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 1_usize) -> [success: bb2, unwind continue]; ++ _12 = const 3_usize; ++ _13 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb2, unwind continue]; } bb2: { diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-abort.diff index be55d259dcf..e99b413f708 100644 --- a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-abort.diff @@ -55,11 +55,12 @@ _10 = const _; StorageLive(_11); _11 = const 1_usize; - _12 = Len((*_10)); +- _12 = Len((*_10)); - _13 = Lt(_11, _12); - assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind unreachable]; -+ _13 = Lt(const 1_usize, _12); -+ assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 1_usize) -> [success: bb2, unwind unreachable]; ++ _12 = const 3_usize; ++ _13 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb2, unwind unreachable]; } bb2: { diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-unwind.diff index f9a6c509ac8..759a793fbf3 100644 --- a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-unwind.diff @@ -55,11 +55,12 @@ _10 = const _; StorageLive(_11); _11 = const 1_usize; - _12 = Len((*_10)); +- _12 = Len((*_10)); - _13 = Lt(_11, _12); - assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind continue]; -+ _13 = Lt(const 1_usize, _12); -+ assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 1_usize) -> [success: bb2, unwind continue]; ++ _12 = const 3_usize; ++ _13 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb2, unwind continue]; } bb2: { diff --git a/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.32bit.diff new file mode 100644 index 00000000000..2de6ba307d5 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.32bit.diff @@ -0,0 +1,129 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let mut _1: S; + let mut _3: i32; + let mut _5: i32; + let mut _6: i32; + let mut _11: BigStruct; + let mut _16: &&BigStruct; + let mut _17: &BigStruct; + let mut _18: &BigStruct; + let mut _19: &BigStruct; + let mut _20: &BigStruct; + let mut _21: &BigStruct; + scope 1 { + debug s => _1; + let _2: i32; + scope 2 { + debug a => _2; + let _4: i32; + scope 3 { + debug b => _4; + let _7: S; + let _8: u8; + let _9: f32; + let _10: S; + scope 4 { + debug a => _7; + debug b => _8; + debug c => _9; + debug d => _10; + let _12: S; + let _13: u8; + let _14: f32; + let _15: S; + scope 5 { + debug a => _12; + debug b => _13; + debug c => _14; + debug d => _15; + } + } + } + } + } + + bb0: { + StorageLive(_1); + _1 = S(const 1_i32); + StorageLive(_2); + StorageLive(_3); +- _3 = (_1.0: i32); +- _2 = Add(move _3, const 2_i32); ++ _3 = const 1_i32; ++ _2 = const 3_i32; + StorageDead(_3); + (_1.0: i32) = const 3_i32; + StorageLive(_4); + StorageLive(_5); +- _5 = _2; ++ _5 = const 3_i32; + StorageLive(_6); +- _6 = (_1.0: i32); +- _4 = Add(move _5, move _6); ++ _6 = const 3_i32; ++ _4 = const 6_i32; + StorageDead(_6); + StorageDead(_5); + StorageLive(_11); + _11 = const _; + StorageLive(_7); +- _7 = (_11.0: S); ++ _7 = const S(1_i32); + StorageLive(_8); +- _8 = (_11.1: u8); ++ _8 = const 5_u8; + StorageLive(_9); +- _9 = (_11.2: f32); ++ _9 = const 7f32; + StorageLive(_10); +- _10 = (_11.3: S); ++ _10 = const S(13_i32); + StorageDead(_11); + StorageLive(_16); + _16 = const {alloc1: &&BigStruct}; + _17 = deref_copy (*_16); + StorageLive(_12); + _18 = deref_copy (*_16); +- _12 = ((*_18).0: S); ++ _12 = const S(1_i32); + StorageLive(_13); + _19 = deref_copy (*_16); +- _13 = ((*_19).1: u8); ++ _13 = const 5_u8; + StorageLive(_14); + _20 = deref_copy (*_16); +- _14 = ((*_20).2: f32); ++ _14 = const 7f32; + StorageLive(_15); + _21 = deref_copy (*_16); +- _15 = ((*_21).3: S); ++ _15 = const S(13_i32); + StorageDead(_16); + _0 = const (); + StorageDead(_15); + StorageDead(_14); + StorageDead(_13); + StorageDead(_12); + StorageDead(_10); + StorageDead(_9); + StorageDead(_8); + StorageDead(_7); + StorageDead(_4); + StorageDead(_2); + StorageDead(_1); + return; + } + } + + alloc1 (static: STAT, size: 4, align: 4) { + ╾─alloc15─╼ │ ╾──╼ + } + + alloc15 (size: 16, align: 4) { + 01 00 00 00 00 00 e0 40 0d 00 00 00 05 __ __ __ │ .......@.....░░░ + } + diff --git a/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..71a28f2165b --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.64bit.diff @@ -0,0 +1,129 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let mut _1: S; + let mut _3: i32; + let mut _5: i32; + let mut _6: i32; + let mut _11: BigStruct; + let mut _16: &&BigStruct; + let mut _17: &BigStruct; + let mut _18: &BigStruct; + let mut _19: &BigStruct; + let mut _20: &BigStruct; + let mut _21: &BigStruct; + scope 1 { + debug s => _1; + let _2: i32; + scope 2 { + debug a => _2; + let _4: i32; + scope 3 { + debug b => _4; + let _7: S; + let _8: u8; + let _9: f32; + let _10: S; + scope 4 { + debug a => _7; + debug b => _8; + debug c => _9; + debug d => _10; + let _12: S; + let _13: u8; + let _14: f32; + let _15: S; + scope 5 { + debug a => _12; + debug b => _13; + debug c => _14; + debug d => _15; + } + } + } + } + } + + bb0: { + StorageLive(_1); + _1 = S(const 1_i32); + StorageLive(_2); + StorageLive(_3); +- _3 = (_1.0: i32); +- _2 = Add(move _3, const 2_i32); ++ _3 = const 1_i32; ++ _2 = const 3_i32; + StorageDead(_3); + (_1.0: i32) = const 3_i32; + StorageLive(_4); + StorageLive(_5); +- _5 = _2; ++ _5 = const 3_i32; + StorageLive(_6); +- _6 = (_1.0: i32); +- _4 = Add(move _5, move _6); ++ _6 = const 3_i32; ++ _4 = const 6_i32; + StorageDead(_6); + StorageDead(_5); + StorageLive(_11); + _11 = const _; + StorageLive(_7); +- _7 = (_11.0: S); ++ _7 = const S(1_i32); + StorageLive(_8); +- _8 = (_11.1: u8); ++ _8 = const 5_u8; + StorageLive(_9); +- _9 = (_11.2: f32); ++ _9 = const 7f32; + StorageLive(_10); +- _10 = (_11.3: S); ++ _10 = const S(13_i32); + StorageDead(_11); + StorageLive(_16); + _16 = const {alloc1: &&BigStruct}; + _17 = deref_copy (*_16); + StorageLive(_12); + _18 = deref_copy (*_16); +- _12 = ((*_18).0: S); ++ _12 = const S(1_i32); + StorageLive(_13); + _19 = deref_copy (*_16); +- _13 = ((*_19).1: u8); ++ _13 = const 5_u8; + StorageLive(_14); + _20 = deref_copy (*_16); +- _14 = ((*_20).2: f32); ++ _14 = const 7f32; + StorageLive(_15); + _21 = deref_copy (*_16); +- _15 = ((*_21).3: S); ++ _15 = const S(13_i32); + StorageDead(_16); + _0 = const (); + StorageDead(_15); + StorageDead(_14); + StorageDead(_13); + StorageDead(_12); + StorageDead(_10); + StorageDead(_9); + StorageDead(_8); + StorageDead(_7); + StorageDead(_4); + StorageDead(_2); + StorageDead(_1); + return; + } + } + + alloc1 (static: STAT, size: 8, align: 8) { + ╾───────alloc15───────╼ │ ╾──────╼ + } + + alloc15 (size: 16, align: 4) { + 01 00 00 00 00 00 e0 40 0d 00 00 00 05 __ __ __ │ .......@.....░░░ + } + diff --git a/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.diff deleted file mode 100644 index 914bc8ac47e..00000000000 --- a/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.diff +++ /dev/null @@ -1,51 +0,0 @@ -- // MIR for `main` before DataflowConstProp -+ // MIR for `main` after DataflowConstProp - - fn main() -> () { - let mut _0: (); - let mut _1: S; - let mut _3: i32; - let mut _5: i32; - let mut _6: i32; - scope 1 { - debug s => _1; - let _2: i32; - scope 2 { - debug a => _2; - let _4: i32; - scope 3 { - debug b => _4; - } - } - } - - bb0: { - StorageLive(_1); - _1 = S(const 1_i32); - StorageLive(_2); - StorageLive(_3); -- _3 = (_1.0: i32); -- _2 = Add(move _3, const 2_i32); -+ _3 = const 1_i32; -+ _2 = const 3_i32; - StorageDead(_3); - (_1.0: i32) = const 3_i32; - StorageLive(_4); - StorageLive(_5); -- _5 = _2; -+ _5 = const 3_i32; - StorageLive(_6); -- _6 = (_1.0: i32); -- _4 = Add(move _5, move _6); -+ _6 = const 3_i32; -+ _4 = const 6_i32; - StorageDead(_6); - StorageDead(_5); - _0 = const (); - StorageDead(_4); - StorageDead(_2); - StorageDead(_1); - return; - } - } - diff --git a/tests/mir-opt/dataflow-const-prop/struct.rs b/tests/mir-opt/dataflow-const-prop/struct.rs index 841b279e03e..e92a1676d3f 100644 --- a/tests/mir-opt/dataflow-const-prop/struct.rs +++ b/tests/mir-opt/dataflow-const-prop/struct.rs @@ -1,11 +1,22 @@ // unit-test: DataflowConstProp +// EMIT_MIR_FOR_EACH_BIT_WIDTH +#[derive(Copy, Clone)] struct S(i32); +#[derive(Copy, Clone)] +struct BigStruct(S, u8, f32, S); + // EMIT_MIR struct.main.DataflowConstProp.diff fn main() { let mut s = S(1); let a = s.0 + 2; s.0 = 3; let b = a + s.0; + + const VAL: BigStruct = BigStruct(S(1), 5, 7., S(13)); + let BigStruct(a, b, c, d) = VAL; + + static STAT: &BigStruct = &BigStruct(S(1), 5, 7., S(13)); + let BigStruct(a, b, c, d) = *STAT; } |
