Skip to content

Commit 935c8b6

Browse files
committed
Revert "InstSimplify: Remove null parent checks"
This reverts commit 2ca21e8. Dependent commit to be reverted
1 parent dd1c79b commit 935c8b6

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ static bool valueDominatesPHI(Value *V, PHINode *P, const DominatorTree *DT) {
218218
// Arguments and constants dominate all instructions.
219219
return true;
220220

221+
// If we are processing instructions (and/or basic blocks) that have not been
222+
// fully added to a function, the parent nodes may still be null. Simply
223+
// return the conservative answer in these cases.
224+
if (!I->getParent() || !P->getParent() || !I->getFunction())
225+
return false;
226+
221227
// If we have a DominatorTree then do a precise test.
222228
if (DT)
223229
return DT->dominates(I, P);
@@ -2632,7 +2638,7 @@ static bool isAllocDisjoint(const Value *V) {
26322638
// that might be resolve lazily to symbols in another dynamically-loaded
26332639
// library (and, thus, could be malloc'ed by the implementation).
26342640
if (const AllocaInst *AI = dyn_cast<AllocaInst>(V))
2635-
return AI->isStaticAlloca();
2641+
return AI->getParent() && AI->getFunction() && AI->isStaticAlloca();
26362642
if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
26372643
return (GV->hasLocalLinkage() || GV->hasHiddenVisibility() ||
26382644
GV->hasProtectedVisibility() || GV->hasGlobalUnnamedAddr()) &&
@@ -3663,7 +3669,7 @@ static Value *simplifyICmpWithDominatingAssume(CmpInst::Predicate Predicate,
36633669
Value *LHS, Value *RHS,
36643670
const SimplifyQuery &Q) {
36653671
// Gracefully handle instructions that have not been inserted yet.
3666-
if (!Q.AC || !Q.CxtI)
3672+
if (!Q.AC || !Q.CxtI || !Q.CxtI->getParent())
36673673
return nullptr;
36683674

36693675
for (Value *AssumeBaseOp : {LHS, RHS}) {
@@ -6469,6 +6475,9 @@ static Value *simplifyIntrinsic(CallBase *Call, Value *Callee,
64696475
if (!NumOperands) {
64706476
switch (IID) {
64716477
case Intrinsic::vscale: {
6478+
// Call may not be inserted into the IR yet at point of calling simplify.
6479+
if (!Call->getParent() || !Call->getParent()->getParent())
6480+
return nullptr;
64726481
auto Attr = Call->getFunction()->getFnAttribute(Attribute::VScaleRange);
64736482
if (!Attr.isValid())
64746483
return nullptr;
@@ -6916,7 +6925,10 @@ static bool replaceAndRecursivelySimplifyImpl(
69166925
// Replace the instruction with its simplified value.
69176926
I->replaceAllUsesWith(SimpleV);
69186927

6919-
if (!I->isEHPad() && !I->isTerminator() && !I->mayHaveSideEffects())
6928+
// Gracefully handle edge cases where the instruction is not wired into any
6929+
// parent block.
6930+
if (I->getParent() && !I->isEHPad() && !I->isTerminator() &&
6931+
!I->mayHaveSideEffects())
69206932
I->eraseFromParent();
69216933
} else {
69226934
Worklist.insert(I);
@@ -6945,7 +6957,10 @@ static bool replaceAndRecursivelySimplifyImpl(
69456957
// Replace the instruction with its simplified value.
69466958
I->replaceAllUsesWith(SimpleV);
69476959

6948-
if (!I->isEHPad() && !I->isTerminator() && !I->mayHaveSideEffects())
6960+
// Gracefully handle edge cases where the instruction is not wired into any
6961+
// parent block.
6962+
if (I->getParent() && !I->isEHPad() && !I->isTerminator() &&
6963+
!I->mayHaveSideEffects())
69496964
I->eraseFromParent();
69506965
}
69516966
return Simplified;

0 commit comments

Comments
 (0)