[llvm] r284500 - [SCEV] Extract out a helper function; NFC

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 18 10:45:13 PDT 2016


Author: sanjoy
Date: Tue Oct 18 12:45:13 2016
New Revision: 284500

URL: http://llvm.org/viewvc/llvm-project?rev=284500&view=rev
Log:
[SCEV] Extract out a helper function; NFC

Modified:
    llvm/trunk/lib/Analysis/ScalarEvolution.cpp

Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=284500&r1=284499&r2=284500&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Tue Oct 18 12:45:13 2016
@@ -448,6 +448,51 @@ bool SCEVUnknown::isOffsetOf(Type *&CTy,
 //                               SCEV Utilities
 //===----------------------------------------------------------------------===//
 
+static int CompareValueComplexity(const LoopInfo *const LI, Value *LV,
+                                  Value *RV) {
+  // Order pointer values after integer values. This helps SCEVExpander form
+  // GEPs.
+  bool LIsPointer = LV->getType()->isPointerTy(),
+       RIsPointer = RV->getType()->isPointerTy();
+  if (LIsPointer != RIsPointer)
+    return (int)LIsPointer - (int)RIsPointer;
+
+  // Compare getValueID values.
+  unsigned LID = LV->getValueID(), RID = RV->getValueID();
+  if (LID != RID)
+    return (int)LID - (int)RID;
+
+  // Sort arguments by their position.
+  if (const Argument *LA = dyn_cast<Argument>(LV)) {
+    const Argument *RA = cast<Argument>(RV);
+    unsigned LArgNo = LA->getArgNo(), RArgNo = RA->getArgNo();
+    return (int)LArgNo - (int)RArgNo;
+  }
+
+  // For instructions, compare their loop depth, and their operand count.  This
+  // is pretty loose.
+  if (const Instruction *LInst = dyn_cast<Instruction>(LV)) {
+    const Instruction *RInst = cast<Instruction>(RV);
+
+    // Compare loop depths.
+    const BasicBlock *LParent = LInst->getParent(),
+                     *RParent = RInst->getParent();
+    if (LParent != RParent) {
+      unsigned LDepth = LI->getLoopDepth(LParent),
+               RDepth = LI->getLoopDepth(RParent);
+      if (LDepth != RDepth)
+        return (int)LDepth - (int)RDepth;
+    }
+
+    // Compare the number of operands.
+    unsigned LNumOps = LInst->getNumOperands(),
+             RNumOps = RInst->getNumOperands();
+    return (int)LNumOps - (int)RNumOps;
+  }
+
+  return 0;
+}
+
 // Return negative, zero, or positive, if LHS is less than, equal to, or greater
 // than RHS, respectively. A three-way result allows recursive comparisons to be
 // more efficient.
@@ -470,51 +515,7 @@ static int CompareSCEVComplexity(const L
     const SCEVUnknown *LU = cast<SCEVUnknown>(LHS);
     const SCEVUnknown *RU = cast<SCEVUnknown>(RHS);
 
-    // Sort SCEVUnknown values with some loose heuristics. TODO: This is
-    // not as complete as it could be.
-    const Value *LV = LU->getValue(), *RV = RU->getValue();
-
-    // Order pointer values after integer values. This helps SCEVExpander
-    // form GEPs.
-    bool LIsPointer = LV->getType()->isPointerTy(),
-         RIsPointer = RV->getType()->isPointerTy();
-    if (LIsPointer != RIsPointer)
-      return (int)LIsPointer - (int)RIsPointer;
-
-    // Compare getValueID values.
-    unsigned LID = LV->getValueID(), RID = RV->getValueID();
-    if (LID != RID)
-      return (int)LID - (int)RID;
-
-    // Sort arguments by their position.
-    if (const Argument *LA = dyn_cast<Argument>(LV)) {
-      const Argument *RA = cast<Argument>(RV);
-      unsigned LArgNo = LA->getArgNo(), RArgNo = RA->getArgNo();
-      return (int)LArgNo - (int)RArgNo;
-    }
-
-    // For instructions, compare their loop depth, and their operand
-    // count.  This is pretty loose.
-    if (const Instruction *LInst = dyn_cast<Instruction>(LV)) {
-      const Instruction *RInst = cast<Instruction>(RV);
-
-      // Compare loop depths.
-      const BasicBlock *LParent = LInst->getParent(),
-                       *RParent = RInst->getParent();
-      if (LParent != RParent) {
-        unsigned LDepth = LI->getLoopDepth(LParent),
-                 RDepth = LI->getLoopDepth(RParent);
-        if (LDepth != RDepth)
-          return (int)LDepth - (int)RDepth;
-      }
-
-      // Compare the number of operands.
-      unsigned LNumOps = LInst->getNumOperands(),
-               RNumOps = RInst->getNumOperands();
-      return (int)LNumOps - (int)RNumOps;
-    }
-
-    return 0;
+    return CompareValueComplexity(LI, LU->getValue(), RU->getValue());
   }
 
   case scConstant: {




More information about the llvm-commits mailing list