From a27f3e3fd1e4d16160f8885b6b06665b5319f56c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 21 Jul 2025 14:34:12 +0200 Subject: Rename `tests/codegen` into `tests/codegen-llvm` --- tests/codegen-llvm/lib-optimizations/iter-sum.rs | 13 ++++++++++ .../codegen-llvm/lib-optimizations/slice_rotate.rs | 30 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/codegen-llvm/lib-optimizations/iter-sum.rs create mode 100644 tests/codegen-llvm/lib-optimizations/slice_rotate.rs (limited to 'tests/codegen-llvm/lib-optimizations') diff --git a/tests/codegen-llvm/lib-optimizations/iter-sum.rs b/tests/codegen-llvm/lib-optimizations/iter-sum.rs new file mode 100644 index 00000000000..a054ffffe74 --- /dev/null +++ b/tests/codegen-llvm/lib-optimizations/iter-sum.rs @@ -0,0 +1,13 @@ +//@ compile-flags: -Copt-level=3 +//@ only-x86_64 (vectorization varies between architectures) +#![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() +} diff --git a/tests/codegen-llvm/lib-optimizations/slice_rotate.rs b/tests/codegen-llvm/lib-optimizations/slice_rotate.rs new file mode 100644 index 00000000000..aa4bb3b528c --- /dev/null +++ b/tests/codegen-llvm/lib-optimizations/slice_rotate.rs @@ -0,0 +1,30 @@ +//@ compile-flags: -Copt-level=3 + +#![crate_type = "lib"] + +// Ensure that the simple case of rotating by a constant 1 optimizes to the obvious thing + +// CHECK-LABEL: @rotate_left_by_one +#[no_mangle] +pub fn rotate_left_by_one(slice: &mut [i32]) { + // CHECK-NOT: phi + // CHECK-NOT: call + // CHECK-NOT: load + // CHECK-NOT: store + // CHECK-NOT: getelementptr + // CHECK: %[[END:.+]] = getelementptr + // CHECK-NEXT: %[[DIM:.+]] = getelementptr + // CHECK-NEXT: %[[LAST:.+]] = load + // CHECK-NEXT: %[[FIRST:.+]] = shl + // CHECK-NEXT: call void @llvm.memmove + // CHECK-NEXT: store i32 %[[LAST]], ptr %[[DIM:.+]] + // CHECK-NOT: phi + // CHECK-NOT: call + // CHECK-NOT: load + // CHECK-NOT: store + // CHECK-NOT: getelementptr + // CHECK: ret void + if !slice.is_empty() { + slice.rotate_left(1); + } +} -- cgit 1.4.1-3-g733a5