2024-02-23 17:04:01 -06:00
|
|
|
//@ ignore-debug: FIXME: checks for call detect scoped noalias metadata
|
2022-04-05 13:58:36 -05:00
|
|
|
//@ compile-flags: -O -Z merge-functions=disabled
|
2020-12-08 18:08:11 -06:00
|
|
|
#![crate_type = "lib"]
|
|
|
|
|
|
|
|
// Ensure that trivial casts of vec elements are O(1)
|
|
|
|
|
2022-04-05 13:58:36 -05:00
|
|
|
pub struct Wrapper<T>(T);
|
|
|
|
|
2023-04-03 08:29:46 -05:00
|
|
|
// previously repr(C) caused the optimization to fail
|
2022-04-05 13:58:36 -05:00
|
|
|
#[repr(C)]
|
|
|
|
pub struct Foo {
|
|
|
|
a: u64,
|
|
|
|
b: u64,
|
|
|
|
c: u64,
|
|
|
|
d: u64,
|
|
|
|
}
|
|
|
|
|
2023-04-03 08:29:46 -05:00
|
|
|
// implementing Copy exercises the TrustedRandomAccess specialization inside the in-place
|
|
|
|
// specialization
|
2022-04-05 13:58:36 -05:00
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
pub struct Bar {
|
|
|
|
a: u64,
|
|
|
|
b: u64,
|
|
|
|
c: u64,
|
|
|
|
d: u64,
|
|
|
|
}
|
|
|
|
|
2023-04-03 08:29:46 -05:00
|
|
|
// this exercises the try-fold codepath
|
|
|
|
pub struct Baz {
|
|
|
|
a: u64,
|
|
|
|
b: u64,
|
|
|
|
c: u64,
|
|
|
|
d: u64,
|
|
|
|
}
|
|
|
|
|
2022-04-05 13:58:36 -05:00
|
|
|
// CHECK-LABEL: @vec_iterator_cast_primitive
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn vec_iterator_cast_primitive(vec: Vec<i8>) -> Vec<u8> {
|
|
|
|
// CHECK-NOT: loop
|
|
|
|
// CHECK-NOT: call
|
|
|
|
vec.into_iter().map(|e| e as u8).collect()
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @vec_iterator_cast_wrapper
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn vec_iterator_cast_wrapper(vec: Vec<u8>) -> Vec<Wrapper<u8>> {
|
|
|
|
// CHECK-NOT: loop
|
|
|
|
// CHECK-NOT: call
|
|
|
|
vec.into_iter().map(|e| Wrapper(e)).collect()
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @vec_iterator_cast_unwrap
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn vec_iterator_cast_unwrap(vec: Vec<Wrapper<u8>>) -> Vec<u8> {
|
|
|
|
// CHECK-NOT: loop
|
|
|
|
// CHECK-NOT: call
|
|
|
|
vec.into_iter().map(|e| e.0).collect()
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @vec_iterator_cast_aggregate
|
2020-12-08 18:08:11 -06:00
|
|
|
#[no_mangle]
|
2022-04-05 13:58:36 -05:00
|
|
|
pub fn vec_iterator_cast_aggregate(vec: Vec<[u64; 4]>) -> Vec<Foo> {
|
2023-04-03 08:29:46 -05:00
|
|
|
// CHECK-NOT: loop
|
|
|
|
// CHECK-NOT: call
|
2022-04-05 13:58:36 -05:00
|
|
|
vec.into_iter().map(|e| unsafe { std::mem::transmute(e) }).collect()
|
|
|
|
}
|
|
|
|
|
2023-04-03 08:29:46 -05:00
|
|
|
// CHECK-LABEL: @vec_iterator_cast_deaggregate_tra
|
2022-04-05 13:58:36 -05:00
|
|
|
#[no_mangle]
|
2023-04-03 08:29:46 -05:00
|
|
|
pub fn vec_iterator_cast_deaggregate_tra(vec: Vec<Bar>) -> Vec<[u64; 4]> {
|
|
|
|
// CHECK-NOT: loop
|
|
|
|
// CHECK-NOT: call
|
|
|
|
|
|
|
|
// Safety: For the purpose of this test we assume that Bar layout matches [u64; 4].
|
|
|
|
// This currently is not guaranteed for repr(Rust) types, but it happens to work here and
|
|
|
|
// the UCG may add additional guarantees for homogenous types in the future that would make this
|
|
|
|
// correct.
|
|
|
|
vec.into_iter().map(|e| unsafe { std::mem::transmute(e) }).collect()
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @vec_iterator_cast_deaggregate_fold
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn vec_iterator_cast_deaggregate_fold(vec: Vec<Baz>) -> Vec<[u64; 4]> {
|
|
|
|
// CHECK-NOT: loop
|
|
|
|
// CHECK-NOT: call
|
2022-04-05 13:58:36 -05:00
|
|
|
|
|
|
|
// Safety: For the purpose of this test we assume that Bar layout matches [u64; 4].
|
|
|
|
// This currently is not guaranteed for repr(Rust) types, but it happens to work here and
|
|
|
|
// the UCG may add additional guarantees for homogenous types in the future that would make this
|
|
|
|
// correct.
|
|
|
|
vec.into_iter().map(|e| unsafe { std::mem::transmute(e) }).collect()
|
2020-12-08 18:08:11 -06:00
|
|
|
}
|
2024-05-19 19:10:45 -05:00
|
|
|
|
|
|
|
// CHECK-LABEL: @vec_iterator_cast_unwrap_drop
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn vec_iterator_cast_unwrap_drop(vec: Vec<Wrapper<String>>) -> Vec<String> {
|
|
|
|
// CHECK-NOT: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
|
|
|
|
// CHECK-NOT: call
|
|
|
|
// CHECK-NOT: %{{.*}} = mul
|
|
|
|
// CHECK-NOT: %{{.*}} = udiv
|
|
|
|
|
|
|
|
vec.into_iter().map(|Wrapper(e)| e).collect()
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @vec_iterator_cast_wrap_drop
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn vec_iterator_cast_wrap_drop(vec: Vec<String>) -> Vec<Wrapper<String>> {
|
|
|
|
// CHECK-NOT: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
|
|
|
|
// CHECK-NOT: call
|
|
|
|
// CHECK-NOT: %{{.*}} = mul
|
|
|
|
// CHECK-NOT: %{{.*}} = udiv
|
|
|
|
|
|
|
|
vec.into_iter().map(Wrapper).collect()
|
|
|
|
}
|