summaryrefslogtreecommitdiffstats
path: root/tests/codegen/slice-ref-equality.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
commita4b7ed7a42c716ab9f05e351f003d589124fd55d (patch)
treeb620cd3f223850b28716e474e80c58059dca5dd4 /tests/codegen/slice-ref-equality.rs
parentAdding upstream version 1.67.1+dfsg1. (diff)
downloadrustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.tar.xz
rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.zip
Adding upstream version 1.68.2+dfsg1.upstream/1.68.2+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/codegen/slice-ref-equality.rs')
-rw-r--r--tests/codegen/slice-ref-equality.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/codegen/slice-ref-equality.rs b/tests/codegen/slice-ref-equality.rs
new file mode 100644
index 000000000..47fde12bf
--- /dev/null
+++ b/tests/codegen/slice-ref-equality.rs
@@ -0,0 +1,38 @@
+// compile-flags: -C opt-level=3 -Zmerge-functions=disabled
+
+#![crate_type = "lib"]
+
+// #71602 reported a simple array comparison just generating a loop.
+// This was originally fixed by ensuring it generates a single bcmp,
+// but we now generate it as a load+icmp instead. `is_zero_slice` was
+// tweaked to still test the case of comparison against a slice,
+// and `is_zero_array` tests the new array-specific behaviour.
+// The optimization was then extended to short slice-to-array comparisons,
+// so the first test here now has a long slice to still get the bcmp.
+
+// CHECK-LABEL: @is_zero_slice_long
+#[no_mangle]
+pub fn is_zero_slice_long(data: &[u8; 456]) -> bool {
+ // CHECK: %[[BCMP:.+]] = tail call i32 @{{bcmp|memcmp}}({{.+}})
+ // CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[BCMP]], 0
+ // CHECK-NEXT: ret i1 %[[EQ]]
+ &data[..] == [0; 456]
+}
+
+// CHECK-LABEL: @is_zero_slice_short
+#[no_mangle]
+pub fn is_zero_slice_short(data: &[u8; 4]) -> bool {
+ // CHECK: %[[LOAD:.+]] = load i32, {{i32\*|ptr}} %{{.+}}, align 1
+ // CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[LOAD]], 0
+ // CHECK-NEXT: ret i1 %[[EQ]]
+ &data[..] == [0; 4]
+}
+
+// CHECK-LABEL: @is_zero_array
+#[no_mangle]
+pub fn is_zero_array(data: &[u8; 4]) -> bool {
+ // CHECK: %[[LOAD:.+]] = load i32, {{i32\*|ptr}} %{{.+}}, align 1
+ // CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[LOAD]], 0
+ // CHECK-NEXT: ret i1 %[[EQ]]
+ *data == [0; 4]
+}