This patch is to resolve the bug reported and discussed in https://reviews.llvm.org/D124926#3718761, https://reviews.llvm.org/D124926#3719876.
The bug is that when we run loop interchange twice with the new pass manager using -passes="loop(loop-interchange,loop-interchange)" on the IR attached in https://reviews.llvm.org/D124926#3718761, it hangs forever and consumes more and more memory. The IR is added as a new lit test file in this patch.
The underlying reason, as described in https://reviews.llvm.org/D124926#3719876, is that loop interchange is a loopnest pass under the new pass manager, but the loop nest is not constructed correctly by the loop pass manager after completing the first loop interchange pass and before running the second interchange pass. The loop in the IR is a triply nested loop. But after completing the first interchange pass, the loop nest constructed is a doubly nested loop which is incorrect and caused the trouble.
The reason that the loop nest is constructed incorrectly is that the outermost loop has changed after the first interchange, and what was the original outermost loop is not the current outermost loop anymore. For this bug (https://reviews.llvm.org/D124926#3718761) the original outermost loop L has actually become the middle loop. However the loop nest is still constructed based on L, that is why the loop nest is constructed as a doubly nested loop.
What this patch does is that, in the loop pass manager before running each pass, we always let L point to the current outermost loop, because loop nests should be constructed based on the outermost loop and it is only valid to run a loopnest pass when L is the outermost loop. Please refer to lines 89 to 94 in LoopPassManager.cpp in this patch.
markLoopNestChanged