From b789165e6bd13757da0243618757211d9530e078 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Thu, 19 Apr 2018 15:05:47 +0000 Subject: [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 --- llvm/lib/Transforms/Scalar/NewGVN.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Transforms') 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 CurrentDeps; if (MemAccess) TempToMemory.insert({ValueOp, MemAccess}); bool SafeForPHIOfOps = true; @@ -2764,7 +2765,7 @@ NewGVN::makePossiblePHIOfOps(Instruction *I, if (isa(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) -- cgit v1.2.3