[PATCH] D12008: [ScalarEvolutionExpander] Refactor isHighCostExpansionHelper division case
Igor Laevsky via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 13 07:53:41 PDT 2015
igor-laevsky created this revision.
igor-laevsky added a reviewer: sanjoy.
igor-laevsky added a subscriber: llvm-commits.
igor-laevsky set the repository for this revision to rL LLVM.
Herald added a subscriber: sanjoy.
This is follow up after http://reviews.llvm.org/D11687
In `SCEVUDivExpr` case inside `isHighCostExpansionHelper` we had lookup code which was almost exactly same as code inside `findExistingExpansion`. Refactor it to make use of the existing function.
Repository:
rL LLVM
http://reviews.llvm.org/D12008
Files:
lib/Analysis/ScalarEvolutionExpander.cpp
Index: lib/Analysis/ScalarEvolutionExpander.cpp
===================================================================
--- lib/Analysis/ScalarEvolutionExpander.cpp
+++ lib/Analysis/ScalarEvolutionExpander.cpp
@@ -1816,11 +1816,11 @@
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;
@@ -1887,28 +1887,20 @@
// UDivExpr is very likely a UDiv that ScalarEvolution's HowFarToZero or
// HowManyLessThans produced to compute a precise expression, rather than a
// UDiv from the user's code. If we can't find a UDiv in the code with some
- // simple searching, assume the former consider UDivExpr expensive to
+ // simple searaching, assume the former consider UDivExpr expensive to
// compute.
BasicBlock *ExitingBB = L->getExitingBlock();
if (!ExitingBB)
return true;
- BranchInst *ExitingBI = dyn_cast<BranchInst>(ExitingBB->getTerminator());
- if (!ExitingBI || !ExitingBI->isConditional())
+ // We already tried to find existing value for plain 'S' at the beginning of
+ // this function. Now try to lookup 'S + 1' as it is common pattern
+ // involving division. This is just 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12008.32047.patch
Type: text/x-patch
Size: 2409 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150813/4c603e99/attachment-0001.bin>
More information about the llvm-commits
mailing list