about summary refs log tree commit diff
path: root/tests/mir-opt/instsimplify
diff options
context:
space:
mode:
authorCamille Gillot <gillot.camille@gmail.com>2025-09-16 22:44:35 +0000
committerCamille Gillot <gillot.camille@gmail.com>2025-09-16 22:44:35 +0000
commitde73af9ec47552dcade86e4ebc4edb8a68fddd2e (patch)
tree8b0e46e5728f546fe32c2ba7a8d9d7c97ddc3f08 /tests/mir-opt/instsimplify
parentf018b46558c2c4049cf26bd88d562eefa69ff336 (diff)
Add test.
Diffstat (limited to 'tests/mir-opt/instsimplify')
-rw-r--r--tests/mir-opt/instsimplify/combine_array_len.normN.InstSimplify-after-simplifycfg.panic-abort.diff71
-rw-r--r--tests/mir-opt/instsimplify/combine_array_len.normN.InstSimplify-after-simplifycfg.panic-unwind.diff71
-rw-r--r--tests/mir-opt/instsimplify/combine_array_len.rs12
3 files changed, 153 insertions, 1 deletions
diff --git a/tests/mir-opt/instsimplify/combine_array_len.normN.InstSimplify-after-simplifycfg.panic-abort.diff b/tests/mir-opt/instsimplify/combine_array_len.normN.InstSimplify-after-simplifycfg.panic-abort.diff
new file mode 100644
index 00000000000..e9cb2c58177
--- /dev/null
+++ b/tests/mir-opt/instsimplify/combine_array_len.normN.InstSimplify-after-simplifycfg.panic-abort.diff
@@ -0,0 +1,71 @@
+- // MIR for `normN` before InstSimplify-after-simplifycfg
++ // MIR for `normN` after InstSimplify-after-simplifycfg
+  
+  fn normN(_1: [f32; N]) -> f32 {
+      debug x => _1;
+      let mut _0: f32;
+      let _2: f32;
+      let _3: usize;
+      let mut _4: bool;
+      let _6: usize;
+      let mut _7: bool;
+      let mut _8: f32;
+      let mut _9: f32;
+      let mut _10: f32;
+      let mut _11: f32;
+      let mut _12: f32;
+      let mut _13: f32;
+      scope 1 {
+          debug a => _2;
+          let _5: f32;
+          scope 2 {
+              debug b => _5;
+          }
+      }
+  
+      bb0: {
+          StorageLive(_2);
+          StorageLive(_3);
+          _3 = const 0_usize;
+          _4 = Lt(copy _3, const N);
+          assert(move _4, "index out of bounds: the length is {} but the index is {}", const N, copy _3) -> [success: bb1, unwind unreachable];
+      }
+  
+      bb1: {
+          _2 = copy _1[_3];
+          StorageDead(_3);
+          StorageLive(_5);
+          StorageLive(_6);
+          _6 = const 1_usize;
+          _7 = Lt(copy _6, const N);
+          assert(move _7, "index out of bounds: the length is {} but the index is {}", const N, copy _6) -> [success: bb2, unwind unreachable];
+      }
+  
+      bb2: {
+          _5 = copy _1[_6];
+          StorageDead(_6);
+          StorageLive(_8);
+          StorageLive(_9);
+          _9 = copy _2;
+          StorageLive(_10);
+          _10 = copy _2;
+          _8 = Mul(move _9, move _10);
+          StorageDead(_10);
+          StorageDead(_9);
+          StorageLive(_11);
+          StorageLive(_12);
+          _12 = copy _5;
+          StorageLive(_13);
+          _13 = copy _5;
+          _11 = Mul(move _12, move _13);
+          StorageDead(_13);
+          StorageDead(_12);
+          _0 = Add(move _8, move _11);
+          StorageDead(_11);
+          StorageDead(_8);
+          StorageDead(_5);
+          StorageDead(_2);
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/instsimplify/combine_array_len.normN.InstSimplify-after-simplifycfg.panic-unwind.diff b/tests/mir-opt/instsimplify/combine_array_len.normN.InstSimplify-after-simplifycfg.panic-unwind.diff
new file mode 100644
index 00000000000..0ddc70f2003
--- /dev/null
+++ b/tests/mir-opt/instsimplify/combine_array_len.normN.InstSimplify-after-simplifycfg.panic-unwind.diff
@@ -0,0 +1,71 @@
+- // MIR for `normN` before InstSimplify-after-simplifycfg
++ // MIR for `normN` after InstSimplify-after-simplifycfg
+  
+  fn normN(_1: [f32; N]) -> f32 {
+      debug x => _1;
+      let mut _0: f32;
+      let _2: f32;
+      let _3: usize;
+      let mut _4: bool;
+      let _6: usize;
+      let mut _7: bool;
+      let mut _8: f32;
+      let mut _9: f32;
+      let mut _10: f32;
+      let mut _11: f32;
+      let mut _12: f32;
+      let mut _13: f32;
+      scope 1 {
+          debug a => _2;
+          let _5: f32;
+          scope 2 {
+              debug b => _5;
+          }
+      }
+  
+      bb0: {
+          StorageLive(_2);
+          StorageLive(_3);
+          _3 = const 0_usize;
+          _4 = Lt(copy _3, const N);
+          assert(move _4, "index out of bounds: the length is {} but the index is {}", const N, copy _3) -> [success: bb1, unwind continue];
+      }
+  
+      bb1: {
+          _2 = copy _1[_3];
+          StorageDead(_3);
+          StorageLive(_5);
+          StorageLive(_6);
+          _6 = const 1_usize;
+          _7 = Lt(copy _6, const N);
+          assert(move _7, "index out of bounds: the length is {} but the index is {}", const N, copy _6) -> [success: bb2, unwind continue];
+      }
+  
+      bb2: {
+          _5 = copy _1[_6];
+          StorageDead(_6);
+          StorageLive(_8);
+          StorageLive(_9);
+          _9 = copy _2;
+          StorageLive(_10);
+          _10 = copy _2;
+          _8 = Mul(move _9, move _10);
+          StorageDead(_10);
+          StorageDead(_9);
+          StorageLive(_11);
+          StorageLive(_12);
+          _12 = copy _5;
+          StorageLive(_13);
+          _13 = copy _5;
+          _11 = Mul(move _12, move _13);
+          StorageDead(_13);
+          StorageDead(_12);
+          _0 = Add(move _8, move _11);
+          StorageDead(_11);
+          StorageDead(_8);
+          StorageDead(_5);
+          StorageDead(_2);
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/instsimplify/combine_array_len.rs b/tests/mir-opt/instsimplify/combine_array_len.rs
index 91f43f75689..1c4d42d3bbe 100644
--- a/tests/mir-opt/instsimplify/combine_array_len.rs
+++ b/tests/mir-opt/instsimplify/combine_array_len.rs
@@ -4,7 +4,16 @@
 // EMIT_MIR combine_array_len.norm2.InstSimplify-after-simplifycfg.diff
 fn norm2(x: [f32; 2]) -> f32 {
     // CHECK-LABEL: fn norm2(
-    // CHECK-NOT: Len(
+    // CHECK-NOT: PtrMetadata(
+    let a = x[0];
+    let b = x[1];
+    a * a + b * b
+}
+
+// EMIT_MIR combine_array_len.normN.InstSimplify-after-simplifycfg.diff
+fn normN<const N: usize>(x: [f32; N]) -> f32 {
+    // CHECK-LABEL: fn normN(
+    // CHECK-NOT: PtrMetadata(
     let a = x[0];
     let b = x[1];
     a * a + b * b
@@ -12,4 +21,5 @@ fn norm2(x: [f32; 2]) -> f32 {
 
 fn main() {
     assert_eq!(norm2([3.0, 4.0]), 5.0 * 5.0);
+    assert_eq!(normN([3.0, 4.0]), 5.0 * 5.0);
 }