[llvm] r319153 - [SCEV][NFC] More efficient caching in CompareValueComplexity
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 28 00:26:43 PST 2017
Author: mkazantsev
Date: Tue Nov 28 00:26:43 2017
New Revision: 319153
URL: http://llvm.org/viewvc/llvm-project?rev=319153&view=rev
Log:
[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
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=319153&r1=319152&r2=319153&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Tue Nov 28 00:26:43 2017
@@ -549,10 +549,10 @@ bool SCEVUnknown::isOffsetOf(Type *&CTy,
/// 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(EquivalenceClasses<Value *> &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<std::pai
}
}
- EqCache.insert({LV, RV});
+ EqCache.unionSets(LV, RV);
return 0;
}
@@ -649,7 +649,7 @@ static int CompareSCEVComplexity(
const SCEVUnknown *LU = cast<SCEVUnknown>(LHS);
const SCEVUnknown *RU = cast<SCEVUnknown>(RHS);
- SmallSet<std::pair<Value *, Value *>, 8> EqCache;
+ EquivalenceClasses<Value *> EqCache;
int X = CompareValueComplexity(EqCache, LI, LU->getValue(), RU->getValue(),
Depth + 1);
if (X == 0)
More information about the llvm-commits
mailing list