[PATCH] D32553: InferAddressSpaces: Avoid looking up deleted values

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 26 12:42:50 PDT 2017


arsenm created this revision.
Herald added a subscriber: wdng.

While looking at pure addressing expressions, it's possible
for the value to appear later in Postorder.

      

I haven't been able to come up with a testcase where this
exhibits an actual issue, but if you insert a dump befoer
the value map lookup, a few testcases crash.


https://reviews.llvm.org/D32553

Files:
  lib/Transforms/Scalar/InferAddressSpaces.cpp


Index: lib/Transforms/Scalar/InferAddressSpaces.cpp
===================================================================
--- lib/Transforms/Scalar/InferAddressSpaces.cpp
+++ lib/Transforms/Scalar/InferAddressSpaces.cpp
@@ -815,6 +815,8 @@
     NewV->setOperand(OperandNo, ValueWithNewAddrSpace.lookup(UndefUse->get()));
   }
 
+  std::vector<Instruction *> DeadInstructions;
+
   // Replaces the uses of the old address expressions with the new ones.
   for (Value *V : Postorder) {
     Value *NewV = ValueWithNewAddrSpace.lookup(V);
@@ -888,7 +890,7 @@
           unsigned NewAS = NewV->getType()->getPointerAddressSpace();
           if (ASC->getDestAddressSpace() == NewAS) {
             ASC->replaceAllUsesWith(NewV);
-            ASC->eraseFromParent();
+            DeadInstructions.push_back(ASC);
             continue;
           }
         }
@@ -906,10 +908,15 @@
       }
     }
 
-    if (V->use_empty())
-      RecursivelyDeleteTriviallyDeadInstructions(V);
+    if (V->use_empty()) {
+      if (Instruction *I = dyn_cast<Instruction>(V))
+        DeadInstructions.push_back(I);
+    }
   }
 
+  for (Instruction *I : DeadInstructions)
+    RecursivelyDeleteTriviallyDeadInstructions(I);
+
   return true;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32553.96804.patch
Type: text/x-patch
Size: 1225 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170426/7814b3da/attachment.bin>


More information about the llvm-commits mailing list