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
This commit is contained in:
Matt Arsenault 2017-04-28 22:18:19 +00:00
parent a1e734050c
commit c20ccd2c02
1 changed files with 10 additions and 3 deletions

View 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;
}