Index: lib/CodeGen/BlockGenerators.cpp =================================================================== --- lib/CodeGen/BlockGenerators.cpp +++ lib/CodeGen/BlockGenerators.cpp @@ -781,6 +781,17 @@ SE.forgetValue(&Inst); else llvm_unreachable("Unexpected statement type found"); + // Invalidate SCEV of loops surrounding EscapeUsers + for (const auto &EscapeMapping : EscapeMap) { + const EscapeUserVectorTy &EscapeUsers = EscapeMapping.second.second; + for (Instruction *EUser : EscapeUsers) { + if (Loop *L = LI.getLoopFor(EUser->getParent())) + while (L) { + SE.forgetLoop(L); + L = L->getParentLoop(); + } + } + } } void BlockGenerator::finalizeSCoP(Scop &S) {