From c20ccd2c0209fdaae7f7efe066c4b59b4ca46842 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 28 Apr 2017 22:18:19 +0000 Subject: 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. llvm-svn: 301705 --- llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'llvm') diff --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp index a9505a45eef..a2ce9b4907d 100644 --- a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp +++ b/llvm/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; } -- cgit v1.2.3