summaryrefslogtreecommitdiffstats
path: root/tests/mir-opt/instsimplify
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /tests/mir-opt/instsimplify
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--tests/mir-opt/instsimplify/bool_compare.eq_false.InstSimplify.diff36
-rw-r--r--tests/mir-opt/instsimplify/bool_compare.eq_true.InstSimplify.diff36
-rw-r--r--tests/mir-opt/instsimplify/bool_compare.false_eq.InstSimplify.diff36
-rw-r--r--tests/mir-opt/instsimplify/bool_compare.false_ne.InstSimplify.diff36
-rw-r--r--tests/mir-opt/instsimplify/bool_compare.ne_false.InstSimplify.diff36
-rw-r--r--tests/mir-opt/instsimplify/bool_compare.ne_true.InstSimplify.diff36
-rw-r--r--tests/mir-opt/instsimplify/bool_compare.rs68
-rw-r--r--tests/mir-opt/instsimplify/bool_compare.true_eq.InstSimplify.diff36
-rw-r--r--tests/mir-opt/instsimplify/bool_compare.true_ne.InstSimplify.diff36
-rw-r--r--tests/mir-opt/instsimplify/casts.redundant.InstSimplify.diff34
-rw-r--r--tests/mir-opt/instsimplify/casts.roundtrip.InstSimplify.diff26
-rw-r--r--tests/mir-opt/instsimplify/casts.rs25
-rw-r--r--tests/mir-opt/instsimplify/combine_array_len.norm2.InstSimplify.panic-abort.diff (renamed from tests/mir-opt/combine_array_len.norm2.InstSimplify.panic-abort.diff)0
-rw-r--r--tests/mir-opt/instsimplify/combine_array_len.norm2.InstSimplify.panic-unwind.diff (renamed from tests/mir-opt/combine_array_len.norm2.InstSimplify.panic-unwind.diff)0
-rw-r--r--tests/mir-opt/instsimplify/combine_array_len.rs (renamed from tests/mir-opt/combine_array_len.rs)4
-rw-r--r--tests/mir-opt/instsimplify/combine_clone_of_primitives.rs24
-rw-r--r--tests/mir-opt/instsimplify/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-abort.diff (renamed from tests/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-abort.diff)6
-rw-r--r--tests/mir-opt/instsimplify/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-unwind.diff (renamed from tests/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-unwind.diff)6
-rw-r--r--tests/mir-opt/instsimplify/combine_transmutes.adt_transmutes.InstSimplify.diff (renamed from tests/mir-opt/combine_transmutes.adt_transmutes.InstSimplify.diff)0
-rw-r--r--tests/mir-opt/instsimplify/combine_transmutes.identity_transmutes.InstSimplify.diff (renamed from tests/mir-opt/combine_transmutes.identity_transmutes.InstSimplify.diff)0
-rw-r--r--tests/mir-opt/instsimplify/combine_transmutes.integer_transmutes.InstSimplify.diff (renamed from tests/mir-opt/combine_transmutes.integer_transmutes.InstSimplify.diff)0
-rw-r--r--tests/mir-opt/instsimplify/combine_transmutes.rs65
-rw-r--r--tests/mir-opt/instsimplify/duplicate_switch_targets.assert_zero.InstSimplify.diff (renamed from tests/mir-opt/instsimplify_duplicate_switch_targets.assert_zero.InstSimplify.diff)0
-rw-r--r--tests/mir-opt/instsimplify/duplicate_switch_targets.rs29
-rw-r--r--tests/mir-opt/instsimplify/intrinsic_asserts.generic.InstSimplify.diff33
-rw-r--r--tests/mir-opt/instsimplify/intrinsic_asserts.generic_ref.InstSimplify.diff19
-rw-r--r--tests/mir-opt/instsimplify/intrinsic_asserts.panics.InstSimplify.diff (renamed from tests/mir-opt/intrinsic_asserts.panics.InstSimplify.diff)14
-rw-r--r--tests/mir-opt/instsimplify/intrinsic_asserts.removable.InstSimplify.diff (renamed from tests/mir-opt/intrinsic_asserts.removable.InstSimplify.diff)14
-rw-r--r--tests/mir-opt/instsimplify/intrinsic_asserts.rs50
-rw-r--r--tests/mir-opt/instsimplify_duplicate_switch_targets.rs27
30 files changed, 684 insertions, 48 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/combine_array_len.norm2.InstSimplify.panic-abort.diff b/tests/mir-opt/instsimplify/combine_array_len.norm2.InstSimplify.panic-abort.diff
index 3e7d0ce51..3e7d0ce51 100644
--- a/tests/mir-opt/combine_array_len.norm2.InstSimplify.panic-abort.diff
+++ b/tests/mir-opt/instsimplify/combine_array_len.norm2.InstSimplify.panic-abort.diff
diff --git a/tests/mir-opt/combine_array_len.norm2.InstSimplify.panic-unwind.diff b/tests/mir-opt/instsimplify/combine_array_len.norm2.InstSimplify.panic-unwind.diff
index 4833c1089..4833c1089 100644
--- a/tests/mir-opt/combine_array_len.norm2.InstSimplify.panic-unwind.diff
+++ b/tests/mir-opt/instsimplify/combine_array_len.norm2.InstSimplify.panic-unwind.diff
diff --git a/tests/mir-opt/combine_array_len.rs b/tests/mir-opt/instsimplify/combine_array_len.rs
index e971ab478..3b6795bc9 100644
--- a/tests/mir-opt/combine_array_len.rs
+++ b/tests/mir-opt/instsimplify/combine_array_len.rs
@@ -1,8 +1,10 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// unit-test: InstSimplify
-// EMIT_MIR combine_array_len.norm2.InstSimplify.diff
+// 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
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/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
index 124c2dc7e..48586f8b3 100644
--- a/tests/mir-opt/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
@@ -1,7 +1,7 @@
-- // MIR for `<impl at $DIR/combine_clone_of_primitives.rs:6:10: 6:15>::clone` before InstSimplify
-+ // MIR for `<impl at $DIR/combine_clone_of_primitives.rs:6:10: 6:15>::clone` after InstSimplify
+- // 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:6:10: 6:15>::clone(_1: &MyThing<T>) -> MyThing<T> {
+ 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;
diff --git a/tests/mir-opt/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
index f2b87221f..a57266e9c 100644
--- a/tests/mir-opt/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
@@ -1,7 +1,7 @@
-- // MIR for `<impl at $DIR/combine_clone_of_primitives.rs:6:10: 6:15>::clone` before InstSimplify
-+ // MIR for `<impl at $DIR/combine_clone_of_primitives.rs:6:10: 6:15>::clone` after InstSimplify
+- // 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:6:10: 6:15>::clone(_1: &MyThing<T>) -> MyThing<T> {
+ 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;
diff --git a/tests/mir-opt/combine_transmutes.adt_transmutes.InstSimplify.diff b/tests/mir-opt/instsimplify/combine_transmutes.adt_transmutes.InstSimplify.diff
index cb623e83f..cb623e83f 100644
--- a/tests/mir-opt/combine_transmutes.adt_transmutes.InstSimplify.diff
+++ b/tests/mir-opt/instsimplify/combine_transmutes.adt_transmutes.InstSimplify.diff
diff --git a/tests/mir-opt/combine_transmutes.identity_transmutes.InstSimplify.diff b/tests/mir-opt/instsimplify/combine_transmutes.identity_transmutes.InstSimplify.diff
index 58ae59190..58ae59190 100644
--- a/tests/mir-opt/combine_transmutes.identity_transmutes.InstSimplify.diff
+++ b/tests/mir-opt/instsimplify/combine_transmutes.identity_transmutes.InstSimplify.diff
diff --git a/tests/mir-opt/combine_transmutes.integer_transmutes.InstSimplify.diff b/tests/mir-opt/instsimplify/combine_transmutes.integer_transmutes.InstSimplify.diff
index 8eff802dd..8eff802dd 100644
--- a/tests/mir-opt/combine_transmutes.integer_transmutes.InstSimplify.diff
+++ b/tests/mir-opt/instsimplify/combine_transmutes.integer_transmutes.InstSimplify.diff
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
index e2b45c882..e2b45c882 100644
--- a/tests/mir-opt/instsimplify_duplicate_switch_targets.assert_zero.InstSimplify.diff
+++ b/tests/mir-opt/instsimplify/duplicate_switch_targets.assert_zero.InstSimplify.diff
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/intrinsic_asserts.panics.InstSimplify.diff b/tests/mir-opt/instsimplify/intrinsic_asserts.panics.InstSimplify.diff
index 46e053378..1be386acf 100644
--- a/tests/mir-opt/intrinsic_asserts.panics.InstSimplify.diff
+++ b/tests/mir-opt/instsimplify/intrinsic_asserts.panics.InstSimplify.diff
@@ -8,28 +8,28 @@
let _3: ();
bb0: {
- nop;
+ StorageLive(_1);
- _1 = assert_inhabited::<Never>() -> [return: bb1, unwind unreachable];
+ _1 = assert_inhabited::<Never>() -> unwind unreachable;
}
bb1: {
- nop;
- nop;
+ StorageDead(_1);
+ StorageLive(_2);
- _2 = assert_zero_valid::<&u8>() -> [return: bb2, unwind unreachable];
+ _2 = assert_zero_valid::<&u8>() -> unwind unreachable;
}
bb2: {
- nop;
- nop;
+ StorageDead(_2);
+ StorageLive(_3);
- _3 = assert_mem_uninitialized_valid::<&u8>() -> [return: bb3, unwind unreachable];
+ _3 = assert_mem_uninitialized_valid::<&u8>() -> unwind unreachable;
}
bb3: {
- nop;
- nop;
+ StorageDead(_3);
+ _0 = const ();
return;
}
}
diff --git a/tests/mir-opt/intrinsic_asserts.removable.InstSimplify.diff b/tests/mir-opt/instsimplify/intrinsic_asserts.removable.InstSimplify.diff
index 70c3e8830..f2e697838 100644
--- a/tests/mir-opt/intrinsic_asserts.removable.InstSimplify.diff
+++ b/tests/mir-opt/instsimplify/intrinsic_asserts.removable.InstSimplify.diff
@@ -8,28 +8,28 @@
let _3: ();
bb0: {
- nop;
+ StorageLive(_1);
- _1 = assert_inhabited::<()>() -> [return: bb1, unwind unreachable];
+ goto -> bb1;
}
bb1: {
- nop;
- nop;
+ StorageDead(_1);
+ StorageLive(_2);
- _2 = assert_zero_valid::<u8>() -> [return: bb2, unwind unreachable];
+ goto -> bb2;
}
bb2: {
- nop;
- nop;
+ StorageDead(_2);
+ StorageLive(_3);
- _3 = assert_mem_uninitialized_valid::<u8>() -> [return: bb3, unwind unreachable];
+ goto -> bb3;
}
bb3: {
- nop;
- nop;
+ 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>();
+}
diff --git a/tests/mir-opt/instsimplify_duplicate_switch_targets.rs b/tests/mir-opt/instsimplify_duplicate_switch_targets.rs
deleted file mode 100644
index 3e280a40f..000000000
--- a/tests/mir-opt/instsimplify_duplicate_switch_targets.rs
+++ /dev/null
@@ -1,27 +0,0 @@
-#![feature(custom_mir, core_intrinsics)]
-#![crate_type = "lib"]
-
-use std::intrinsics::mir::*;
-
-// unit-test: InstSimplify
-
-// EMIT_MIR instsimplify_duplicate_switch_targets.assert_zero.InstSimplify.diff
-#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
-pub unsafe fn assert_zero(x: u8) -> u8 {
- mir!(
- {
- match x {
- 0 => retblock,
- 1 => unreachable,
- _ => unreachable,
- }
- }
- unreachable = {
- Unreachable()
- }
- retblock = {
- RET = x;
- Return()
- }
- )
-}