From JoS: Cache optimization
On Joel on Software, Art Wilkins says:
I don't think there are any compilers that optimize for caches, that is something you have do do on your own.
One of my pet peeves is when I hear some expert proclaim "Of course, any decent optimizing compiler will do this." when there are no compilers that will do it and how exactly to do it is not even a solved problem, or is something known to be NP complete.