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