Fix a issue in double loop optimization.