Fix 3113: If we have a dead cyclic PHI, replace the whole thing
with an undef.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@59972 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/CodeGenPrepare.cpp b/lib/Transforms/Scalar/CodeGenPrepare.cpp
index a04ccfe..b8664b0 100644
--- a/lib/Transforms/Scalar/CodeGenPrepare.cpp
+++ b/lib/Transforms/Scalar/CodeGenPrepare.cpp
@@ -206,7 +206,10 @@
if (DestBB->getSinglePredecessor()) {
// If DestBB has single-entry PHI nodes, fold them.
while (PHINode *PN = dyn_cast<PHINode>(DestBB->begin())) {
- PN->replaceAllUsesWith(PN->getIncomingValue(0));
+ Value *NewVal = PN->getIncomingValue(0);
+ // Replace self referencing PHI with undef, it must be dead.
+ if (NewVal == PN) NewVal = UndefValue::get(PN->getType());
+ PN->replaceAllUsesWith(NewVal);
PN->eraseFromParent();
}
@@ -569,6 +572,9 @@
if (Instruction *I = dyn_cast_or_null<Instruction>(AddrInst))
AddrModeInsts.push_back(I);
+ if (AddrInst && !AddrInst->hasOneUse())
+ ;
+ else
switch (Opcode) {
case Instruction::PtrToInt:
// PtrToInt is always a noop, as we know that the int type is pointer sized.