3 ms·
It is certainly possible to do structure layout optimizations (like converting from AOS to SOA) in C and its siblings. Even where the standard requires a specif
by gpderetta 10y ago
It is certainly possible to do structure layout optimizations (like converting from AOS to SOA) in C and its siblings. Even where the standard requires a specific layout, the compiler can optimize as long as it can prove that the code can't tell the difference (known as the as-if rule), although in the general case this requires whole program optimization.
This is not just a theoretical thing; at a certain point in the past, both LLVM and GCC had such an optimization, driven by PGO. I think it got removed because it just didn't trigger often enough and didn't give enough benefits to justify the complexity.
Scalar replacement of structs/arrays is of course routinely done by all major compilers and allows to completely optimize away non-escaping local objects.