4 ms·
The strict aliasing stuff allows you to do "optimisations" across translation units that are otherwise unsound. The compiler alias analysis is much more effect
by JonChesterfield 2y ago
The strict aliasing stuff allows you to do "optimisations" across translation units that are otherwise unsound.
The compiler alias analysis is much more effective than those rules permit within a translation unit because it matters whether int* alias other int*.
And then we have link time optimisation, at which point the much better alias analysis runs across the whole program.
What remains therefore is a language semantically compromised to help primitive compilers that no longer exist to emit slightly better code.
This is a deeply annoying state of affairs.
- saagarjha 2y agoAliasing analysis is quite helpful for sophisticated compilers to generate good code.
- matheusmoreira 2y agoAlias analysis is important. It's the C standard's type-based "strict aliasing" rules which are nonsense and should be disabled by default. This is C. Here in these lands, we do things like cast float* to int* so that we can do evil bit level manipulation. The compiler is just gonna have to put that in its pipeline and compile it.
- JonChesterfield 2y agoAlias analysis is critical. Knowing what loads and stores can alias one another is a prerequisite for reordering them, hoisting operations out of loops and so forth. Therefore the compiler needs to do that work - but it needs to do it on values that are the same type as each other, not only on types that happen to differ. Knowing that different types don't alias is a fast path in the analysis or a crutch for a lack of link time optimisation. The price is being unable to write code that does things like initialise an array using normal stores and then operates on it with atomic operations, implement some floating point operations, access network packets as structs, mmap hashtables from disk into C structs and so forth. An especially irritating one is the hostility to arrays that are sometimes a sequence of simd types and sometimes a sequence of uint64_ts. Though C++ is slowly accumulating enough escape hatches to work around that (launder et al), C is distinctly lacking in the same.