diff options
Diffstat (limited to 'tests/mir-opt/instsimplify')
29 files changed, 1207 insertions, 0 deletions
diff --git a/tests/mir-opt/instsimplify/bool_compare.eq_false.InstSimplify.diff b/tests/mir-opt/instsimplify/bool_compare.eq_false.InstSimplify.diff new file mode 100644 index 000000000..5c09963d4 --- /dev/null +++ b/tests/mir-opt/instsimplify/bool_compare.eq_false.InstSimplify.diff @@ -0,0 +1,36 @@ +- // MIR for `eq_false` before InstSimplify ++ // MIR for `eq_false` after InstSimplify + + fn eq_false(_1: bool) -> u32 { + debug x => _1; + let mut _0: u32; + let mut _2: bool; + let mut _3: bool; + + bb0: { + StorageLive(_2); + StorageLive(_3); + _3 = _1; +- _2 = Eq(move _3, const false); ++ _2 = Not(move _3); + switchInt(move _2) -> [0: bb2, otherwise: bb1]; + } + + bb1: { + StorageDead(_3); + _0 = const 0_u32; + goto -> bb3; + } + + bb2: { + StorageDead(_3); + _0 = const 1_u32; + goto -> bb3; + } + + bb3: { + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/bool_compare.eq_true.InstSimplify.diff b/tests/mir-opt/instsimplify/bool_compare.eq_true.InstSimplify.diff new file mode 100644 index 000000000..a80133b0e --- /dev/null +++ b/tests/mir-opt/instsimplify/bool_compare.eq_true.InstSimplify.diff @@ -0,0 +1,36 @@ +- // MIR for `eq_true` before InstSimplify ++ // MIR for `eq_true` after InstSimplify + + fn eq_true(_1: bool) -> u32 { + debug x => _1; + let mut _0: u32; + let mut _2: bool; + let mut _3: bool; + + bb0: { + StorageLive(_2); + StorageLive(_3); + _3 = _1; +- _2 = Eq(move _3, const true); ++ _2 = move _3; + switchInt(move _2) -> [0: bb2, otherwise: bb1]; + } + + bb1: { + StorageDead(_3); + _0 = const 0_u32; + goto -> bb3; + } + + bb2: { + StorageDead(_3); + _0 = const 1_u32; + goto -> bb3; + } + + bb3: { + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/bool_compare.false_eq.InstSimplify.diff b/tests/mir-opt/instsimplify/bool_compare.false_eq.InstSimplify.diff new file mode 100644 index 000000000..8235d5263 --- /dev/null +++ b/tests/mir-opt/instsimplify/bool_compare.false_eq.InstSimplify.diff @@ -0,0 +1,36 @@ +- // MIR for `false_eq` before InstSimplify ++ // MIR for `false_eq` after InstSimplify + + fn false_eq(_1: bool) -> u32 { + debug x => _1; + let mut _0: u32; + let mut _2: bool; + let mut _3: bool; + + bb0: { + StorageLive(_2); + StorageLive(_3); + _3 = _1; +- _2 = Eq(const false, move _3); ++ _2 = Not(move _3); + switchInt(move _2) -> [0: bb2, otherwise: bb1]; + } + + bb1: { + StorageDead(_3); + _0 = const 0_u32; + goto -> bb3; + } + + bb2: { + StorageDead(_3); + _0 = const 1_u32; + goto -> bb3; + } + + bb3: { + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/bool_compare.false_ne.InstSimplify.diff b/tests/mir-opt/instsimplify/bool_compare.false_ne.InstSimplify.diff new file mode 100644 index 000000000..77d076c6c --- /dev/null +++ b/tests/mir-opt/instsimplify/bool_compare.false_ne.InstSimplify.diff @@ -0,0 +1,36 @@ +- // MIR for `false_ne` before InstSimplify ++ // MIR for `false_ne` after InstSimplify + + fn false_ne(_1: bool) -> u32 { + debug x => _1; + let mut _0: u32; + let mut _2: bool; + let mut _3: bool; + + bb0: { + StorageLive(_2); + StorageLive(_3); + _3 = _1; +- _2 = Ne(const false, move _3); ++ _2 = move _3; + switchInt(move _2) -> [0: bb2, otherwise: bb1]; + } + + bb1: { + StorageDead(_3); + _0 = const 0_u32; + goto -> bb3; + } + + bb2: { + StorageDead(_3); + _0 = const 1_u32; + goto -> bb3; + } + + bb3: { + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/bool_compare.ne_false.InstSimplify.diff b/tests/mir-opt/instsimplify/bool_compare.ne_false.InstSimplify.diff new file mode 100644 index 000000000..2362b1129 --- /dev/null +++ b/tests/mir-opt/instsimplify/bool_compare.ne_false.InstSimplify.diff @@ -0,0 +1,36 @@ +- // MIR for `ne_false` before InstSimplify ++ // MIR for `ne_false` after InstSimplify + + fn ne_false(_1: bool) -> u32 { + debug x => _1; + let mut _0: u32; + let mut _2: bool; + let mut _3: bool; + + bb0: { + StorageLive(_2); + StorageLive(_3); + _3 = _1; +- _2 = Ne(move _3, const false); ++ _2 = move _3; + switchInt(move _2) -> [0: bb2, otherwise: bb1]; + } + + bb1: { + StorageDead(_3); + _0 = const 0_u32; + goto -> bb3; + } + + bb2: { + StorageDead(_3); + _0 = const 1_u32; + goto -> bb3; + } + + bb3: { + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/bool_compare.ne_true.InstSimplify.diff b/tests/mir-opt/instsimplify/bool_compare.ne_true.InstSimplify.diff new file mode 100644 index 000000000..6ccbd2fb7 --- /dev/null +++ b/tests/mir-opt/instsimplify/bool_compare.ne_true.InstSimplify.diff @@ -0,0 +1,36 @@ +- // MIR for `ne_true` before InstSimplify ++ // MIR for `ne_true` after InstSimplify + + fn ne_true(_1: bool) -> u32 { + debug x => _1; + let mut _0: u32; + let mut _2: bool; + let mut _3: bool; + + bb0: { + StorageLive(_2); + StorageLive(_3); + _3 = _1; +- _2 = Ne(move _3, const true); ++ _2 = Not(move _3); + switchInt(move _2) -> [0: bb2, otherwise: bb1]; + } + + bb1: { + StorageDead(_3); + _0 = const 0_u32; + goto -> bb3; + } + + bb2: { + StorageDead(_3); + _0 = const 1_u32; + goto -> bb3; + } + + bb3: { + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/bool_compare.rs b/tests/mir-opt/instsimplify/bool_compare.rs new file mode 100644 index 000000000..77f427b0d --- /dev/null +++ b/tests/mir-opt/instsimplify/bool_compare.rs @@ -0,0 +1,68 @@ +// unit-test: InstSimplify + +// EMIT_MIR bool_compare.eq_true.InstSimplify.diff +fn eq_true(x: bool) -> u32 { + // CHECK-LABEL: fn eq_true( + // CHECK-NOT: Eq( + if x == true { 0 } else { 1 } +} + +// EMIT_MIR bool_compare.true_eq.InstSimplify.diff +fn true_eq(x: bool) -> u32 { + // CHECK-LABEL: fn true_eq( + // CHECK-NOT: Eq( + if true == x { 0 } else { 1 } +} + +// EMIT_MIR bool_compare.ne_true.InstSimplify.diff +fn ne_true(x: bool) -> u32 { + // CHECK-LABEL: fn ne_true( + // CHECK: Not( + if x != true { 0 } else { 1 } +} + +// EMIT_MIR bool_compare.true_ne.InstSimplify.diff +fn true_ne(x: bool) -> u32 { + // CHECK-LABEL: fn true_ne( + // CHECK: Not( + if true != x { 0 } else { 1 } +} + +// EMIT_MIR bool_compare.eq_false.InstSimplify.diff +fn eq_false(x: bool) -> u32 { + // CHECK-LABEL: fn eq_false( + // CHECK: Not( + if x == false { 0 } else { 1 } +} + +// EMIT_MIR bool_compare.false_eq.InstSimplify.diff +fn false_eq(x: bool) -> u32 { + // CHECK-LABEL: fn false_eq( + // CHECK: Not( + if false == x { 0 } else { 1 } +} + +// EMIT_MIR bool_compare.ne_false.InstSimplify.diff +fn ne_false(x: bool) -> u32 { + // CHECK-LABEL: fn ne_false( + // CHECK-NOT: Ne( + if x != false { 0 } else { 1 } +} + +// EMIT_MIR bool_compare.false_ne.InstSimplify.diff +fn false_ne(x: bool) -> u32 { + // CHECK-LABEL: fn false_ne( + // CHECK-NOT: Ne( + if false != x { 0 } else { 1 } +} + +fn main() { + eq_true(false); + true_eq(false); + ne_true(false); + true_ne(false); + eq_false(false); + false_eq(false); + ne_false(false); + false_ne(false); +} diff --git a/tests/mir-opt/instsimplify/bool_compare.true_eq.InstSimplify.diff b/tests/mir-opt/instsimplify/bool_compare.true_eq.InstSimplify.diff new file mode 100644 index 000000000..18675329a --- /dev/null +++ b/tests/mir-opt/instsimplify/bool_compare.true_eq.InstSimplify.diff @@ -0,0 +1,36 @@ +- // MIR for `true_eq` before InstSimplify ++ // MIR for `true_eq` after InstSimplify + + fn true_eq(_1: bool) -> u32 { + debug x => _1; + let mut _0: u32; + let mut _2: bool; + let mut _3: bool; + + bb0: { + StorageLive(_2); + StorageLive(_3); + _3 = _1; +- _2 = Eq(const true, move _3); ++ _2 = move _3; + switchInt(move _2) -> [0: bb2, otherwise: bb1]; + } + + bb1: { + StorageDead(_3); + _0 = const 0_u32; + goto -> bb3; + } + + bb2: { + StorageDead(_3); + _0 = const 1_u32; + goto -> bb3; + } + + bb3: { + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/bool_compare.true_ne.InstSimplify.diff b/tests/mir-opt/instsimplify/bool_compare.true_ne.InstSimplify.diff new file mode 100644 index 000000000..dc91cf8a5 --- /dev/null +++ b/tests/mir-opt/instsimplify/bool_compare.true_ne.InstSimplify.diff @@ -0,0 +1,36 @@ +- // MIR for `true_ne` before InstSimplify ++ // MIR for `true_ne` after InstSimplify + + fn true_ne(_1: bool) -> u32 { + debug x => _1; + let mut _0: u32; + let mut _2: bool; + let mut _3: bool; + + bb0: { + StorageLive(_2); + StorageLive(_3); + _3 = _1; +- _2 = Ne(const true, move _3); ++ _2 = Not(move _3); + switchInt(move _2) -> [0: bb2, otherwise: bb1]; + } + + bb1: { + StorageDead(_3); + _0 = const 0_u32; + goto -> bb3; + } + + bb2: { + StorageDead(_3); + _0 = const 1_u32; + goto -> bb3; + } + + bb3: { + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/casts.redundant.InstSimplify.diff b/tests/mir-opt/instsimplify/casts.redundant.InstSimplify.diff new file mode 100644 index 000000000..9e1bce1ee --- /dev/null +++ b/tests/mir-opt/instsimplify/casts.redundant.InstSimplify.diff @@ -0,0 +1,34 @@ +- // MIR for `redundant` before InstSimplify ++ // MIR for `redundant` after InstSimplify + + fn redundant(_1: *const &u8) -> *const &u8 { + debug x => _1; + let mut _0: *const &u8; + let mut _2: *const &u8; + let mut _3: *const &u8; + let mut _4: *const &u8; + scope 1 (inlined generic_cast::<&u8, &u8>) { + debug x => _4; + let mut _5: *const &u8; + } + + bb0: { + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + _4 = _1; + StorageLive(_5); + _5 = _4; +- _3 = move _5 as *const &u8 (PtrToPtr); ++ _3 = move _5; + StorageDead(_5); + StorageDead(_4); +- _2 = move _3 as *const &u8 (PtrToPtr); ++ _2 = move _3; + _0 = _2; + StorageDead(_3); + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/casts.roundtrip.InstSimplify.diff b/tests/mir-opt/instsimplify/casts.roundtrip.InstSimplify.diff new file mode 100644 index 000000000..a6d68cd4e --- /dev/null +++ b/tests/mir-opt/instsimplify/casts.roundtrip.InstSimplify.diff @@ -0,0 +1,26 @@ +- // MIR for `roundtrip` before InstSimplify ++ // MIR for `roundtrip` after InstSimplify + + fn roundtrip(_1: *const u8) -> *const u8 { + debug x => _1; + let mut _0: *const u8; + let mut _2: *const u8; + let mut _3: *mut u8; + let mut _4: *const u8; + + bb0: { + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + _4 = _1; + _3 = move _4 as *mut u8 (PtrToPtr); + _2 = move _3 as *const u8 (PointerCoercion(MutToConstPointer)); + StorageDead(_4); + StorageDead(_3); +- _0 = move _2 as *const u8 (PtrToPtr); ++ _0 = move _2; + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/casts.rs b/tests/mir-opt/instsimplify/casts.rs new file mode 100644 index 000000000..86f9b34ea --- /dev/null +++ b/tests/mir-opt/instsimplify/casts.rs @@ -0,0 +1,25 @@ +// unit-test: InstSimplify +// compile-flags: -Zinline-mir +#![crate_type = "lib"] + +#[inline(always)] +fn generic_cast<T, U>(x: *const T) -> *const U { + x as *const U +} + +// EMIT_MIR casts.redundant.InstSimplify.diff +pub fn redundant<'a, 'b: 'a>(x: *const &'a u8) -> *const &'a u8 { + // CHECK-LABEL: fn redundant( + // CHECK: inlined generic_cast + // CHECK-NOT: as + generic_cast::<&'a u8, &'b u8>(x) as *const &'a u8 +} + +// EMIT_MIR casts.roundtrip.InstSimplify.diff +pub fn roundtrip(x: *const u8) -> *const u8 { + // CHECK-LABEL: fn roundtrip( + // CHECK: _4 = _1; + // CHECK: _3 = move _4 as *mut u8 (PtrToPtr); + // CHECK: _2 = move _3 as *const u8 (PointerCoercion(MutToConstPointer)); + x as *mut u8 as *const u8 +} diff --git a/tests/mir-opt/instsimplify/combine_array_len.norm2.InstSimplify.panic-abort.diff b/tests/mir-opt/instsimplify/combine_array_len.norm2.InstSimplify.panic-abort.diff new file mode 100644 index 000000000..3e7d0ce51 --- /dev/null +++ b/tests/mir-opt/instsimplify/combine_array_len.norm2.InstSimplify.panic-abort.diff @@ -0,0 +1,77 @@ +- // MIR for `norm2` before InstSimplify ++ // MIR for `norm2` after InstSimplify + + fn norm2(_1: [f32; 2]) -> f32 { + debug x => _1; + let mut _0: f32; + let _2: f32; + let _3: usize; + let mut _4: usize; + let mut _5: bool; + let _7: usize; + let mut _8: usize; + let mut _9: bool; + let mut _10: f32; + let mut _11: f32; + let mut _12: f32; + let mut _13: f32; + let mut _14: f32; + let mut _15: f32; + scope 1 { + debug a => _2; + let _6: f32; + scope 2 { + debug b => _6; + } + } + + bb0: { + StorageLive(_2); + StorageLive(_3); + _3 = const 0_usize; +- _4 = Len(_1); ++ _4 = const 2_usize; + _5 = Lt(_3, _4); + assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind unreachable]; + } + + bb1: { + _2 = _1[_3]; + StorageDead(_3); + StorageLive(_6); + StorageLive(_7); + _7 = const 1_usize; +- _8 = Len(_1); ++ _8 = const 2_usize; + _9 = Lt(_7, _8); + assert(move _9, "index out of bounds: the length is {} but the index is {}", move _8, _7) -> [success: bb2, unwind unreachable]; + } + + bb2: { + _6 = _1[_7]; + StorageDead(_7); + StorageLive(_10); + StorageLive(_11); + _11 = _2; + StorageLive(_12); + _12 = _2; + _10 = Mul(move _11, move _12); + StorageDead(_12); + StorageDead(_11); + StorageLive(_13); + StorageLive(_14); + _14 = _6; + StorageLive(_15); + _15 = _6; + _13 = Mul(move _14, move _15); + StorageDead(_15); + StorageDead(_14); + _0 = Add(move _10, move _13); + StorageDead(_13); + StorageDead(_10); + StorageDead(_6); + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/combine_array_len.norm2.InstSimplify.panic-unwind.diff b/tests/mir-opt/instsimplify/combine_array_len.norm2.InstSimplify.panic-unwind.diff new file mode 100644 index 000000000..4833c1089 --- /dev/null +++ b/tests/mir-opt/instsimplify/combine_array_len.norm2.InstSimplify.panic-unwind.diff @@ -0,0 +1,77 @@ +- // MIR for `norm2` before InstSimplify ++ // MIR for `norm2` after InstSimplify + + fn norm2(_1: [f32; 2]) -> f32 { + debug x => _1; + let mut _0: f32; + let _2: f32; + let _3: usize; + let mut _4: usize; + let mut _5: bool; + let _7: usize; + let mut _8: usize; + let mut _9: bool; + let mut _10: f32; + let mut _11: f32; + let mut _12: f32; + let mut _13: f32; + let mut _14: f32; + let mut _15: f32; + scope 1 { + debug a => _2; + let _6: f32; + scope 2 { + debug b => _6; + } + } + + bb0: { + StorageLive(_2); + StorageLive(_3); + _3 = const 0_usize; +- _4 = Len(_1); ++ _4 = const 2_usize; + _5 = Lt(_3, _4); + assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind continue]; + } + + bb1: { + _2 = _1[_3]; + StorageDead(_3); + StorageLive(_6); + StorageLive(_7); + _7 = const 1_usize; +- _8 = Len(_1); ++ _8 = const 2_usize; + _9 = Lt(_7, _8); + assert(move _9, "index out of bounds: the length is {} but the index is {}", move _8, _7) -> [success: bb2, unwind continue]; + } + + bb2: { + _6 = _1[_7]; + StorageDead(_7); + StorageLive(_10); + StorageLive(_11); + _11 = _2; + StorageLive(_12); + _12 = _2; + _10 = Mul(move _11, move _12); + StorageDead(_12); + StorageDead(_11); + StorageLive(_13); + StorageLive(_14); + _14 = _6; + StorageLive(_15); + _15 = _6; + _13 = Mul(move _14, move _15); + StorageDead(_15); + StorageDead(_14); + _0 = Add(move _10, move _13); + StorageDead(_13); + StorageDead(_10); + StorageDead(_6); + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/combine_array_len.rs b/tests/mir-opt/instsimplify/combine_array_len.rs new file mode 100644 index 000000000..3b6795bc9 --- /dev/null +++ b/tests/mir-opt/instsimplify/combine_array_len.rs @@ -0,0 +1,15 @@ +// EMIT_MIR_FOR_EACH_PANIC_STRATEGY +// unit-test: InstSimplify + +// EMIT_MIR combine_array_len.norm2.InstSimplify.diff +fn norm2(x: [f32; 2]) -> f32 { + // CHECK-LABEL: fn norm2( + // CHECK-NOT: Len( + let a = x[0]; + let b = x[1]; + a*a + b*b +} + +fn main() { + assert_eq!(norm2([3.0, 4.0]), 5.0*5.0); +} diff --git a/tests/mir-opt/instsimplify/combine_clone_of_primitives.rs b/tests/mir-opt/instsimplify/combine_clone_of_primitives.rs new file mode 100644 index 000000000..2adbe778d --- /dev/null +++ b/tests/mir-opt/instsimplify/combine_clone_of_primitives.rs @@ -0,0 +1,24 @@ +// unit-test: InstSimplify +// EMIT_MIR_FOR_EACH_PANIC_STRATEGY + +// EMIT_MIR combine_clone_of_primitives.{impl#0}-clone.InstSimplify.diff +#[derive(Clone)] +struct MyThing<T> { + v: T, + i: u64, + a: [f32; 3], +} + +// CHECK-LABEL: ::clone( +// CHECK: <T as Clone>::clone( +// CHECK-NOT: <u64 as Clone>::clone( +// CHECK-NOT: <[f32; 3] as Clone>::clone( + +fn main() { + let x = MyThing::<i16> { v: 2, i: 3, a: [0.0; 3] }; + let y = x.clone(); + + assert_eq!(y.v, 2); + assert_eq!(y.i, 3); + assert_eq!(y.a, [0.0; 3]); +} diff --git a/tests/mir-opt/instsimplify/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-abort.diff b/tests/mir-opt/instsimplify/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-abort.diff new file mode 100644 index 000000000..48586f8b3 --- /dev/null +++ b/tests/mir-opt/instsimplify/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-abort.diff @@ -0,0 +1,65 @@ +- // MIR for `<impl at $DIR/combine_clone_of_primitives.rs:5:10: 5:15>::clone` before InstSimplify ++ // MIR for `<impl at $DIR/combine_clone_of_primitives.rs:5:10: 5:15>::clone` after InstSimplify + + fn <impl at $DIR/combine_clone_of_primitives.rs:5:10: 5:15>::clone(_1: &MyThing<T>) -> MyThing<T> { + debug self => _1; + let mut _0: MyThing<T>; + let mut _2: T; + let mut _3: &T; + let _4: &T; + let mut _5: u64; + let mut _6: &u64; + let _7: &u64; + let mut _8: [f32; 3]; + let mut _9: &[f32; 3]; + let _10: &[f32; 3]; + + bb0: { + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + _4 = &((*_1).0: T); +- _3 = &(*_4); ++ _3 = _4; + _2 = <T as Clone>::clone(move _3) -> [return: bb1, unwind unreachable]; + } + + bb1: { + StorageDead(_3); + StorageLive(_5); + StorageLive(_6); + StorageLive(_7); + _7 = &((*_1).1: u64); +- _6 = &(*_7); +- _5 = <u64 as Clone>::clone(move _6) -> [return: bb2, unwind unreachable]; ++ _6 = _7; ++ _5 = (*_6); ++ goto -> bb2; + } + + bb2: { + StorageDead(_6); + StorageLive(_8); + StorageLive(_9); + StorageLive(_10); + _10 = &((*_1).2: [f32; 3]); +- _9 = &(*_10); +- _8 = <[f32; 3] as Clone>::clone(move _9) -> [return: bb3, unwind unreachable]; ++ _9 = _10; ++ _8 = (*_9); ++ goto -> bb3; + } + + bb3: { + StorageDead(_9); + _0 = MyThing::<T> { v: move _2, i: move _5, a: move _8 }; + StorageDead(_8); + StorageDead(_5); + StorageDead(_2); + StorageDead(_10); + StorageDead(_7); + StorageDead(_4); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-unwind.diff b/tests/mir-opt/instsimplify/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-unwind.diff new file mode 100644 index 000000000..a57266e9c --- /dev/null +++ b/tests/mir-opt/instsimplify/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-unwind.diff @@ -0,0 +1,73 @@ +- // MIR for `<impl at $DIR/combine_clone_of_primitives.rs:5:10: 5:15>::clone` before InstSimplify ++ // MIR for `<impl at $DIR/combine_clone_of_primitives.rs:5:10: 5:15>::clone` after InstSimplify + + fn <impl at $DIR/combine_clone_of_primitives.rs:5:10: 5:15>::clone(_1: &MyThing<T>) -> MyThing<T> { + debug self => _1; + let mut _0: MyThing<T>; + let mut _2: T; + let mut _3: &T; + let _4: &T; + let mut _5: u64; + let mut _6: &u64; + let _7: &u64; + let mut _8: [f32; 3]; + let mut _9: &[f32; 3]; + let _10: &[f32; 3]; + + bb0: { + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + _4 = &((*_1).0: T); +- _3 = &(*_4); ++ _3 = _4; + _2 = <T as Clone>::clone(move _3) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageDead(_3); + StorageLive(_5); + StorageLive(_6); + StorageLive(_7); + _7 = &((*_1).1: u64); +- _6 = &(*_7); +- _5 = <u64 as Clone>::clone(move _6) -> [return: bb2, unwind: bb4]; ++ _6 = _7; ++ _5 = (*_6); ++ goto -> bb2; + } + + bb2: { + StorageDead(_6); + StorageLive(_8); + StorageLive(_9); + StorageLive(_10); + _10 = &((*_1).2: [f32; 3]); +- _9 = &(*_10); +- _8 = <[f32; 3] as Clone>::clone(move _9) -> [return: bb3, unwind: bb4]; ++ _9 = _10; ++ _8 = (*_9); ++ goto -> bb3; + } + + bb3: { + StorageDead(_9); + _0 = MyThing::<T> { v: move _2, i: move _5, a: move _8 }; + StorageDead(_8); + StorageDead(_5); + StorageDead(_2); + StorageDead(_10); + StorageDead(_7); + StorageDead(_4); + return; + } + + bb4 (cleanup): { + drop(_2) -> [return: bb5, unwind terminate(cleanup)]; + } + + bb5 (cleanup): { + resume; + } + } + diff --git a/tests/mir-opt/instsimplify/combine_transmutes.adt_transmutes.InstSimplify.diff b/tests/mir-opt/instsimplify/combine_transmutes.adt_transmutes.InstSimplify.diff new file mode 100644 index 000000000..cb623e83f --- /dev/null +++ b/tests/mir-opt/instsimplify/combine_transmutes.adt_transmutes.InstSimplify.diff @@ -0,0 +1,83 @@ +- // MIR for `adt_transmutes` before InstSimplify ++ // MIR for `adt_transmutes` after InstSimplify + + fn adt_transmutes() -> () { + let mut _0: (); + let _1: u8; + let mut _2: std::option::Option<std::num::NonZeroU8>; + let mut _4: std::num::Wrapping<i16>; + let mut _6: std::num::Wrapping<i16>; + let mut _8: Union32; + let mut _10: Union32; + let mut _12: std::mem::MaybeUninit<std::string::String>; + scope 1 { + debug _a => _1; + let _3: i16; + scope 2 { + debug _a => _3; + let _5: u16; + scope 3 { + debug _a => _5; + let _7: u32; + scope 4 { + debug _a => _7; + let _9: i32; + scope 5 { + debug _a => _9; + let _11: std::mem::ManuallyDrop<std::string::String>; + scope 6 { + debug _a => _11; + } + } + } + } + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = Option::<NonZeroU8>::Some(const _); + _1 = move _2 as u8 (Transmute); + StorageDead(_2); + StorageLive(_3); + StorageLive(_4); + _4 = Wrapping::<i16>(const 0_i16); +- _3 = move _4 as i16 (Transmute); ++ _3 = move (_4.0: i16); + StorageDead(_4); + StorageLive(_5); + StorageLive(_6); + _6 = Wrapping::<i16>(const 0_i16); + _5 = move _6 as u16 (Transmute); + StorageDead(_6); + StorageLive(_7); + StorageLive(_8); + _8 = Union32 { u32: const 0_i32 }; + _7 = move _8 as u32 (Transmute); + StorageDead(_8); + StorageLive(_9); + StorageLive(_10); + _10 = Union32 { u32: const 0_u32 }; + _9 = move _10 as i32 (Transmute); + StorageDead(_10); + StorageLive(_11); + StorageLive(_12); + _12 = MaybeUninit::<String>::uninit() -> [return: bb1, unwind unreachable]; + } + + bb1: { +- _11 = move _12 as std::mem::ManuallyDrop<std::string::String> (Transmute); ++ _11 = move (_12.1: std::mem::ManuallyDrop<std::string::String>); + StorageDead(_12); + _0 = const (); + StorageDead(_11); + StorageDead(_9); + StorageDead(_7); + StorageDead(_5); + StorageDead(_3); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/combine_transmutes.identity_transmutes.InstSimplify.diff b/tests/mir-opt/instsimplify/combine_transmutes.identity_transmutes.InstSimplify.diff new file mode 100644 index 000000000..58ae59190 --- /dev/null +++ b/tests/mir-opt/instsimplify/combine_transmutes.identity_transmutes.InstSimplify.diff @@ -0,0 +1,39 @@ +- // MIR for `identity_transmutes` before InstSimplify ++ // MIR for `identity_transmutes` after InstSimplify + + fn identity_transmutes() -> () { + let mut _0: (); + let _1: i32; + let mut _3: std::vec::Vec<i32>; + scope 1 { + debug _a => _1; + let _2: std::vec::Vec<i32>; + scope 2 { + debug _a => _2; + } + } + + bb0: { + StorageLive(_1); +- _1 = const 1_i32 as i32 (Transmute); ++ _1 = const 1_i32; + StorageLive(_2); + StorageLive(_3); + _3 = Vec::<i32>::new() -> [return: bb1, unwind unreachable]; + } + + bb1: { +- _2 = move _3 as std::vec::Vec<i32> (Transmute); ++ _2 = move _3; + StorageDead(_3); + _0 = const (); + drop(_2) -> [return: bb2, unwind unreachable]; + } + + bb2: { + StorageDead(_2); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/combine_transmutes.integer_transmutes.InstSimplify.diff b/tests/mir-opt/instsimplify/combine_transmutes.integer_transmutes.InstSimplify.diff new file mode 100644 index 000000000..8eff802dd --- /dev/null +++ b/tests/mir-opt/instsimplify/combine_transmutes.integer_transmutes.InstSimplify.diff @@ -0,0 +1,24 @@ +- // MIR for `integer_transmutes` before InstSimplify ++ // MIR for `integer_transmutes` after InstSimplify + + fn integer_transmutes() -> () { + let mut _0: (); + let mut _1: u32; + let mut _2: i64; + let mut _3: i64; + let mut _4: u32; + let mut _5: usize; + + bb0: { +- _1 = const 1_i32 as u32 (Transmute); ++ _1 = const 1_i32 as u32 (IntToInt); + _2 = const 1_i32 as i64 (Transmute); +- _3 = const 1_u64 as i64 (Transmute); ++ _3 = const 1_u64 as i64 (IntToInt); + _4 = const 1_u64 as u32 (Transmute); +- _5 = const 1_isize as usize (Transmute); ++ _5 = const 1_isize as usize (IntToInt); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/combine_transmutes.rs b/tests/mir-opt/instsimplify/combine_transmutes.rs new file mode 100644 index 000000000..b8e15da90 --- /dev/null +++ b/tests/mir-opt/instsimplify/combine_transmutes.rs @@ -0,0 +1,65 @@ +// unit-test: InstSimplify +// compile-flags: -C panic=abort + +#![crate_type = "lib"] +#![feature(core_intrinsics)] +#![feature(custom_mir)] + +use std::intrinsics::mir::*; +use std::mem::{MaybeUninit, ManuallyDrop, transmute}; + +// EMIT_MIR combine_transmutes.identity_transmutes.InstSimplify.diff +pub unsafe fn identity_transmutes() { + // CHECK-LABEL: fn identity_transmutes( + // CHECK-NOT: as i32 (Transmute); + // CHECK-NOT: as Vec<i32> (Transmute); + + // These are nops and should be removed + let _a = transmute::<i32, i32>(1); + let _a = transmute::<Vec<i32>, Vec<i32>>(Vec::new()); +} + +#[custom_mir(dialect = "runtime", phase = "initial")] +// EMIT_MIR combine_transmutes.integer_transmutes.InstSimplify.diff +pub unsafe fn integer_transmutes() { + // CHECK-LABEL: fn integer_transmutes( + // CHECK-NOT: _i32 as u32 (Transmute); + // CHECK: _i32 as u32 (IntToInt); + // CHECK: _i32 as i64 (Transmute); + // CHECK-NOT: _u64 as i64 (Transmute); + // CHECK: _u64 as i64 (IntToInt); + // CHECK: _u64 as u32 (Transmute); + // CHECK-NOT: _isize as usize (Transmute); + // CHECK: _isize as usize (IntToInt); + + mir! { + { + let A = CastTransmute::<i32, u32>(1); // Can be a cast + let B = CastTransmute::<i32, i64>(1); // UB + let C = CastTransmute::<u64, i64>(1); // Can be a cast + let D = CastTransmute::<u64, u32>(1); // UB + let E = CastTransmute::<isize, usize>(1); // Can be a cast + Return() + } + } +} + +// EMIT_MIR combine_transmutes.adt_transmutes.InstSimplify.diff +pub unsafe fn adt_transmutes() { + // CHECK-LABEL: fn adt_transmutes( + // CHECK: as u8 (Transmute); + // CHECK: ({{_.*}}.0: i16); + // CHECK: as u16 (Transmute); + // CHECK: as u32 (Transmute); + // CHECK: as i32 (Transmute); + // CHECK: ({{_.*}}.1: std::mem::ManuallyDrop<std::string::String>); + + let _a: u8 = transmute(Some(std::num::NonZeroU8::MAX)); + let _a: i16 = transmute(std::num::Wrapping(0_i16)); + let _a: u16 = transmute(std::num::Wrapping(0_i16)); + let _a: u32 = transmute(Union32 { i32: 0 }); + let _a: i32 = transmute(Union32 { u32: 0 }); + let _a: ManuallyDrop<String> = transmute(MaybeUninit::<String>::uninit()); +} + +pub union Union32 { u32: u32, i32: i32 } diff --git a/tests/mir-opt/instsimplify/duplicate_switch_targets.assert_zero.InstSimplify.diff b/tests/mir-opt/instsimplify/duplicate_switch_targets.assert_zero.InstSimplify.diff new file mode 100644 index 000000000..e2b45c882 --- /dev/null +++ b/tests/mir-opt/instsimplify/duplicate_switch_targets.assert_zero.InstSimplify.diff @@ -0,0 +1,21 @@ +- // MIR for `assert_zero` before InstSimplify ++ // MIR for `assert_zero` after InstSimplify + + fn assert_zero(_1: u8) -> u8 { + let mut _0: u8; + + bb0: { +- switchInt(_1) -> [0: bb2, 1: bb1, otherwise: bb1]; ++ switchInt(_1) -> [0: bb2, otherwise: bb1]; + } + + bb1: { + unreachable; + } + + bb2: { + _0 = _1; + return; + } + } + diff --git a/tests/mir-opt/instsimplify/duplicate_switch_targets.rs b/tests/mir-opt/instsimplify/duplicate_switch_targets.rs new file mode 100644 index 000000000..e40bc7eda --- /dev/null +++ b/tests/mir-opt/instsimplify/duplicate_switch_targets.rs @@ -0,0 +1,29 @@ +// unit-test: InstSimplify + +#![feature(custom_mir, core_intrinsics)] +#![crate_type = "lib"] + +use std::intrinsics::mir::*; + +// EMIT_MIR duplicate_switch_targets.assert_zero.InstSimplify.diff +#[custom_mir(dialect = "runtime", phase = "post-cleanup")] +pub unsafe fn assert_zero(x: u8) -> u8 { + // CHECK-LABEL: fn assert_zero( + // CHECK: switchInt({{.*}}) -> [0: {{bb.*}}, otherwise: {{bb.*}}] + mir!( + { + match x { + 0 => retblock, + 1 => unreachable, + _ => unreachable, + } + } + unreachable = { + Unreachable() + } + retblock = { + RET = x; + Return() + } + ) +} diff --git a/tests/mir-opt/instsimplify/intrinsic_asserts.generic.InstSimplify.diff b/tests/mir-opt/instsimplify/intrinsic_asserts.generic.InstSimplify.diff new file mode 100644 index 000000000..2ecacb5e3 --- /dev/null +++ b/tests/mir-opt/instsimplify/intrinsic_asserts.generic.InstSimplify.diff @@ -0,0 +1,33 @@ +- // MIR for `generic` before InstSimplify ++ // MIR for `generic` after InstSimplify + + fn generic() -> () { + let mut _0: (); + let _1: (); + let _2: (); + let _3: (); + + bb0: { + StorageLive(_1); + _1 = assert_inhabited::<T>() -> [return: bb1, unwind unreachable]; + } + + bb1: { + StorageDead(_1); + StorageLive(_2); + _2 = assert_zero_valid::<T>() -> [return: bb2, unwind unreachable]; + } + + bb2: { + StorageDead(_2); + StorageLive(_3); + _3 = assert_mem_uninitialized_valid::<T>() -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_3); + _0 = const (); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/intrinsic_asserts.generic_ref.InstSimplify.diff b/tests/mir-opt/instsimplify/intrinsic_asserts.generic_ref.InstSimplify.diff new file mode 100644 index 000000000..d29af0945 --- /dev/null +++ b/tests/mir-opt/instsimplify/intrinsic_asserts.generic_ref.InstSimplify.diff @@ -0,0 +1,19 @@ +- // MIR for `generic_ref` before InstSimplify ++ // MIR for `generic_ref` after InstSimplify + + fn generic_ref() -> () { + let mut _0: (); + let _1: (); + + bb0: { + StorageLive(_1); + _1 = assert_mem_uninitialized_valid::<&T>() -> [return: bb1, unwind unreachable]; + } + + bb1: { + StorageDead(_1); + _0 = const (); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/intrinsic_asserts.panics.InstSimplify.diff b/tests/mir-opt/instsimplify/intrinsic_asserts.panics.InstSimplify.diff new file mode 100644 index 000000000..1be386acf --- /dev/null +++ b/tests/mir-opt/instsimplify/intrinsic_asserts.panics.InstSimplify.diff @@ -0,0 +1,36 @@ +- // MIR for `panics` before InstSimplify ++ // MIR for `panics` after InstSimplify + + fn panics() -> () { + let mut _0: (); + let _1: (); + let _2: (); + let _3: (); + + bb0: { + StorageLive(_1); +- _1 = assert_inhabited::<Never>() -> [return: bb1, unwind unreachable]; ++ _1 = assert_inhabited::<Never>() -> unwind unreachable; + } + + bb1: { + StorageDead(_1); + StorageLive(_2); +- _2 = assert_zero_valid::<&u8>() -> [return: bb2, unwind unreachable]; ++ _2 = assert_zero_valid::<&u8>() -> unwind unreachable; + } + + bb2: { + StorageDead(_2); + StorageLive(_3); +- _3 = assert_mem_uninitialized_valid::<&u8>() -> [return: bb3, unwind unreachable]; ++ _3 = assert_mem_uninitialized_valid::<&u8>() -> unwind unreachable; + } + + bb3: { + StorageDead(_3); + _0 = const (); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/intrinsic_asserts.removable.InstSimplify.diff b/tests/mir-opt/instsimplify/intrinsic_asserts.removable.InstSimplify.diff new file mode 100644 index 000000000..f2e697838 --- /dev/null +++ b/tests/mir-opt/instsimplify/intrinsic_asserts.removable.InstSimplify.diff @@ -0,0 +1,36 @@ +- // MIR for `removable` before InstSimplify ++ // MIR for `removable` after InstSimplify + + fn removable() -> () { + let mut _0: (); + let _1: (); + let _2: (); + let _3: (); + + bb0: { + StorageLive(_1); +- _1 = assert_inhabited::<()>() -> [return: bb1, unwind unreachable]; ++ goto -> bb1; + } + + bb1: { + StorageDead(_1); + StorageLive(_2); +- _2 = assert_zero_valid::<u8>() -> [return: bb2, unwind unreachable]; ++ goto -> bb2; + } + + bb2: { + StorageDead(_2); + StorageLive(_3); +- _3 = assert_mem_uninitialized_valid::<u8>() -> [return: bb3, unwind unreachable]; ++ goto -> bb3; + } + + bb3: { + StorageDead(_3); + _0 = const (); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/intrinsic_asserts.rs b/tests/mir-opt/instsimplify/intrinsic_asserts.rs new file mode 100644 index 000000000..43998b2db --- /dev/null +++ b/tests/mir-opt/instsimplify/intrinsic_asserts.rs @@ -0,0 +1,50 @@ +// unit-test: InstSimplify + +#![crate_type = "lib"] +#![feature(core_intrinsics)] + +// All these assertions pass, so all the intrinsic calls should be deleted. +// EMIT_MIR intrinsic_asserts.removable.InstSimplify.diff +pub fn removable() { + // CHECK-LABEL: fn removable( + // CHECK-NOT: assert_inhabited + // CHECK-NOT: assert_zero_valid + // CHECK-NOT: assert_mem_uninitialized_valid + core::intrinsics::assert_inhabited::<()>(); + core::intrinsics::assert_zero_valid::<u8>(); + core::intrinsics::assert_mem_uninitialized_valid::<u8>(); +} + +enum Never {} + +// These assertions all diverge, so their target blocks should become None. +// EMIT_MIR intrinsic_asserts.panics.InstSimplify.diff +pub fn panics() { + // CHECK-LABEL: fn panics( + // CHECK: assert_inhabited::<Never>() -> unwind + // CHECK: assert_zero_valid::<&u8>() -> unwind + // CHECK: assert_mem_uninitialized_valid::<&u8>() -> unwind + core::intrinsics::assert_inhabited::<Never>(); + core::intrinsics::assert_zero_valid::<&u8>(); + core::intrinsics::assert_mem_uninitialized_valid::<&u8>(); +} + +// Whether or not these asserts pass isn't known, so they shouldn't be modified. +// EMIT_MIR intrinsic_asserts.generic.InstSimplify.diff +pub fn generic<T>() { + // CHECK-LABEL: fn generic( + // CHECK: assert_inhabited::<T>() -> [return: + // CHECK: assert_zero_valid::<T>() -> [return: + // CHECK: assert_mem_uninitialized_valid::<T>() -> [return: + core::intrinsics::assert_inhabited::<T>(); + core::intrinsics::assert_zero_valid::<T>(); + core::intrinsics::assert_mem_uninitialized_valid::<T>(); +} + +// Whether or not these asserts pass isn't known, so they shouldn't be modified. +// EMIT_MIR intrinsic_asserts.generic_ref.InstSimplify.diff +pub fn generic_ref<T>() { + // CHECK-LABEL: fn generic_ref( + // CHECK: assert_mem_uninitialized_valid::<&T>() -> [return: + core::intrinsics::assert_mem_uninitialized_valid::<&T>(); +} |