[llvm] 1dc38f8 - [IR] improve code comment/logic in removePredecessor(); NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 30 07:56:41 PST 2020


Author: Sanjay Patel
Date: 2020-11-30T10:51:30-05:00
New Revision: 1dc38f8cfbbc4cce12f8416a1e51d38285e6872f

URL: https://github.com/llvm/llvm-project/commit/1dc38f8cfbbc4cce12f8416a1e51d38285e6872f
DIFF: https://github.com/llvm/llvm-project/commit/1dc38f8cfbbc4cce12f8416a1e51d38285e6872f.diff

LOG: [IR] improve code comment/logic in removePredecessor(); NFC

This was suggested in the post-commit review of ce134da4b1.

Added: 
    

Modified: 
    llvm/lib/IR/BasicBlock.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index 3268641ddf19..95b8602b9b6c 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -333,14 +333,16 @@ void BasicBlock::removePredecessor(BasicBlock *Pred,
     Phi.removeIncomingValue(Pred, !KeepOneInputPHIs);
     if (KeepOneInputPHIs)
       continue;
-    // If we have a single predecessor, removeIncomingValue erased the PHI
-    // node itself.
+
+    // If we have a single predecessor, removeIncomingValue may have erased the
+    // PHI node itself.
+    if (NumPreds == 1)
+      continue;
+
     // Try to replace the PHI node with a constant value.
-    if (NumPreds > 1) {
-      if (Value *PhiConstant = Phi.hasConstantValue()) {
-        Phi.replaceAllUsesWith(PhiConstant);
-        Phi.eraseFromParent();
-      }
+    if (Value *PhiConstant = Phi.hasConstantValue()) {
+      Phi.replaceAllUsesWith(PhiConstant);
+      Phi.eraseFromParent();
     }
   }
 }


        


More information about the llvm-commits mailing list