From 2371e0a1c853ea8b9c562d34c9aba6b8f4ccc379 Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Tue, 13 Mar 2018 07:46:06 +0000 Subject: [PATCH] [SCEV][NFC] Smarter implementation of isAvailableAtLoopEntry isAvailableAtLoopEntry duplicates logic of `properlyDominates` after checking invariance. This patch replaces this logic with invocation of this method which is more profitable because it supports caching. Differential Revision: https://reviews.llvm.org/D43997 llvm-svn: 327373 --- llvm/lib/Analysis/ScalarEvolution.cpp | 54 +---------------------------------- 1 file changed, 1 insertion(+), 53 deletions(-) diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 5aea3a4..6638ae5 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -2234,59 +2234,7 @@ StrengthenNoWrapFlags(ScalarEvolution *SE, SCEVTypes Type, } bool ScalarEvolution::isAvailableAtLoopEntry(const SCEV *S, const Loop *L) { - if (!isLoopInvariant(S, L)) - return false; - // If a value depends on a SCEVUnknown which is defined after the loop, we - // conservatively assume that we cannot calculate it at the loop's entry. - struct FindDominatedSCEVUnknown { - bool Found = false; - const Loop *L; - DominatorTree &DT; - LoopInfo &LI; - - FindDominatedSCEVUnknown(const Loop *L, DominatorTree &DT, LoopInfo &LI) - : L(L), DT(DT), LI(LI) {} - - bool checkSCEVUnknown(const SCEVUnknown *SU) { - if (auto *I = dyn_cast(SU->getValue())) { - if (DT.dominates(L->getHeader(), I->getParent())) - Found = true; - else - assert(DT.dominates(I->getParent(), L->getHeader()) && - "No dominance relationship between SCEV and loop?"); - } - return false; - } - - bool follow(const SCEV *S) { - switch (static_cast(S->getSCEVType())) { - case scConstant: - return false; - case scAddRecExpr: - case scTruncate: - case scZeroExtend: - case scSignExtend: - case scAddExpr: - case scMulExpr: - case scUMaxExpr: - case scSMaxExpr: - case scUDivExpr: - return true; - case scUnknown: - return checkSCEVUnknown(cast(S)); - case scCouldNotCompute: - llvm_unreachable("Attempt to use a SCEVCouldNotCompute object!"); - } - return false; - } - - bool isDone() { return Found; } - }; - - FindDominatedSCEVUnknown FSU(L, DT, LI); - SCEVTraversal ST(FSU); - ST.visitAll(S); - return !FSU.Found; + return isLoopInvariant(S, L) && properlyDominates(S, L->getHeader()); } /// Get a canonical add expression, or something simpler if possible. -- 2.7.4