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.
clang-tidy: warning: invalid case style for variable 'i' [readability-identifier-naming]
not useful
clang-tidy: warning: invalid case style for variable 'e' [readability-identifier-naming]
not useful