[llvm] b85f91f - [InstSimplify] SimplifyPHINode(): check that instruction is in basic block first

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 27 12:32:33 PDT 2020


Author: Roman Lebedev
Date: 2020-08-27T22:32:03+03:00
New Revision: b85f91fdced8e94c43f3350152bcb2ccfa71ef14

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

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 41217ea792c5..3746bc66e426 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -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


        


More information about the llvm-commits mailing list