]> granicus.if.org Git - llvm/commitdiff
NewGVN: Detect copies through predicateinfo
authorDaniel Berlin <dberlin@dberlin.org>
Tue, 5 Sep 2017 02:17:41 +0000 (02:17 +0000)
committerDaniel Berlin <dberlin@dberlin.org>
Tue, 5 Sep 2017 02:17:41 +0000 (02:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312508 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/NewGVN.cpp

index e9046d9af0510681f80030e5815c133c88bac82c..a2f008e70e331ce297394be5034df426320a04bb 100644 (file)
@@ -850,6 +850,17 @@ void NewGVN::deleteExpression(const Expression *E) const {
   const_cast<BasicExpression *>(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<IntrinsicInst>(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;