rust/tests/codegen/lib-optimizations/iter-sum.rs

15 lines
390 B
Rust

// ignore-debug: the debug assertions get in the way
// compile-flags: -O
#![crate_type = "lib"]
// Ensure that slice + take + sum gets vectorized.
// Currently this relies on the slice::Iter::try_fold implementation
// CHECK-LABEL: @slice_take_sum
#[no_mangle]
pub fn slice_take_sum(s: &[u64], l: usize) -> u64 {
// CHECK: vector.body:
// CHECK: ret
s.iter().take(l).sum()
}