From 484bd13e2d40c780ddba2362ca5b43f65de7fa3f Mon Sep 17 00:00:00 2001 From: Alexandros Lamprineas Date: Tue, 28 Aug 2018 11:07:54 +0000 Subject: [GVNHoist] Prune out useless CHI insertions Fix for the out-of-memory error when compiling SemaChecking.cpp with GVNHoist and ubsan enabled. I've used a cache for inserted CHIs to avoid excessive memory usage. Differential Revision: https://reviews.llvm.org/D50323 llvm-svn: 340818 --- llvm/lib/Transforms/Scalar/GVNHoist.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/Scalar/GVNHoist.cpp b/llvm/lib/Transforms/Scalar/GVNHoist.cpp index ca19576e8b1..10cdcd59e42 100644 --- a/llvm/lib/Transforms/Scalar/GVNHoist.cpp +++ b/llvm/lib/Transforms/Scalar/GVNHoist.cpp @@ -155,6 +155,7 @@ struct CHIArg { using CHIIt = SmallVectorImpl::iterator; using CHIArgs = iterator_range; +using CHICache = DenseMap>; using OutValuesType = DenseMap>; using InValuesType = DenseMap, 2>>; @@ -766,6 +767,7 @@ private: ReverseIDFCalculator IDFs(*PDT); OutValuesType OutValue; InValuesType InValue; + CHICache CachedCHIs; for (const auto &R : Ranks) { const SmallVecInsn &V = Map.lookup(R); if (V.size() < 2) @@ -792,11 +794,12 @@ private: } // Insert empty CHI node for this VN. This is used to factor out // basic blocks where the ANTIC can potentially change. - for (auto IDFB : IDFBlocks) { // TODO: Prune out useless CHI insertions. + for (auto IDFB : IDFBlocks) { for (unsigned i = 0; i < V.size(); ++i) { CHIArg C = {VN, nullptr, nullptr}; // Ignore spurious PDFs. - if (DT->properlyDominates(IDFB, V[i]->getParent())) { + if (DT->properlyDominates(IDFB, V[i]->getParent()) && + CachedCHIs[IDFB].insert(V[i]).second) { OutValue[IDFB].push_back(C); LLVM_DEBUG(dbgs() << "\nInsertion a CHI for BB: " << IDFB->getName() << ", for Insn: " << *V[i]); -- cgit v1.2.3