Skip to content

Commit b85f91f

Browse files
committed
[InstSimplify] SimplifyPHINode(): check that instruction is in basic block first
As pointed out in post-commit review, this can legally be called on instructions that are not inserted into basic blocks, so don't blindly assume that there is basic block.
1 parent 035833a commit b85f91f

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -4404,16 +4404,18 @@ Value *llvm::SimplifyExtractElementInst(Value *Vec, Value *Idx,
44044404
/// See if we can fold the given phi. If not, returns null.
44054405
static Value *SimplifyPHINode(PHINode *PN, const SimplifyQuery &Q) {
44064406
// Is there an identical PHI node before this one in this basic block?
4407-
for (PHINode &Src : PN->getParent()->phis()) {
4408-
// Once we've reached the PHI node we've been asked about, stop looking.
4409-
if (&Src == PN)
4410-
break;
4411-
// If the previous PHI is currently trivially dead, ignore it,
4412-
// it might have been already recorded as being dead.
4413-
if (Src.use_empty())
4414-
continue;
4415-
if (PN->isIdenticalToWhenDefined(&Src))
4416-
return &Src;
4407+
if (BasicBlock *BB = PN->getParent()) {
4408+
for (PHINode &Src : BB->phis()) {
4409+
// Once we've reached the PHI node we've been asked about, stop looking.
4410+
if (&Src == PN)
4411+
break;
4412+
// If the previous PHI is currently trivially dead, ignore it,
4413+
// it might have been already recorded as being dead.
4414+
if (Src.use_empty())
4415+
continue;
4416+
if (PN->isIdenticalToWhenDefined(&Src))
4417+
return &Src;
4418+
}
44174419
}
44184420

44194421
// If all of the PHI's incoming values are the same then replace the PHI node

0 commit comments

Comments
 (0)