As far as I know, reference/pointer aliasing can hinder the compiler\'s ability to generate optimized code, since they must ensure the generated binary behaves correctly in
Rust originally did enable LLVM's noalias attribute, but this caused miscompiled code. When all supported LLVM versions no longer miscompile the code, it will be re-enabled.
If you add -Zmutable-noalias=yes to the compiler options, you get the expected assembly:
adds:
mov eax, dword ptr [rsi]
add eax, eax
add dword ptr [rdi], eax
ret
Simply put, Rust put the equivalent of C's restrict keyword everywhere, far more prevalent than any usual C program. This exercised corner cases of LLVM more than it was able to handle correctly. It turns out that C and C++ programmers simply don't use restrict as frequently as &mut is used in Rust.
This has happened multiple times.
noalias enablednoalias disablednoalias enablednoalias disabledCurrent case
Previous case
Other