summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-05-13 03:09:05 +0000
committerbors <bors@rust-lang.org>2023-05-13 03:09:05 +0000
commit16d3e18281fde75eb6c62ebb8363af28de8a3ef0 (patch)
treeeab54d309d3dabf34f985b9871ea384ac8c7344f /tests/codegen
parent9850584a4e5e4b7e5cebd9d90c27d8b88591f264 (diff)
parentc50a2e1d1742ca290aed840fb5273662b209b936 (diff)
downloadrust-16d3e18281fde75eb6c62ebb8363af28de8a3ef0.tar.gz
rust-16d3e18281fde75eb6c62ebb8363af28de8a3ef0.zip
Auto merge of #111447 - scottmcm:remove-more-assumes, r=thomcc
Remove useless `assume`s from `slice::iter(_mut)`

You were right in https://github.com/rust-lang/rust/pull/111395#discussion_r1190312704,
r? `@the8472`

LLVM already removes these assumes while optimizing, as can be seen in <https://rust.godbolt.org/z/KTfWKbdEM>.
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/slice-iter-nonnull.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/codegen/slice-iter-nonnull.rs b/tests/codegen/slice-iter-nonnull.rs
index 392e4338076..997bdaf5636 100644
--- a/tests/codegen/slice-iter-nonnull.rs
+++ b/tests/codegen/slice-iter-nonnull.rs
@@ -40,3 +40,38 @@ pub fn slice_iter_next_back<'a>(it: &mut std::slice::Iter<'a, u32>) -> Option<&'
 
     it.next_back()
 }
+
+// The slice iterator `new` methods used to `assume` that the pointer is non-null,
+// but passing slices already requires that, to the extent that LLVM actually
+// removed the `call @llvm.assume` anyway.  These tests just demonstrate that the
+// attribute is there, and confirms adding the assume back doesn't do anything.
+
+// CHECK-LABEL: @slice_iter_new
+// CHECK-SAME: (ptr noalias noundef nonnull {{.+}} %slice.0, {{.+}} noundef %slice.1)
+#[no_mangle]
+pub fn slice_iter_new(slice: &[u32]) -> std::slice::Iter<'_, u32> {
+    // CHECK-NOT: slice
+    // CHECK: %[[END:.+]] = getelementptr inbounds i32{{.+}} %slice.0{{.+}} %slice.1
+    // CHECK-NOT: slice
+    // CHECK: insertvalue {{.+}} ptr %slice.0, 0
+    // CHECK-NOT: slice
+    // CHECK: insertvalue {{.+}} ptr %[[END]], 1
+    // CHECK-NOT: slice
+    // CHECK: }
+    slice.iter()
+}
+
+// CHECK-LABEL: @slice_iter_mut_new
+// CHECK-SAME: (ptr noalias noundef nonnull {{.+}} %slice.0, {{.+}} noundef %slice.1)
+#[no_mangle]
+pub fn slice_iter_mut_new(slice: &mut [u32]) -> std::slice::IterMut<'_, u32> {
+    // CHECK-NOT: slice
+    // CHECK: %[[END:.+]] = getelementptr inbounds i32{{.+}} %slice.0{{.+}} %slice.1
+    // CHECK-NOT: slice
+    // CHECK: insertvalue {{.+}} ptr %slice.0, 0
+    // CHECK-NOT: slice
+    // CHECK: insertvalue {{.+}} ptr %[[END]], 1
+    // CHECK-NOT: slice
+    // CHECK: }
+    slice.iter_mut()
+}