[llvm] r304194 - NewGVN: Fix PR33194, memory corruption by putting temporary instructions in tables sometimes.

Daniel Berlin via llvm-commits llvm-commits at lists.llvm.org
Mon May 29 23:42:30 PDT 2017


Author: dannyb
Date: Tue May 30 01:42:29 2017
New Revision: 304194

URL: http://llvm.org/viewvc/llvm-project?rev=304194&view=rev
Log:
NewGVN: Fix PR33194, memory corruption by putting temporary instructions in tables sometimes.

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=304194&r1=304193&r2=304194&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp Tue May 30 01:42:29 2017
@@ -956,8 +956,12 @@ const Expression *NewGVN::checkSimplific
   if (CC && CC->getDefiningExpr()) {
     // If we simplified to something else, we need to communicate
     // that we're users of the value we simplified to.
-    if (I != V)
-      addAdditionalUsers(V, I);
+    if (I != V) {
+      // Don't add temporary instructions to the user lists.
+      if (!AllTempInstructions.count(I))
+        addAdditionalUsers(V, I);
+    }
+
     if (I)
       DEBUG(dbgs() << "Simplified " << *I << " to "
                    << " expression " << *CC->getDefiningExpr() << "\n");
@@ -2502,9 +2506,8 @@ NewGVN::makePossiblePhiOfOps(Instruction
         // Clone the instruction, create an expression from it, and see if we
         // have a leader.
         Instruction *ValueOp = I->clone();
-        auto Iter = TempToMemory.end();
         if (MemAccess)
-          Iter = TempToMemory.insert({ValueOp, MemAccess}).first;
+          TempToMemory.insert({ValueOp, MemAccess});
 
         for (auto &Op : ValueOp->operands()) {
           Op = Op->DoPHITranslation(PHIBlock, PredBB);
@@ -2523,7 +2526,7 @@ NewGVN::makePossiblePhiOfOps(Instruction
         AllTempInstructions.erase(ValueOp);
         ValueOp->deleteValue();
         if (MemAccess)
-          TempToMemory.erase(Iter);
+          TempToMemory.erase(ValueOp);
         if (!E)
           return nullptr;
         FoundVal = findPhiOfOpsLeader(E, PredBB);




More information about the llvm-commits mailing list