Index: llvm/lib/Analysis/ScalarEvolution.cpp =================================================================== --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -5359,6 +5359,13 @@ } const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) { + // If the PHI is in the midst of being constructed, it does not make sense to + // compute a SCEV for it. Here we assume that for every predecessor block + // there is a corresponding incoming value in the PHI. + unsigned NumIncoming = PN->getNumIncomingValues(); + if (!PN->getParent()->hasNPredecessors(NumIncoming)) + return getUnknown(PN); + if (const SCEV *S = createAddRecFromPHI(PN)) return S;