Avoid reloading Vec::len across grow_one in push
This saves an extra load from memory.
This commit is contained in:
parent
c3ceb00281
commit
f1ae5314be
2 changed files with 21 additions and 3 deletions
16
tests/codegen/vec-len-invariant.rs
Normal file
16
tests/codegen/vec-len-invariant.rs
Normal file
|
@ -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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue