[llvm] r301705 - InferAddressSpaces: Avoid looking up deleted values
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 28 15:18:19 PDT 2017
Author: arsenm
Date: Fri Apr 28 17:18:19 2017
New Revision: 301705
URL: http://llvm.org/viewvc/llvm-project?rev=301705&view=rev
Log:
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.
Modified:
llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp?rev=301705&r1=301704&r2=301705&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp Fri Apr 28 17:18:19 2017
@@ -815,6 +815,8 @@ bool InferAddressSpaces::rewriteWithNewA
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::rewriteWithNewA
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::rewriteWithNewA
}
}
- 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;
}
More information about the llvm-commits
mailing list