Index: llvm/lib/Analysis/ScalarEvolution.cpp =================================================================== --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -11154,20 +11154,6 @@ return true; } - // Try to prove (Pred, LHS, RHS) using isImpliedViaGuard. - auto ProveViaGuard = [&](const BasicBlock *Block) { - if (isImpliedViaGuard(Block, Pred, LHS, RHS)) - return true; - if (ProvingStrictComparison) { - auto ProofFn = [&](ICmpInst::Predicate P) { - return isImpliedViaGuard(Block, P, LHS, RHS); - }; - if (SplitAndProve(ProofFn)) - return true; - } - return false; - }; - // Try to prove (Pred, LHS, RHS) using isImpliedCond. auto ProveViaCond = [&](const Value *Condition, bool Inverse) { const Instruction *CtxI = &BB->front(); @@ -11194,9 +11180,6 @@ PredBB = BB->getSinglePredecessor(); for (std::pair Pair(PredBB, BB); Pair.first; Pair = getPredecessorWithUniqueSuccessorForBB(Pair.first)) { - if (ProveViaGuard(Pair.first)) - return true; - const BranchInst *BlockEntryPredicate = dyn_cast(Pair.first->getTerminator()); if (!BlockEntryPredicate || BlockEntryPredicate->isUnconditional()) @@ -11219,6 +11202,16 @@ return true; } + // Check conditions due to any @llvm.experimental.guard intrinsics. + auto *GuardDecl = F.getParent()->getFunction( + Intrinsic::getName(Intrinsic::experimental_guard)); + if (GuardDecl) { + for (const auto *GU : GuardDecl->users()) + if (const auto *Guard = dyn_cast(GU)) + if (Guard->getFunction() == BB->getParent() && DT.dominates(Guard, BB)) + if (ProveViaCond(Guard->getArgOperand(0), false)) + return true; + } return false; }