From: Chris Lattner Date: Fri, 17 Jun 2005 01:45:53 +0000 (+0000) Subject: Don't crash on: X = phi (X, X). X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=0289929c6212229980c9057853860ccfd3f81678;p=oota-llvm.git Don't crash on: X = phi (X, X). This fixes PR584 and Transforms/SimplifyCFG/2005-06-16-PHICrash.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22232 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index ad78506ad42..6a3b803cbdb 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1461,12 +1461,15 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { BasicBlock::iterator AfterPHIIt = BB->begin(); while (isa(AfterPHIIt)) { PHINode *PN = cast(AfterPHIIt++); - if (PN->getIncomingValue(0) == PN->getIncomingValue(1)) - PN->replaceAllUsesWith(PN->getIncomingValue(0)); - else if (!DominatesMergePoint(PN->getIncomingValue(0), BB, - &AggressiveInsts) || - !DominatesMergePoint(PN->getIncomingValue(1), BB, - &AggressiveInsts)) { + if (PN->getIncomingValue(0) == PN->getIncomingValue(1)) { + if (PN->getIncomingValue(0) != PN) + PN->replaceAllUsesWith(PN->getIncomingValue(0)); + else + PN->replaceAllUsesWith(UndefValue::get(PN->getType())); + } else if (!DominatesMergePoint(PN->getIncomingValue(0), BB, + &AggressiveInsts) || + !DominatesMergePoint(PN->getIncomingValue(1), BB, + &AggressiveInsts)) { CanPromote = false; break; }