diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -11012,8 +11012,10 @@ ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS) { // Interpret a null as meaning no loop, where there is obviously no guard - // (interprocedural conditions notwithstanding). - if (!L) return true; + // (interprocedural conditions notwithstanding). Do not bother about + // unreachable loops. + if (!L || !DT.isReachableFromEntry(L->getHeader())) + return true; if (VerifyIR) assert(!verifyFunction(*L->getHeader()->getParent(), &dbgs()) && @@ -11070,12 +11072,6 @@ return true; } - // If the loop is not reachable from the entry block, we risk running into an - // infinite loop as we walk up into the dom tree. These loops do not matter - // anyway, so we just return a conservative answer when we see them. - if (!DT.isReachableFromEntry(L->getHeader())) - return false; - if (isImpliedViaGuard(Latch, Pred, LHS, RHS)) return true; @@ -11121,6 +11117,9 @@ ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS) { + // Do not bother proving facts for unreachable code. + if (!DT.isReachableFromEntry(BB)) + return true; if (VerifyIR) assert(!verifyFunction(*BB->getParent(), &dbgs()) && "This cannot be done on broken IR!");