[llvm] 935c8b6 - Revert "InstSimplify: Remove null parent checks"

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 16 11:24:47 PDT 2023


Author: Arthur Eubanks
Date: 2023-06-16T11:24:28-07:00
New Revision: 935c8b6f3a4dda0ff881ed86faaad9fe5b276d70

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

LOG: Revert "InstSimplify: Remove null parent checks"

This reverts commit 2ca21e8775dd16189bb4c00c3f9553f17578a63c.

Dependent commit to be reverted

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 616873f87f313..13a4553b702d5 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -218,6 +218,12 @@ static bool valueDominatesPHI(Value *V, PHINode *P, const DominatorTree *DT) {
     // Arguments and constants dominate all instructions.
     return true;
 
+  // If we are processing instructions (and/or basic blocks) that have not been
+  // fully added to a function, the parent nodes may still be null. Simply
+  // return the conservative answer in these cases.
+  if (!I->getParent() || !P->getParent() || !I->getFunction())
+    return false;
+
   // If we have a DominatorTree then do a precise test.
   if (DT)
     return DT->dominates(I, P);
@@ -2632,7 +2638,7 @@ static bool isAllocDisjoint(const Value *V) {
   // that might be resolve lazily to symbols in another dynamically-loaded
   // library (and, thus, could be malloc'ed by the implementation).
   if (const AllocaInst *AI = dyn_cast<AllocaInst>(V))
-    return AI->isStaticAlloca();
+    return AI->getParent() && AI->getFunction() && AI->isStaticAlloca();
   if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
     return (GV->hasLocalLinkage() || GV->hasHiddenVisibility() ||
             GV->hasProtectedVisibility() || GV->hasGlobalUnnamedAddr()) &&
@@ -3663,7 +3669,7 @@ static Value *simplifyICmpWithDominatingAssume(CmpInst::Predicate Predicate,
                                                Value *LHS, Value *RHS,
                                                const SimplifyQuery &Q) {
   // Gracefully handle instructions that have not been inserted yet.
-  if (!Q.AC || !Q.CxtI)
+  if (!Q.AC || !Q.CxtI || !Q.CxtI->getParent())
     return nullptr;
 
   for (Value *AssumeBaseOp : {LHS, RHS}) {
@@ -6469,6 +6475,9 @@ static Value *simplifyIntrinsic(CallBase *Call, Value *Callee,
   if (!NumOperands) {
     switch (IID) {
     case Intrinsic::vscale: {
+      // Call may not be inserted into the IR yet at point of calling simplify.
+      if (!Call->getParent() || !Call->getParent()->getParent())
+        return nullptr;
       auto Attr = Call->getFunction()->getFnAttribute(Attribute::VScaleRange);
       if (!Attr.isValid())
         return nullptr;
@@ -6916,7 +6925,10 @@ static bool replaceAndRecursivelySimplifyImpl(
     // Replace the instruction with its simplified value.
     I->replaceAllUsesWith(SimpleV);
 
-    if (!I->isEHPad() && !I->isTerminator() && !I->mayHaveSideEffects())
+    // Gracefully handle edge cases where the instruction is not wired into any
+    // parent block.
+    if (I->getParent() && !I->isEHPad() && !I->isTerminator() &&
+        !I->mayHaveSideEffects())
       I->eraseFromParent();
   } else {
     Worklist.insert(I);
@@ -6945,7 +6957,10 @@ static bool replaceAndRecursivelySimplifyImpl(
     // Replace the instruction with its simplified value.
     I->replaceAllUsesWith(SimpleV);
 
-    if (!I->isEHPad() && !I->isTerminator() && !I->mayHaveSideEffects())
+    // Gracefully handle edge cases where the instruction is not wired into any
+    // parent block.
+    if (I->getParent() && !I->isEHPad() && !I->isTerminator() &&
+        !I->mayHaveSideEffects())
       I->eraseFromParent();
   }
   return Simplified;


        


More information about the llvm-commits mailing list