forked from OSchip/llvm-project
[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.
This commit is contained in:
parent
035833ae42
commit
b85f91fdce
|
@ -4404,16 +4404,18 @@ Value *llvm::SimplifyExtractElementInst(Value *Vec, Value *Idx,
|
|||
/// See if we can fold the given phi. If not, returns null.
|
||||
static Value *SimplifyPHINode(PHINode *PN, const SimplifyQuery &Q) {
|
||||
// Is there an identical PHI node before this one in this basic block?
|
||||
for (PHINode &Src : PN->getParent()->phis()) {
|
||||
// Once we've reached the PHI node we've been asked about, stop looking.
|
||||
if (&Src == PN)
|
||||
break;
|
||||
// If the previous PHI is currently trivially dead, ignore it,
|
||||
// it might have been already recorded as being dead.
|
||||
if (Src.use_empty())
|
||||
continue;
|
||||
if (PN->isIdenticalToWhenDefined(&Src))
|
||||
return &Src;
|
||||
if (BasicBlock *BB = PN->getParent()) {
|
||||
for (PHINode &Src : BB->phis()) {
|
||||
// Once we've reached the PHI node we've been asked about, stop looking.
|
||||
if (&Src == PN)
|
||||
break;
|
||||
// If the previous PHI is currently trivially dead, ignore it,
|
||||
// it might have been already recorded as being dead.
|
||||
if (Src.use_empty())
|
||||
continue;
|
||||
if (PN->isIdenticalToWhenDefined(&Src))
|
||||
return &Src;
|
||||
}
|
||||
}
|
||||
|
||||
// If all of the PHI's incoming values are the same then replace the PHI node
|
||||
|
|
Loading…
Reference in New Issue