]> granicus.if.org Git - llvm/commitdiff
InferAddressSpaces: Avoid looking up deleted values
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Fri, 28 Apr 2017 22:18:19 +0000 (22:18 +0000)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Fri, 28 Apr 2017 22:18:19 +0000 (22:18 +0000)
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 before
the value map lookup, a few testcases crash.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301705 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InferAddressSpaces.cpp

index a9505a45eef56be8966626f73598b3ef83fa7773..a2ce9b4907dee676e46d72c51d21cdb0a73ce621 100644 (file)
@@ -815,6 +815,8 @@ bool InferAddressSpaces::rewriteWithNewAddressSpaces(
     NewV->setOperand(OperandNo, ValueWithNewAddrSpace.lookup(UndefUse->get()));
   }
 
+  SmallVector<Instruction *, 16> 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 @@ bool InferAddressSpaces::rewriteWithNewAddressSpaces(
           unsigned NewAS = NewV->getType()->getPointerAddressSpace();
           if (ASC->getDestAddressSpace() == NewAS) {
             ASC->replaceAllUsesWith(NewV);
-            ASC->eraseFromParent();
+            DeadInstructions.push_back(ASC);
             continue;
           }
         }
@@ -906,10 +908,15 @@ bool InferAddressSpaces::rewriteWithNewAddressSpaces(
       }
     }
 
-    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;
 }