[PATCH] D12008: [ScalarEvolutionExpander] Refactor isHighCostExpansionHelper division case

Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 09:38:06 PDT 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL245227: [ScalarEvolutionExpander] Reuse findExistingExpansion during expansion cost… (authored by igor.laevsky).

Changed prior to commit:
  http://reviews.llvm.org/D12008?vs=32047&id=32316#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D12008

Files:
  llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp

Index: llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
===================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
+++ llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -1815,11 +1815,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;
@@ -1892,22 +1892,14 @@
     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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12008.32316.patch
Type: text/x-patch
Size: 1988 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150817/e1aab2bd/attachment.bin>


More information about the llvm-commits mailing list