Merge redundant loops.