[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

llvm-svn: 319153
This commit is contained in:
Max Kazantsev 2017-11-28 08:26:43 +00:00
parent 2d614ced55
commit 6e78ad35cc
1 changed files with 4 additions and 4 deletions

View File

@ -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<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::pair<Value *, Value *>, 8> &EqCache,
}
}
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)