// If AlternativeV is not nullptr, we care about both incoming values in PHI.
// PHI must be exactly: phi <ty> [ %BB, %V ], [ %OtherBB, %AlternativeV]
// where OtherBB is the single other predecessor of BB's only successor.
+
+ // If V is not an instruction defined in BB, just return it.
+ if (!isa<Instruction>(V) || cast<Instruction>(V)->getParent() != BB)
+ return V;
+
PHINode *PHI = nullptr;
BasicBlock *Succ = BB->getSingleSuccessor();