about summary refs log tree commit diff
path: root/tests/codegen/array-equality.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-03-01 23:34:37 +0000
committerbors <bors@rust-lang.org>2023-03-01 23:34:37 +0000
commit0b4ba4cf0ed52bb4f1ff9436b9a887fd5f049e6b (patch)
tree638e6a20a40832bb6f9bab1086b225a6ab44111b /tests/codegen/array-equality.rs
parentf77bfb7336f21bfe6a5fb5f7358d4406e2597289 (diff)
parent44eec1d9b0eaf7375994fff39b1150539f215f1a (diff)
downloadrust-0b4ba4cf0ed52bb4f1ff9436b9a887fd5f049e6b.tar.gz
rust-0b4ba4cf0ed52bb4f1ff9436b9a887fd5f049e6b.zip
Auto merge of #108483 - scottmcm:unify-bytewise-eq-traits, r=the8472
Merge two different equality specialization traits in `core`

Arrays and slices each had their own version of this, without a matching set of `impl`s.

Merge them into one (still-`pub(crate)`) `cmp::BytewiseEq` trait, so we can stop doing all these things twice.

And that means that the `[T]::eq` → `memcmp` specialization picks up a bunch of types where that previously only worked for arrays, so examples like <https://rust.godbolt.org/z/KjsG8MGGT> will use it now instead of emitting loops.

r? the8472
Diffstat (limited to 'tests/codegen/array-equality.rs')
-rw-r--r--tests/codegen/array-equality.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/codegen/array-equality.rs b/tests/codegen/array-equality.rs
index cd5e82a9205..abfe295f8b6 100644
--- a/tests/codegen/array-equality.rs
+++ b/tests/codegen/array-equality.rs
@@ -1,4 +1,4 @@
-// compile-flags: -O
+// compile-flags: -O -Z merge-functions=disabled
 // only-x86_64
 
 #![crate_type = "lib"]
@@ -43,6 +43,15 @@ pub fn array_eq_long(a: &[u16; 1234], b: &[u16; 1234]) -> bool {
     a == b
 }
 
+// CHECK-LABEL: @array_char_eq
+#[no_mangle]
+pub fn array_char_eq(a: [char; 2], b: [char; 2]) -> bool {
+    // CHECK-NEXT: start:
+    // CHECK-NEXT: %[[EQ:.+]] = icmp eq i64 %0, %1
+    // CHECK-NEXT: ret i1 %[[EQ]]
+    a == b
+}
+
 // CHECK-LABEL: @array_eq_zero_short(i48
 #[no_mangle]
 pub fn array_eq_zero_short(x: [u16; 3]) -> bool {
@@ -52,6 +61,25 @@ pub fn array_eq_zero_short(x: [u16; 3]) -> bool {
     x == [0; 3]
 }
 
+// CHECK-LABEL: @array_eq_none_short(i40
+#[no_mangle]
+pub fn array_eq_none_short(x: [Option<std::num::NonZeroU8>; 5]) -> bool {
+    // CHECK-NEXT: start:
+    // CHECK-NEXT: %[[EQ:.+]] = icmp eq i40 %0, 0
+    // CHECK-NEXT: ret i1 %[[EQ]]
+    x == [None; 5]
+}
+
+// CHECK-LABEL: @array_eq_zero_nested(
+#[no_mangle]
+pub fn array_eq_zero_nested(x: [[u8; 3]; 3]) -> bool {
+    // CHECK: %[[VAL:.+]] = load i72
+    // CHECK-SAME: align 1
+    // CHECK: %[[EQ:.+]] = icmp eq i72 %[[VAL]], 0
+    // CHECK: ret i1 %[[EQ]]
+    x == [[0; 3]; 3]
+}
+
 // CHECK-LABEL: @array_eq_zero_mid(
 #[no_mangle]
 pub fn array_eq_zero_mid(x: [u16; 8]) -> bool {