diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -2368,15 +2368,27 @@ // Helper function that checks whether a function has any cycle. // TODO: Replace with more efficent code -static bool containsCycle(Function &F) { +static bool containsCycle(Function &F,Attributor &A) { SmallPtrSet Visited; // Traverse BB by dfs and check whether successor is already visited. for (BasicBlock *BB : depth_first(&F)) { Visited.insert(BB); for (auto *SuccBB : successors(BB)) { - if (Visited.count(SuccBB)) + if (Visited.count(SuccBB)){ + ScalarEvolution *SE = + A.getInfoCache().getAnalysisResultForFunction(F); + + LoopInfo *LI = + A.getInfoCache().getAnalysisResultForFunction(F); + + if(LI->isLoopHeader(BB)){ + Loop *L = LI->getLoopFor(BB); + if(SE->getSmallConstantMaxTripCount(L)) return false; + return true; + } return true; + } } } return false; @@ -2386,8 +2398,8 @@ // endless loop // FIXME: Any cycle is regarded as endless loop for now. // We have to allow some patterns. -static bool containsPossiblyEndlessLoop(Function *F) { - return !F || !F->hasExactDefinition() || containsCycle(*F); +static bool containsPossiblyEndlessLoop(Function *F,Attributor &A) { + return !F || !F->hasExactDefinition() || containsCycle(*F,A); } struct AAWillReturnImpl : public AAWillReturn { @@ -2398,7 +2410,7 @@ AAWillReturn::initialize(A); Function *F = getAssociatedFunction(); - if (containsPossiblyEndlessLoop(F)) + if (containsPossiblyEndlessLoop(F,A)) indicatePessimisticFixpoint(); } @@ -7374,7 +7386,7 @@ for (Instruction *I : OpcodeInstMap[Opcode]) { // Skip dead instructions. if (A && A->isAssumedDead(IRPosition::value(*I), QueryingAA, LivenessAA, - CheckBBLivenessOnly)) + CheckBBLivenessOnly)) continue; if (!Pred(*I))