Skip to content

Commit

Permalink
[GVNHoist] Prune out useless CHI insertions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
labrinea committed Aug 28, 2018
1 parent 99fc18c commit 484bd13
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions llvm/lib/Transforms/Scalar/GVNHoist.cpp
Expand Up @@ -155,6 +155,7 @@ struct CHIArg {

using CHIIt = SmallVectorImpl<CHIArg>::iterator;
using CHIArgs = iterator_range<CHIIt>;
using CHICache = DenseMap<BasicBlock *, SmallPtrSet<Instruction *, 4>>;
using OutValuesType = DenseMap<BasicBlock *, SmallVector<CHIArg, 2>>;
using InValuesType =
DenseMap<BasicBlock *, SmallVector<std::pair<VNType, Instruction *>, 2>>;
Expand Down Expand Up @@ -766,6 +767,7 @@ class GVNHoist {
ReverseIDFCalculator IDFs(*PDT);
OutValuesType OutValue;
InValuesType InValue;
CHICache CachedCHIs;
for (const auto &R : Ranks) {
const SmallVecInsn &V = Map.lookup(R);
if (V.size() < 2)
Expand All @@ -792,11 +794,12 @@ class GVNHoist {
}
// 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]);
Expand Down

0 comments on commit 484bd13

Please sign in to comment.