[IR] simplify code in removePredecessor(); NFCI

As suggested in D92247 (and independent of whatever we decide to do there),
this code is confusing as-is. Hopefully, this is at least mildly better.

We might be able to do better still, but we have a function called
"removePredecessor" with this behavior:
"Note that this function does not actually remove the predecessor." (!)
This commit is contained in:
Sanjay Patel
2020-11-29 09:55:04 -05:00
parent 2cebad702c
commit ce134da4b1

View File

@@ -327,21 +327,19 @@ void BasicBlock::removePredecessor(BasicBlock *Pred,
// Return early if there are no PHI nodes to update.
if (!isa<PHINode>(begin()))
return;
unsigned NumPreds = cast<PHINode>(front()).getNumIncomingValues();
// Update all PHI nodes.
for (iterator II = begin(); isa<PHINode>(II);) {
PHINode *PN = cast<PHINode>(II++);
PN->removeIncomingValue(Pred, !KeepOneInputPHIs);
if (!KeepOneInputPHIs) {
// If we have a single predecessor, removeIncomingValue erased the PHI
// node itself.
if (NumPreds > 1) {
if (Value *PNV = PN->hasConstantValue()) {
// Replace the PHI node with its constant value.
PN->replaceAllUsesWith(PNV);
PN->eraseFromParent();
}
unsigned NumPreds = cast<PHINode>(front()).getNumIncomingValues();
for (PHINode &Phi : make_early_inc_range(phis())) {
Phi.removeIncomingValue(Pred, !KeepOneInputPHIs);
if (KeepOneInputPHIs)
continue;
// If we have a single predecessor, removeIncomingValue erased the PHI
// node itself.
// Try to replace the PHI node with a constant value.
if (NumPreds > 1) {
if (Value *PhiConstant = Phi.hasConstantValue()) {
Phi.replaceAllUsesWith(PhiConstant);
Phi.eraseFromParent();
}
}
}