about summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2024-04-14 11:15:00 -0400
committerMark Rousskov <mark.simulacrum@gmail.com>2024-04-20 21:07:00 -0400
commitf1ae5314bef94f1defe868cb5d78d15b5da31c8c (patch)
tree340f0c989216cc1fdf29d0f9c3ad3004ce8d23dd /tests/codegen
parentc3ceb00281f9557dcf5bba54fc44c9931cc90d42 (diff)
downloadrust-f1ae5314bef94f1defe868cb5d78d15b5da31c8c.tar.gz
rust-f1ae5314bef94f1defe868cb5d78d15b5da31c8c.zip
Avoid reloading Vec::len across grow_one in push
This saves an extra load from memory.
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/vec-len-invariant.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/codegen/vec-len-invariant.rs b/tests/codegen/vec-len-invariant.rs
new file mode 100644
index 00000000000..780c86bab95
--- /dev/null
+++ b/tests/codegen/vec-len-invariant.rs
@@ -0,0 +1,16 @@
+//@ compile-flags: -O
+//@ only-64bit
+//
+// This test confirms that we do not reload the length of a Vec after growing it in push.
+
+#![crate_type = "lib"]
+
+// CHECK-LABEL: @should_load_once
+#[no_mangle]
+pub fn should_load_once(v: &mut Vec<u8>) {
+    // CHECK: load i64
+    // CHECK: call {{.*}}grow_one
+    // CHECK-NOT: load i64
+    // CHECK: add {{.*}}, 1
+    v.push(1);
+}