With certain condition of phi node, LoopSimplify pass converts loop with multiple latches to a nested loop as below.
// Loop with multiple latches // // | /----------------\ // +--------v----v------+ | // | header <---\ | // +--------------------+ | | // | | | // +--------v-----------+ | | // | latch1 >---/ | // +--------------------+ | // | | // +--------v-----------+ | // | latch2 >----------/ // +--------------------+ // | //==============================> // // A nested loop // // | /----------------\ // +-------------v------+ | // | outer header | | // +--------------------+ | // | | // +--------v----v------+ | // | inner header <---\ | // +--------------------+ | | // | | | // +--------v-----------+ | | // | latch1 >---/ | // +--------------------+ | // | | // +--------v-----------+ | // | latch2 >----------/ // +--------------------+ // |
This patch enables above transformation more using dominator tree. If one latch dominates other latches, the latch can be inner loop's one.