This is a very active area of research.
CGO, one of the main compiler conference, has had many papers on memory and data optimization in the past 5 years, and PLDI did before that.
Google for "structure layout optimization compiler", "Data structure optimization compiler", "polyhedral loop optimization compiler".
Compilers have been studying and doing data and loop reordering (for memory optimization) optimizations for many many years.
In fact, some of these are even famous (http://www.hpcwire.com/hpcwire/2007-11-09/compilers_and_more...). Look at the art hack.
This is a very active area of research. CGO, one of the main compiler conference, has had many papers on memory and data optimization in the past 5 years, and PLDI did before that.
Google for "structure layout optimization compiler", "Data structure optimization compiler", "polyhedral loop optimization compiler".