Open
Description
I tried this code:
pub fn bar(count: &mut usize, n: usize) {
for i in 0..n {
*count = count.wrapping_add(1);
}
}
I expected to see this happen:
example::bar:
add qword ptr [rdi], rsi
ret
Instead, this happened:
example::bar:
test rsi, rsi
je .LBB1_2
add qword ptr [rdi], rsi
.LBB1_2:
ret
The missed branch is going to be much more expansive than throwing something in a store buffer. Maybe you could argue the compiler thinks n=0 is going to be common, but I find that unlikely.
I'm pretty sure Rust's ownership system allows inserting stores that didn't exist because an &mut
can't be used on another thread.