aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/BasicBlock.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2020-11-29 09:55:04 -0500
committerSanjay Patel <spatel@rotateright.com>2020-11-29 09:55:04 -0500
commitce134da4b18c27bbeba4e32f5813b1a3b043066e (patch)
tree0a60c8f7d92a1fb1fbc76705154176df5687b29f /llvm/lib/IR/BasicBlock.cpp
parent2cebad702cdff8c320c8afa748626e8cc1b3b2f3 (diff)
downloadllvm-ce134da4b18c27bbeba4e32f5813b1a3b043066e.zip
llvm-ce134da4b18c27bbeba4e32f5813b1a3b043066e.tar.gz
llvm-ce134da4b18c27bbeba4e32f5813b1a3b043066e.tar.bz2
[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." (!)
Diffstat (limited to 'llvm/lib/IR/BasicBlock.cpp')
-rw-r--r--llvm/lib/IR/BasicBlock.cpp26
1 files changed, 12 insertions, 14 deletions
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index 3166626..3268641 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -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();
}
}
}