diff options
author | Max Kazantsev <max.kazantsev@azul.com> | 2017-11-28 07:48:12 +0000 |
---|---|---|
committer | Max Kazantsev <max.kazantsev@azul.com> | 2017-11-28 07:48:12 +0000 |
commit | cf9b1b24ce6690bbb83ecbdec69096fe840b92b1 (patch) | |
tree | 586863da8d382c638667677b1470aeca94a37cbd /llvm/lib/Analysis/ScalarEvolution.cpp | |
parent | 08c2f0fabb5d54f0e60c980dd6e1b7f9d5d00ee7 (diff) | |
download | bcm5719-llvm-cf9b1b24ce6690bbb83ecbdec69096fe840b92b1.tar.gz bcm5719-llvm-cf9b1b24ce6690bbb83ecbdec69096fe840b92b1.zip |
[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
llvm-svn: 319149
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index faf99c0a3c9..8082f01e7bc 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -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::pair<Value *, Value *>, 8> &EqCache, // 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(SmallVectorImpl<const SCEV *> &Ops, 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. |