This paper presents a novel approach which integrates both structure layout optimization and array flattening in a unified compiler framework to improve memory locality and reduce required memory bandwidth. The proposed compiler framework includes alias group-wise safety analysis, memory layout profitability analysis and memory layout transformations. The alias group-wise safety analysis is proposed to process the candidates of structure layout optimization and array flattening in a unified framework. The alias group-wise approach could expose more opportunities for structure layout optimization and array flattening. The profitability analysis including array dimension reordering and structure layout profitability analysis tries to select a profitable data layout that enables more structure layout optimizations as well as array flattening to exploit more data locality. Experimental results show that the implemented framework delivers significant performance gain for memory intensive programs in CPU2006 and OMP2001 suites.