summary refs log tree commit diff
path: root/tests/codegen/lib-optimizations
diff options
context:
space:
mode:
authoredwloef <edwin.frank.loeffler@gmail.com>2025-01-28 12:26:32 +0100
committeredwloef <edwin.frank.loeffler@gmail.com>2025-01-29 19:34:19 +0100
commitfb3d1d0c4bcd1b744c8ef23ba977bad9fcd43849 (patch)
treee462872232d47d6a8b903706c4b9d3d0ca05c9f9 /tests/codegen/lib-optimizations
parent311c3b71f0972e144cac91679a08906875c8af3f (diff)
downloadrust-fb3d1d0c4bcd1b744c8ef23ba977bad9fcd43849.tar.gz
rust-fb3d1d0c4bcd1b744c8ef23ba977bad9fcd43849.zip
add inline attribute and codegen test
Diffstat (limited to 'tests/codegen/lib-optimizations')
-rw-r--r--tests/codegen/lib-optimizations/slice_rotate.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/codegen/lib-optimizations/slice_rotate.rs b/tests/codegen/lib-optimizations/slice_rotate.rs
new file mode 100644
index 00000000000..d0a7b328d18
--- /dev/null
+++ b/tests/codegen/lib-optimizations/slice_rotate.rs
@@ -0,0 +1,30 @@
+//@ compile-flags: -O
+
+#![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);
+    }
+}