[llvm] r312507 - NewGVN: Change where check for original instruction in phi of ops leader finding is done. Where we had it before, we would stop looking when we hit the original instruction, but skip it. Now we skip it and keep looking.

Daniel Berlin via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 4 19:17:40 PDT 2017


Author: dannyb
Date: Mon Sep  4 19:17:40 2017
New Revision: 312507

URL: http://llvm.org/viewvc/llvm-project?rev=312507&view=rev
Log:
NewGVN: Change where check for original instruction in phi of ops leader finding is done. Where we had it before, we would stop looking when we hit the original instruction, but skip it. Now we skip it and keep looking.

Modified:
    llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp?rev=312507&r1=312506&r2=312507&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp Mon Sep  4 19:17:40 2017
@@ -713,7 +713,9 @@ private:
   void replaceInstruction(Instruction *, Value *);
   void markInstructionForDeletion(Instruction *);
   void deleteInstructionsInBlock(BasicBlock *);
-  Value *findPHIOfOpsLeader(const Expression *E, const BasicBlock *BB) const;
+  Value *findPHIOfOpsLeader(const Expression *, const Instruction *,
+                            const BasicBlock *) const;
+
   // New instruction creation.
   void handleNewInstruction(Instruction *){};
 
@@ -2551,8 +2553,8 @@ Value *NewGVN::findLeaderForInst(Instruc
     TempToMemory.erase(TransInst);
   if (!E)
     return nullptr;
-  auto *FoundVal = findPHIOfOpsLeader(E, PredBB);
-  if (!FoundVal || FoundVal == OrigInst) {
+  auto *FoundVal = findPHIOfOpsLeader(E, OrigInst, PredBB);
+  if (!FoundVal) {
     ExpressionToPhiOfOps[E].insert(OrigInst);
     DEBUG(dbgs() << "Cannot find phi of ops operand for " << *TransInst
                  << " in block " << getBlockName(PredBB) << "\n");
@@ -3622,6 +3624,7 @@ CongruenceClass *NewGVN::getClassForExpr
 // Given a value and a basic block we are trying to see if it is available in,
 // see if the value has a leader available in that block.
 Value *NewGVN::findPHIOfOpsLeader(const Expression *E,
+                                  const Instruction *OrigInst,
                                   const BasicBlock *BB) const {
   // It would already be constant if we could make it constant
   if (auto *CE = dyn_cast<ConstantExpression>(E))
@@ -3640,6 +3643,8 @@ Value *NewGVN::findPHIOfOpsLeader(const
 
   for (auto Member : *CC) {
     auto *MemberInst = dyn_cast<Instruction>(Member);
+    if (MemberInst == OrigInst)
+      continue;
     // Anything that isn't an instruction is always available.
     if (!MemberInst)
       return Member;




More information about the llvm-commits mailing list