In the special case, call the comparison function instead of
authorDan Gohman <gohman@apple.com>
Mon, 14 Apr 2008 18:23:56 +0000 (18:23 +0000)
committerDan Gohman <gohman@apple.com>
Mon, 14 Apr 2008 18:23:56 +0000 (18:23 +0000)
manually performing the comparison. This allows the special
case to work correctly even in the case where someone is
experimenting with a different comparison function :-).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49670 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ScalarEvolution.cpp

index 1b4c277e1a75b38d4b0297182af622a3b47f42b9..4b4b97e28624bb9adb706ec585a026f8d45603a2 100644 (file)
@@ -431,7 +431,7 @@ namespace {
   /// than the complexity of the RHS.  This comparator is used to canonicalize
   /// expressions.
   struct VISIBILITY_HIDDEN SCEVComplexityCompare {
-    bool operator()(SCEV *LHS, SCEV *RHS) {
+    bool operator()(const SCEV *LHS, const SCEV *RHS) const {
       return LHS->getSCEVType() < RHS->getSCEVType();
     }
   };
@@ -452,7 +452,7 @@ static void GroupByComplexity(std::vector<SCEVHandle> &Ops) {
   if (Ops.size() == 2) {
     // This is the common case, which also happens to be trivially simple.
     // Special case it.
-    if (Ops[0]->getSCEVType() > Ops[1]->getSCEVType())
+    if (SCEVComplexityCompare()(Ops[1], Ops[0]))
       std::swap(Ops[0], Ops[1]);
     return;
   }