From e91b6db85f504f4fcaea141e268251e6fa16fd9a Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 28 Apr 2017 22:18:19 +0000 Subject: [PATCH] InferAddressSpaces: Avoid looking up deleted values 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 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/Scalar/InferAddressSpaces.cpp b/lib/Transforms/Scalar/InferAddressSpaces.cpp index a9505a45eef..a2ce9b4907d 100644 --- a/lib/Transforms/Scalar/InferAddressSpaces.cpp +++ b/lib/Transforms/Scalar/InferAddressSpaces.cpp @@ -815,6 +815,8 @@ bool InferAddressSpaces::rewriteWithNewAddressSpaces( NewV->setOperand(OperandNo, ValueWithNewAddrSpace.lookup(UndefUse->get())); } + SmallVector 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(V)) + DeadInstructions.push_back(I); + } } + for (Instruction *I : DeadInstructions) + RecursivelyDeleteTriviallyDeadInstructions(I); + return true; } -- 2.40.0