From: Max Kazantsev Date: Tue, 28 Nov 2017 08:26:43 +0000 (+0000) Subject: [SCEV][NFC] More efficient caching in CompareValueComplexity X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e58aca6a4340bad92687f41966d54884b953d7ef;p=llvm [SCEV][NFC] More efficient caching in CompareValueComplexity 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 `EquivalenceClasses` 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. Differential Revision: https://reviews.llvm.org/D40429 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319153 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 8082f01e7bc..bc227747538 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -549,10 +549,10 @@ bool SCEVUnknown::isOffsetOf(Type *&CTy, Constant *&FieldNo) const { /// 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, 8> &EqCache, +CompareValueComplexity(EquivalenceClasses &EqCache, const LoopInfo *const LI, Value *LV, Value *RV, unsigned Depth) { - if (Depth > MaxValueCompareDepth || EqCache.count({LV, RV})) + if (Depth > MaxValueCompareDepth || EqCache.isEquivalent(LV, RV)) return 0; // Order pointer values after integer values. This helps SCEVExpander form @@ -619,7 +619,7 @@ CompareValueComplexity(SmallSet, 8> &EqCache, } } - EqCache.insert({LV, RV}); + EqCache.unionSets(LV, RV); return 0; } @@ -649,7 +649,7 @@ static int CompareSCEVComplexity( const SCEVUnknown *LU = cast(LHS); const SCEVUnknown *RU = cast(RHS); - SmallSet, 8> EqCache; + EquivalenceClasses EqCache; int X = CompareValueComplexity(EqCache, LI, LU->getValue(), RU->getValue(), Depth + 1); if (X == 0)