Check memory access patterns for the outer loop

This loop has inefficient memory access patterns. If the memory access patterns are more efficient for the outer loop, reorder the loops if possible.