2023-02-26 06:47:20 +00:00
|
|
|
// compile-flags: -O -Zmerge-functions=disabled
|
|
|
|
// ignore-debug (the extra assertions get in the way)
|
2020-12-26 06:43:51 +00:00
|
|
|
|
|
|
|
#![crate_type = "lib"]
|
|
|
|
|
2023-02-26 06:47:20 +00:00
|
|
|
use std::num::{NonZeroI16, NonZeroU32};
|
|
|
|
|
2021-05-30 17:25:41 +00:00
|
|
|
// #71602 reported a simple array comparison just generating a loop.
|
|
|
|
// This was originally fixed by ensuring it generates a single bcmp,
|
2021-12-11 23:29:52 +00:00
|
|
|
// but we now generate it as a load+icmp instead. `is_zero_slice` was
|
2021-05-30 17:25:41 +00:00
|
|
|
// tweaked to still test the case of comparison against a slice,
|
|
|
|
// and `is_zero_array` tests the new array-specific behaviour.
|
2021-12-11 23:29:52 +00:00
|
|
|
// 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.
|
2020-12-26 06:43:51 +00:00
|
|
|
|
2021-12-11 23:29:52 +00:00
|
|
|
// CHECK-LABEL: @is_zero_slice_long
|
2020-12-26 06:43:51 +00:00
|
|
|
#[no_mangle]
|
2021-12-11 23:29:52 +00:00
|
|
|
pub fn is_zero_slice_long(data: &[u8; 456]) -> bool {
|
2022-02-21 10:21:23 +00:00
|
|
|
// CHECK: %[[BCMP:.+]] = tail call i32 @{{bcmp|memcmp}}({{.+}})
|
2020-12-26 06:43:51 +00:00
|
|
|
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[BCMP]], 0
|
|
|
|
// CHECK-NEXT: ret i1 %[[EQ]]
|
2021-12-11 23:29:52 +00:00
|
|
|
&data[..] == [0; 456]
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @is_zero_slice_short
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn is_zero_slice_short(data: &[u8; 4]) -> bool {
|
2023-07-27 21:44:13 +00:00
|
|
|
// CHECK: %[[LOAD:.+]] = load i32, ptr %{{.+}}, align 1
|
2021-12-11 23:29:52 +00:00
|
|
|
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[LOAD]], 0
|
|
|
|
// CHECK-NEXT: ret i1 %[[EQ]]
|
2021-05-30 17:25:41 +00:00
|
|
|
&data[..] == [0; 4]
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @is_zero_array
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn is_zero_array(data: &[u8; 4]) -> bool {
|
2023-07-27 21:44:13 +00:00
|
|
|
// CHECK: %[[LOAD:.+]] = load i32, ptr %{{.+}}, align 1
|
2021-05-30 17:25:41 +00:00
|
|
|
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[LOAD]], 0
|
|
|
|
// CHECK-NEXT: ret i1 %[[EQ]]
|
2020-12-26 06:43:51 +00:00
|
|
|
*data == [0; 4]
|
|
|
|
}
|
2023-02-26 06:47:20 +00:00
|
|
|
|
|
|
|
// The following test the extra specializations to make sure that slice
|
|
|
|
// equality for non-byte types also just emit a `bcmp`, not a loop.
|
|
|
|
|
|
|
|
// CHECK-LABEL: @eq_slice_of_nested_u8(
|
2023-08-17 18:28:33 +00:00
|
|
|
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
|
|
|
|
// CHECK-SAME: [[USIZE]] noundef %3
|
2023-02-26 06:47:20 +00:00
|
|
|
#[no_mangle]
|
|
|
|
fn eq_slice_of_nested_u8(x: &[[u8; 3]], y: &[[u8; 3]]) -> bool {
|
2023-08-17 18:28:33 +00:00
|
|
|
// CHECK: icmp eq [[USIZE]] %1, %3
|
|
|
|
// CHECK: %[[BYTES:.+]] = mul nsw [[USIZE]] %1, 3
|
2023-07-27 21:44:13 +00:00
|
|
|
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr
|
2023-02-26 06:47:20 +00:00
|
|
|
// CHECK-SAME: , [[USIZE]]{{( noundef)?}} %[[BYTES]])
|
|
|
|
x == y
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @eq_slice_of_i32(
|
2023-08-17 18:28:33 +00:00
|
|
|
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
|
|
|
|
// CHECK-SAME: [[USIZE]] noundef %3
|
2023-02-26 06:47:20 +00:00
|
|
|
#[no_mangle]
|
|
|
|
fn eq_slice_of_i32(x: &[i32], y: &[i32]) -> bool {
|
2023-08-17 18:28:33 +00:00
|
|
|
// CHECK: icmp eq [[USIZE]] %1, %3
|
|
|
|
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 2
|
2023-07-27 21:44:13 +00:00
|
|
|
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr
|
2023-02-26 06:47:20 +00:00
|
|
|
// CHECK-SAME: , [[USIZE]]{{( noundef)?}} %[[BYTES]])
|
|
|
|
x == y
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @eq_slice_of_nonzero(
|
2023-08-17 18:28:33 +00:00
|
|
|
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
|
|
|
|
// CHECK-SAME: [[USIZE]] noundef %3
|
2023-02-26 06:47:20 +00:00
|
|
|
#[no_mangle]
|
|
|
|
fn eq_slice_of_nonzero(x: &[NonZeroU32], y: &[NonZeroU32]) -> bool {
|
2023-08-17 18:28:33 +00:00
|
|
|
// CHECK: icmp eq [[USIZE]] %1, %3
|
|
|
|
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 2
|
2023-07-27 21:44:13 +00:00
|
|
|
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr
|
2023-02-26 06:47:20 +00:00
|
|
|
// CHECK-SAME: , [[USIZE]]{{( noundef)?}} %[[BYTES]])
|
|
|
|
x == y
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @eq_slice_of_option_of_nonzero(
|
2023-08-17 18:28:33 +00:00
|
|
|
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
|
|
|
|
// CHECK-SAME: [[USIZE]] noundef %3
|
2023-02-26 06:47:20 +00:00
|
|
|
#[no_mangle]
|
|
|
|
fn eq_slice_of_option_of_nonzero(x: &[Option<NonZeroI16>], y: &[Option<NonZeroI16>]) -> bool {
|
2023-08-17 18:28:33 +00:00
|
|
|
// CHECK: icmp eq [[USIZE]] %1, %3
|
|
|
|
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 1
|
2023-07-27 21:44:13 +00:00
|
|
|
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr
|
2023-02-26 06:47:20 +00:00
|
|
|
// CHECK-SAME: , [[USIZE]]{{( noundef)?}} %[[BYTES]])
|
|
|
|
x == y
|
|
|
|
}
|