Skip to content

Commit 2ca21e8

Browse files
committed
InstSimplify: Remove null parent checks
The feature to operate on incomplete IR was barely used an poorly tested.
1 parent 1536e29 commit 2ca21e8

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,6 @@ 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-
227221
// If we have a DominatorTree then do a precise test.
228222
if (DT)
229223
return DT->dominates(I, P);
@@ -2638,7 +2632,7 @@ static bool isAllocDisjoint(const Value *V) {
26382632
// that might be resolve lazily to symbols in another dynamically-loaded
26392633
// library (and, thus, could be malloc'ed by the implementation).
26402634
if (const AllocaInst *AI = dyn_cast<AllocaInst>(V))
2641-
return AI->getParent() && AI->getFunction() && AI->isStaticAlloca();
2635+
return AI->isStaticAlloca();
26422636
if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
26432637
return (GV->hasLocalLinkage() || GV->hasHiddenVisibility() ||
26442638
GV->hasProtectedVisibility() || GV->hasGlobalUnnamedAddr()) &&
@@ -3669,7 +3663,7 @@ static Value *simplifyICmpWithDominatingAssume(CmpInst::Predicate Predicate,
36693663
Value *LHS, Value *RHS,
36703664
const SimplifyQuery &Q) {
36713665
// Gracefully handle instructions that have not been inserted yet.
3672-
if (!Q.AC || !Q.CxtI || !Q.CxtI->getParent())
3666+
if (!Q.AC || !Q.CxtI)
36733667
return nullptr;
36743668

36753669
for (Value *AssumeBaseOp : {LHS, RHS}) {
@@ -6474,9 +6468,6 @@ static Value *simplifyIntrinsic(CallBase *Call, Value *Callee,
64746468
if (!NumOperands) {
64756469
switch (IID) {
64766470
case Intrinsic::vscale: {
6477-
// Call may not be inserted into the IR yet at point of calling simplify.
6478-
if (!Call->getParent() || !Call->getParent()->getParent())
6479-
return nullptr;
64806471
auto Attr = Call->getFunction()->getFnAttribute(Attribute::VScaleRange);
64816472
if (!Attr.isValid())
64826473
return nullptr;
@@ -6924,10 +6915,7 @@ static bool replaceAndRecursivelySimplifyImpl(
69246915
// Replace the instruction with its simplified value.
69256916
I->replaceAllUsesWith(SimpleV);
69266917

6927-
// Gracefully handle edge cases where the instruction is not wired into any
6928-
// parent block.
6929-
if (I->getParent() && !I->isEHPad() && !I->isTerminator() &&
6930-
!I->mayHaveSideEffects())
6918+
if (!I->isEHPad() && !I->isTerminator() && !I->mayHaveSideEffects())
69316919
I->eraseFromParent();
69326920
} else {
69336921
Worklist.insert(I);
@@ -6956,10 +6944,7 @@ static bool replaceAndRecursivelySimplifyImpl(
69566944
// Replace the instruction with its simplified value.
69576945
I->replaceAllUsesWith(SimpleV);
69586946

6959-
// Gracefully handle edge cases where the instruction is not wired into any
6960-
// parent block.
6961-
if (I->getParent() && !I->isEHPad() && !I->isTerminator() &&
6962-
!I->mayHaveSideEffects())
6947+
if (!I->isEHPad() && !I->isTerminator() && !I->mayHaveSideEffects())
69636948
I->eraseFromParent();
69646949
}
69656950
return Simplified;

0 commit comments

Comments
 (0)