[llvm] r340818 - [GVNHoist] Prune out useless CHI insertions
Alexandros Lamprineas via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 28 04:07:55 PDT 2018
Author: alelab01
Date: Tue Aug 28 04:07:54 2018
New Revision: 340818
URL: http://llvm.org/viewvc/llvm-project?rev=340818&view=rev
Log:
[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
Modified:
llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp?rev=340818&r1=340817&r2=340818&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp Tue Aug 28 04:07:54 2018
@@ -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>>;
@@ -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]);
More information about the llvm-commits
mailing list