diff options
author | Igor Laevsky <igmyrj@gmail.com> | 2015-08-17 16:37:04 +0000 |
---|---|---|
committer | Igor Laevsky <igmyrj@gmail.com> | 2015-08-17 16:37:04 +0000 |
commit | 06044f97d21dfdabe4f9599447005b08e13344c1 (patch) | |
tree | 99c0917520c0211847820a0dabde7104cca90767 /llvm/lib/Analysis/ScalarEvolutionExpander.cpp | |
parent | b322aa6f5310750c7bdfb018bd8dde489f48f297 (diff) | |
download | llvm-06044f97d21dfdabe4f9599447005b08e13344c1.zip llvm-06044f97d21dfdabe4f9599447005b08e13344c1.tar.gz llvm-06044f97d21dfdabe4f9599447005b08e13344c1.tar.bz2 |
[ScalarEvolutionExpander] Reuse findExistingExpansion during expansion cost calculation for division
Primary purpose of this change is to reuse existing code inside findExistingExpansion. However it introduces very slight semantic change - findExistingExpansion now looks into exiting blocks instead of a loop latches. Originally heuristic was based on the fact that we want to look at the loop exit conditions. And since all exiting latches will be listed in the ExitingBlocks, heuristic stays roughly the same.
Differential Revision: http://reviews.llvm.org/D12008
llvm-svn: 245227
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolutionExpander.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolutionExpander.cpp | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp index d0b3643..ed7386b 100644 --- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp @@ -1815,11 +1815,11 @@ Value *SCEVExpander::findExistingExpansion(const SCEV *S, const Instruction *At, Loop *L) { using namespace llvm::PatternMatch; - SmallVector<BasicBlock *, 4> Latches; - L->getLoopLatches(Latches); + SmallVector<BasicBlock *, 4> ExitingBlocks; + L->getExitingBlocks(ExitingBlocks); - // Look for suitable value in simple conditions at the loop latches. - for (BasicBlock *BB : Latches) { + // Look for suitable value in simple conditions at the loop exits. + for (BasicBlock *BB : ExitingBlocks) { ICmpInst::Predicate Pred; Instruction *LHS, *RHS; BasicBlock *TrueBB, *FalseBB; @@ -1892,22 +1892,14 @@ bool SCEVExpander::isHighCostExpansionHelper( if (!ExitingBB) return true; - BranchInst *ExitingBI = dyn_cast<BranchInst>(ExitingBB->getTerminator()); - if (!ExitingBI || !ExitingBI->isConditional()) + // At the beginning of this function we already tried to find existing value + // for plain 'S'. Now try to lookup 'S + 1' since it is common pattern + // involving division. This is just a simple search heuristic. + if (!At) + At = &ExitingBB->back(); + if (!findExistingExpansion( + SE.getAddExpr(S, SE.getConstant(S->getType(), 1)), At, L)) return true; - - ICmpInst *OrigCond = dyn_cast<ICmpInst>(ExitingBI->getCondition()); - if (!OrigCond) - return true; - - const SCEV *RHS = SE.getSCEV(OrigCond->getOperand(1)); - RHS = SE.getMinusSCEV(RHS, SE.getConstant(RHS->getType(), 1)); - if (RHS != S) { - const SCEV *LHS = SE.getSCEV(OrigCond->getOperand(0)); - LHS = SE.getMinusSCEV(LHS, SE.getConstant(LHS->getType(), 1)); - if (LHS != S) - return true; - } } // HowManyLessThans uses a Max expression whenever the loop is not guarded by |