Why does the Rust compiler not optimize code assuming that two mutable references cannot alias?
@lebyy▲ 0 net votes
Problem: 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 the case where the two references/pointers indeed alias. For instance, in the… Fix (from the top answer): 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…