3 ms·
For a compiler to properly do the optimization detailed here would require it to have knowledge of runtime execution/memory access patterns. This might be done
by 10000truths 5y ago
For a compiler to properly do the optimization detailed here would require it to have knowledge of runtime execution/memory access patterns. This might be done through profile-guided optimization, or by providing hints like __builtin_expect.
That said, compilers are not magic boxes. Relying on your compiler for optimal codegen has diminishing returns as you approach the point where microarchitectural details start making a difference. Most people don't get to that point, so it's rarely an issue.