about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2023-10-16 19:58:20 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2023-10-19 15:51:54 +0000
commitd8cffda66a2d865adf098c4f079fafdb73bcf1ba (patch)
tree0df67dd780a052e3b5f21203bfb1fe8761693142
parent68c409f8f64316b9a917d04e1ce4d4a2ee70b85d (diff)
downloadrust-d8cffda66a2d865adf098c4f079fafdb73bcf1ba.tar.gz
rust-d8cffda66a2d865adf098c4f079fafdb73bcf1ba.zip
FileCheck casts.
-rw-r--r--tests/mir-opt/casts.redundant.PreCodegen.after.mir14
-rw-r--r--tests/mir-opt/casts.roundtrip.PreCodegen.after.mir15
-rw-r--r--tests/mir-opt/casts.rs18
-rw-r--r--tests/mir-opt/instsimplify/casts.redundant.InstSimplify.diff (renamed from tests/mir-opt/casts.redundant.InstSimplify.diff)10
-rw-r--r--tests/mir-opt/instsimplify/casts.roundtrip.InstSimplify.diff21
-rw-r--r--tests/mir-opt/instsimplify/casts.rs25
6 files changed, 53 insertions, 50 deletions
diff --git a/tests/mir-opt/casts.redundant.PreCodegen.after.mir b/tests/mir-opt/casts.redundant.PreCodegen.after.mir
deleted file mode 100644
index 2084f44f248..00000000000
--- a/tests/mir-opt/casts.redundant.PreCodegen.after.mir
+++ /dev/null
@@ -1,14 +0,0 @@
-// MIR for `redundant` after PreCodegen
-
-fn redundant(_1: *const &u8) -> *const &u8 {
-    debug x => _1;
-    let mut _0: *const &u8;
-    scope 1 (inlined generic_cast::<&u8, &u8>) {
-        debug x => _1;
-    }
-
-    bb0: {
-        _0 = _1;
-        return;
-    }
-}
diff --git a/tests/mir-opt/casts.roundtrip.PreCodegen.after.mir b/tests/mir-opt/casts.roundtrip.PreCodegen.after.mir
deleted file mode 100644
index f0c35fe9782..00000000000
--- a/tests/mir-opt/casts.roundtrip.PreCodegen.after.mir
+++ /dev/null
@@ -1,15 +0,0 @@
-// MIR for `roundtrip` after PreCodegen
-
-fn roundtrip(_1: *const u8) -> *const u8 {
-    debug x => _1;
-    let mut _0: *const u8;
-    let mut _2: *mut u8;
-
-    bb0: {
-        StorageLive(_2);
-        _2 = _1 as *mut u8 (PtrToPtr);
-        _0 = move _2 as *const u8 (PointerCoercion(MutToConstPointer));
-        StorageDead(_2);
-        return;
-    }
-}
diff --git a/tests/mir-opt/casts.rs b/tests/mir-opt/casts.rs
deleted file mode 100644
index c154aeace0f..00000000000
--- a/tests/mir-opt/casts.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-// skip-filecheck
-#![crate_type = "lib"]
-
-// EMIT_MIR casts.redundant.InstSimplify.diff
-// EMIT_MIR casts.redundant.PreCodegen.after.mir
-pub fn redundant<'a, 'b: 'a>(x: *const &'a u8) -> *const &'a u8 {
-    generic_cast::<&'a u8, &'b u8>(x) as *const &'a u8
-}
-
-#[inline]
-fn generic_cast<T, U>(x: *const T) -> *const U {
-    x as *const U
-}
-
-// EMIT_MIR casts.roundtrip.PreCodegen.after.mir
-pub fn roundtrip(x: *const u8) -> *const u8 {
-    x as *mut u8 as *const u8
-}
diff --git a/tests/mir-opt/casts.redundant.InstSimplify.diff b/tests/mir-opt/instsimplify/casts.redundant.InstSimplify.diff
index f5ea78aecbe..1c417d4346d 100644
--- a/tests/mir-opt/casts.redundant.InstSimplify.diff
+++ b/tests/mir-opt/instsimplify/casts.redundant.InstSimplify.diff
@@ -7,15 +7,19 @@
       let mut _2: *const &u8;
       let mut _3: *const &u8;
       scope 1 (inlined generic_cast::<&u8, &u8>) {
-          debug x => _1;
+          debug x => _3;
+          let mut _4: *const &u8;
       }
   
       bb0: {
           StorageLive(_2);
           StorageLive(_3);
           _3 = _1;
--         _2 = _3 as *const &u8 (PtrToPtr);
-+         _2 = _3;
+          StorageLive(_4);
+          _4 = _3;
+-         _2 = move _4 as *const &u8 (PtrToPtr);
++         _2 = move _4;
+          StorageDead(_4);
           StorageDead(_3);
           _0 = _2;
           StorageDead(_2);
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 00000000000..1ae9d45e66c
--- /dev/null
+++ b/tests/mir-opt/instsimplify/casts.roundtrip.InstSimplify.diff
@@ -0,0 +1,21 @@
+- // 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: *mut u8;
+      let mut _3: *const u8;
+  
+      bb0: {
+          StorageLive(_2);
+          StorageLive(_3);
+          _3 = _1;
+          _2 = move _3 as *mut u8 (PtrToPtr);
+          _0 = move _2 as *const u8 (PointerCoercion(MutToConstPointer));
+          StorageDead(_3);
+          StorageDead(_2);
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/instsimplify/casts.rs b/tests/mir-opt/instsimplify/casts.rs
new file mode 100644
index 00000000000..18bab524c64
--- /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: _3 = _1;
+    // CHECK: _2 = move _3 as *mut u8 (PtrToPtr);
+    // CHECK: _0 = move _2 as *const u8 (PointerCoercion(MutToConstPointer));
+    x as *mut u8 as *const u8
+}