From: Daniel Berlin Date: Tue, 5 Sep 2017 02:17:41 +0000 (+0000) Subject: NewGVN: Detect copies through predicateinfo X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d17cd5cd24cd990b9305aab0bccc7a72c92fdece;p=llvm NewGVN: Detect copies through predicateinfo git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312508 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/NewGVN.cpp b/lib/Transforms/Scalar/NewGVN.cpp index e9046d9af05..a2f008e70e3 100644 --- a/lib/Transforms/Scalar/NewGVN.cpp +++ b/lib/Transforms/Scalar/NewGVN.cpp @@ -850,6 +850,17 @@ void NewGVN::deleteExpression(const Expression *E) const { const_cast(BE)->deallocateOperands(ArgRecycler); ExpressionAllocator.Deallocate(E); } + +// Return true if V is really PN, even accounting for predicateinfo copies. +static bool isCopyOfSelf(const Value *V, const PHINode *PN) { + if (V == PN) + return V; + if (auto *II = dyn_cast(V)) + if (II->getIntrinsicID() == Intrinsic::ssa_copy && II->getOperand(0) == PN) + return true; + return false; +} + PHIExpression *NewGVN::createPHIExpression(Instruction *I, bool &HasBackedge, bool &OriginalOpsConstant) const { BasicBlock *PHIBlock = getBlockForValue(I); @@ -879,7 +890,7 @@ PHIExpression *NewGVN::createPHIExpression(Instruction *I, bool &HasBackedge, // Filter out unreachable phi operands. auto Filtered = make_filter_range(PHIOperands, [&](const Use *U) { - if (*U == PN) + if (isCopyOfSelf(*U, PN)) return false; if (!ReachableEdges.count({PN->getIncomingBlock(*U), PHIBlock})) return false;