[PATCH] D40429: [SCEV][NFC] More efficient caching in CompareValueComplexity

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 24 04:56:20 PST 2017


mkazantsev created this revision.

Currently, we use a set of pairs to cache responces like `CompareValueComplexity(X, Y) == 0`. If we had
proved that `CompareValueComplexity(S1, S2) == 0` and `CompareValueComplexity(S2, S3) == 0`,
this cache does not allow us to prove that `CompareValueComplexity(S1, S3)` is also `0`.

This patch replaces this set with disjoint set union (DSU) that merges Values into equivalence sets so that
any two values from the same set are equal from point of `CompareValueComplexity` . This, in particular,
allows us to prove the fact from example above.


https://reviews.llvm.org/D40429

Files:
  lib/Analysis/ScalarEvolution.cpp


Index: lib/Analysis/ScalarEvolution.cpp
===================================================================
--- lib/Analysis/ScalarEvolution.cpp
+++ lib/Analysis/ScalarEvolution.cpp
@@ -549,10 +549,10 @@
 /// Since we do not continue running this routine on expression trees once we
 /// have seen unequal values, there is no need to track them in the cache.
 static int
-CompareValueComplexity(SmallSet<std::pair<Value *, Value *>, 8> &EqCache,
+CompareValueComplexity(DisjointSetUnion<Value *> &EqCache,
                        const LoopInfo *const LI, Value *LV, Value *RV,
                        unsigned Depth) {
-  if (Depth > MaxValueCompareDepth || EqCache.count({LV, RV}))
+  if (Depth > MaxValueCompareDepth || EqCache.isInSameSet(LV, RV))
     return 0;
 
   // Order pointer values after integer values. This helps SCEVExpander form
@@ -619,7 +619,7 @@
     }
   }
 
-  EqCache.insert({LV, RV});
+  EqCache.mergeSetsOf(LV, RV);
   return 0;
 }
 
@@ -649,7 +649,7 @@
     const SCEVUnknown *LU = cast<SCEVUnknown>(LHS);
     const SCEVUnknown *RU = cast<SCEVUnknown>(RHS);
 
-    SmallSet<std::pair<Value *, Value *>, 8> EqCache;
+    DisjointSetUnion<Value *> EqCache;
     int X = CompareValueComplexity(EqCache, LI, LU->getValue(), RU->getValue(),
                                    Depth + 1);
     if (X == 0)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40429.124166.patch
Type: text/x-patch
Size: 1329 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171124/56d64e82/attachment.bin>


More information about the llvm-commits mailing list