diff options
author | Florian Hahn <florian.hahn@arm.com> | 2018-04-19 15:05:47 +0000 |
---|---|---|
committer | Florian Hahn <florian.hahn@arm.com> | 2018-04-19 15:05:47 +0000 |
commit | b789165e6bd13757da0243618757211d9530e078 (patch) | |
tree | 4f8e29a6a726c0ea502c87cc7164a36b58536607 /llvm/lib/Transforms | |
parent | d92c37e0909e7b72fd13e7fbb67151664d5a9002 (diff) | |
download | bcm5719-llvm-b789165e6bd13757da0243618757211d9530e078.tar.gz bcm5719-llvm-b789165e6bd13757da0243618757211d9530e078.zip |
[NewGVN] Add ops as dependency if we cannot find a leader for ValueOp.
If those operands change, we might find a leader for ValueOp, which
could enable new phi-of-op creation.
This fixes a case where we missed creating a phi-of-ops node. With D43865
and this patch, bootstrapping clang/llvm works with -enable-newgvn, whereas
without it, the "value changed after iteration" assertion is triggered.
Reviewers: dberlin, davide
Reviewed By: dberlin
Differential Revision: https://reviews.llvm.org/D42180
llvm-svn: 330334
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/NewGVN.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp index e82f69a8aa9..3de8d170bcd 100644 --- a/llvm/lib/Transforms/Scalar/NewGVN.cpp +++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -2753,6 +2753,7 @@ NewGVN::makePossiblePHIOfOps(Instruction *I, // Clone the instruction, create an expression from it that is // translated back into the predecessor, and see if we have a leader. Instruction *ValueOp = I->clone(); + SmallPtrSet<Value *, 4> CurrentDeps; if (MemAccess) TempToMemory.insert({ValueOp, MemAccess}); bool SafeForPHIOfOps = true; @@ -2764,7 +2765,7 @@ NewGVN::makePossiblePHIOfOps(Instruction *I, if (isa<PHINode>(Op)) { Op = Op->DoPHITranslation(PHIBlock, PredBB); if (Op != OrigOp && Op != I) - Deps.insert(Op); + CurrentDeps.insert(Op); } else if (auto *ValuePHI = RealToTemp.lookup(Op)) { if (getBlockForValue(ValuePHI) == PHIBlock) Op = ValuePHI->getIncomingValueForBlock(PredBB); @@ -2783,8 +2784,16 @@ NewGVN::makePossiblePHIOfOps(Instruction *I, : findLeaderForInst(ValueOp, Visited, MemAccess, I, PredBB); ValueOp->deleteValue(); - if (!FoundVal) + if (!FoundVal) { + // We failed to find a leader for the current ValueOp, but this might + // change in case of the translated operands change. + if (SafeForPHIOfOps) + for (auto Dep : CurrentDeps) + addAdditionalUsers(Dep, I); + return nullptr; + } + Deps.insert(CurrentDeps.begin(), CurrentDeps.end()); } else { DEBUG(dbgs() << "Skipping phi of ops operand for incoming block " << getBlockName(PredBB) |