[llvm] r319149 - [SCEV][NFC] More efficient caching in CompareSCEVComplexity
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 27 23:48:12 PST 2017
Author: mkazantsev
Date: Mon Nov 27 23:48:12 2017
New Revision: 319149
URL: http://llvm.org/viewvc/llvm-project?rev=319149&view=rev
Log:
[SCEV][NFC] More efficient caching in CompareSCEVComplexity
Currently, we use a set of pairs to cache responces like `CompareSCEVComplexity(X, Y) == 0`. If we had
proved that `CompareSCEVComplexity(S1, S2) == 0` and `CompareSCEVComplexity(S2, S3) == 0`,
this cache does not allow us to prove that `CompareSCEVComplexity(S1, S3)` is also `0`.
This patch replaces this set with `EquivalenceClasses` any two values from the same set are equal from
point of `CompareSCEVComplexity`. This, in particular, allows us to prove the fact from example above.
Differential Revision: https://reviews.llvm.org/D40428
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=319149&r1=319148&r2=319149&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Mon Nov 27 23:48:12 2017
@@ -63,6 +63,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DepthFirstIterator.h"
+#include "llvm/ADT/EquivalenceClasses.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
@@ -626,7 +627,7 @@ CompareValueComplexity(SmallSet<std::pai
// than RHS, respectively. A three-way result allows recursive comparisons to be
// more efficient.
static int CompareSCEVComplexity(
- SmallSet<std::pair<const SCEV *, const SCEV *>, 8> &EqCacheSCEV,
+ EquivalenceClasses<const SCEV *> &EqCacheSCEV,
const LoopInfo *const LI, const SCEV *LHS, const SCEV *RHS,
DominatorTree &DT, unsigned Depth = 0) {
// Fast-path: SCEVs are uniqued so we can do a quick equality check.
@@ -638,7 +639,7 @@ static int CompareSCEVComplexity(
if (LType != RType)
return (int)LType - (int)RType;
- if (Depth > MaxSCEVCompareDepth || EqCacheSCEV.count({LHS, RHS}))
+ if (Depth > MaxSCEVCompareDepth || EqCacheSCEV.isEquivalent(LHS, RHS))
return 0;
// Aside from the getSCEVType() ordering, the particular ordering
// isn't very important except that it's beneficial to be consistent,
@@ -652,7 +653,7 @@ static int CompareSCEVComplexity(
int X = CompareValueComplexity(EqCache, LI, LU->getValue(), RU->getValue(),
Depth + 1);
if (X == 0)
- EqCacheSCEV.insert({LHS, RHS});
+ EqCacheSCEV.unionSets(LHS, RHS);
return X;
}
@@ -700,7 +701,7 @@ static int CompareSCEVComplexity(
if (X != 0)
return X;
}
- EqCacheSCEV.insert({LHS, RHS});
+ EqCacheSCEV.unionSets(LHS, RHS);
return 0;
}
@@ -724,7 +725,7 @@ static int CompareSCEVComplexity(
if (X != 0)
return X;
}
- EqCacheSCEV.insert({LHS, RHS});
+ EqCacheSCEV.unionSets(LHS, RHS);
return 0;
}
@@ -740,7 +741,7 @@ static int CompareSCEVComplexity(
X = CompareSCEVComplexity(EqCacheSCEV, LI, LC->getRHS(), RC->getRHS(), DT,
Depth + 1);
if (X == 0)
- EqCacheSCEV.insert({LHS, RHS});
+ EqCacheSCEV.unionSets(LHS, RHS);
return X;
}
@@ -754,7 +755,7 @@ static int CompareSCEVComplexity(
int X = CompareSCEVComplexity(EqCacheSCEV, LI, LC->getOperand(),
RC->getOperand(), DT, Depth + 1);
if (X == 0)
- EqCacheSCEV.insert({LHS, RHS});
+ EqCacheSCEV.unionSets(LHS, RHS);
return X;
}
@@ -777,7 +778,7 @@ static void GroupByComplexity(SmallVecto
LoopInfo *LI, DominatorTree &DT) {
if (Ops.size() < 2) return; // Noop
- SmallSet<std::pair<const SCEV *, const SCEV *>, 8> EqCache;
+ EquivalenceClasses<const SCEV *> EqCache;
if (Ops.size() == 2) {
// This is the common case, which also happens to be trivially simple.
// Special case it.
More information about the llvm-commits
mailing list