Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp =================================================================== --- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -1786,7 +1786,9 @@ if (predicateLoopExits(L, Rewriter)) { Changed = true; // Given we've changed exit counts, notify SCEV - SE->forgetLoop(L); + // Some nested loops may share same folded exit basic block, + // thus we need to notify top most loop. + SE->forgetTopmostLoop(L); } // If we have a trip count expression, rewrite the loop's exit condition