@@ -730,8 +730,9 @@ void GVNPass::ValueTable::erase(Value *V) {
730
730
// / verifyRemoved - Verify that the value is removed from all internal data
731
731
// / structures.
732
732
void GVNPass::ValueTable::verifyRemoved (const Value *V) const {
733
- assert (!valueNumbering.contains (V) &&
734
- " Inst still occurs in value numbering map!" );
733
+ if (V != nullptr )
734
+ assert (!valueNumbering.contains (V) &&
735
+ " Inst still occurs in value numbering map!" );
735
736
}
736
737
737
738
// ===----------------------------------------------------------------------===//
@@ -1574,7 +1575,7 @@ void GVNPass::eliminatePartiallyRedundantLoad(
1574
1575
I->setDebugLoc (Load->getDebugLoc ());
1575
1576
if (V->getType ()->isPtrOrPtrVectorTy ())
1576
1577
MD->invalidateCachedPointerInfo (V);
1577
- markInstructionForDeletion (Load);
1578
+ doInstructionDeletion (Load);
1578
1579
ORE->emit ([&]() {
1579
1580
return OptimizationRemark (DEBUG_TYPE, " LoadPRE" , Load)
1580
1581
<< " load eliminated by PRE" ;
@@ -1798,7 +1799,7 @@ bool GVNPass::PerformLoadPRE(LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
1798
1799
// Erase instructions generated by the failed PHI translation before
1799
1800
// trying to number them. PHI translation might insert instructions
1800
1801
// in basic blocks other than the current one, and we delete them
1801
- // directly, as markInstructionForDeletion only allows removing from the
1802
+ // directly, as doInstructionDeletion only allows removing from the
1802
1803
// current basic block.
1803
1804
NewInsts.pop_back_val ()->eraseFromParent ();
1804
1805
}
@@ -1997,7 +1998,7 @@ bool GVNPass::processNonLocalLoad(LoadInst *Load) {
1997
1998
I->setDebugLoc (Load->getDebugLoc ());
1998
1999
if (V->getType ()->isPtrOrPtrVectorTy ())
1999
2000
MD->invalidateCachedPointerInfo (V);
2000
- markInstructionForDeletion (Load);
2001
+ doInstructionDeletion (Load);
2001
2002
++NumGVNLoad;
2002
2003
reportLoadElim (Load, V, ORE);
2003
2004
return true ;
@@ -2067,7 +2068,7 @@ bool GVNPass::processAssumeIntrinsic(AssumeInst *IntrinsicI) {
2067
2068
}
2068
2069
}
2069
2070
if (isAssumeWithEmptyBundle (*IntrinsicI)) {
2070
- markInstructionForDeletion (IntrinsicI);
2071
+ doInstructionDeletion (IntrinsicI);
2071
2072
return true ;
2072
2073
}
2073
2074
return false ;
@@ -2179,7 +2180,7 @@ bool GVNPass::processLoad(LoadInst *L) {
2179
2180
return false ;
2180
2181
2181
2182
if (L->use_empty ()) {
2182
- markInstructionForDeletion (L);
2183
+ doInstructionDeletion (L);
2183
2184
return true ;
2184
2185
}
2185
2186
@@ -2209,13 +2210,13 @@ bool GVNPass::processLoad(LoadInst *L) {
2209
2210
// MaterializeAdjustedValue is responsible for combining metadata.
2210
2211
ICF->removeUsersOf (L);
2211
2212
L->replaceAllUsesWith (AvailableValue);
2212
- markInstructionForDeletion (L);
2213
2213
if (MSSAU)
2214
2214
MSSAU->removeMemoryAccess (L);
2215
2215
++NumGVNLoad;
2216
2216
reportLoadElim (L, AvailableValue, ORE);
2217
2217
// Tell MDA to reexamine the reused pointer since we might have more
2218
2218
// information after forwarding it.
2219
+ doInstructionDeletion (L);
2219
2220
if (MD && AvailableValue->getType ()->isPtrOrPtrVectorTy ())
2220
2221
MD->invalidateCachedPointerInfo (AvailableValue);
2221
2222
return true ;
@@ -2605,7 +2606,7 @@ bool GVNPass::processInstruction(Instruction *I) {
2605
2606
Changed = true ;
2606
2607
}
2607
2608
if (isInstructionTriviallyDead (I, TLI)) {
2608
- markInstructionForDeletion (I);
2609
+ doInstructionDeletion (I);
2609
2610
Changed = true ;
2610
2611
}
2611
2612
if (Changed) {
@@ -2723,7 +2724,7 @@ bool GVNPass::processInstruction(Instruction *I) {
2723
2724
patchAndReplaceAllUsesWith (I, Repl);
2724
2725
if (MD && Repl->getType ()->isPtrOrPtrVectorTy ())
2725
2726
MD->invalidateCachedPointerInfo (Repl);
2726
- markInstructionForDeletion (I);
2727
+ doInstructionDeletion (I);
2727
2728
return true ;
2728
2729
}
2729
2730
@@ -2799,10 +2800,6 @@ bool GVNPass::runImpl(Function &F, AssumptionCache &RunAC, DominatorTree &RunDT,
2799
2800
}
2800
2801
2801
2802
bool GVNPass::processBlock (BasicBlock *BB) {
2802
- // FIXME: Kill off InstrsToErase by doing erasing eagerly in a helper function
2803
- // (and incrementing BI before processing an instruction).
2804
- assert (InstrsToErase.empty () &&
2805
- " We expect InstrsToErase to be empty across iterations" );
2806
2803
if (DeadBlocks.count (BB))
2807
2804
return false ;
2808
2805
@@ -2820,41 +2817,12 @@ bool GVNPass::processBlock(BasicBlock *BB) {
2820
2817
VN.erase (PN);
2821
2818
removeInstruction (PN);
2822
2819
}
2823
-
2824
- for (BasicBlock::iterator BI = BB->begin (), BE = BB->end ();
2825
- BI != BE;) {
2820
+ for (BasicBlock::iterator BI = BB->begin (), BE = BB->end (); BI != BE;) {
2821
+ Instruction *Inst = &*BI++;
2826
2822
if (!ReplaceOperandsWithMap.empty ())
2827
- ChangedFunction |= replaceOperandsForInBlockEquality (&*BI);
2828
- ChangedFunction |= processInstruction (&*BI);
2829
-
2830
- if (InstrsToErase.empty ()) {
2831
- ++BI;
2832
- continue ;
2833
- }
2834
-
2835
- // If we need some instructions deleted, do it now.
2836
- NumGVNInstr += InstrsToErase.size ();
2837
-
2838
- // Avoid iterator invalidation.
2839
- bool AtStart = BI == BB->begin ();
2840
- if (!AtStart)
2841
- --BI;
2842
-
2843
- for (auto *I : InstrsToErase) {
2844
- assert (I->getParent () == BB && " Removing instruction from wrong block?" );
2845
- LLVM_DEBUG (dbgs () << " GVN removed: " << *I << ' \n ' );
2846
- salvageKnowledge (I, AC);
2847
- salvageDebugInfo (*I);
2848
- removeInstruction (I);
2849
- }
2850
- InstrsToErase.clear ();
2851
-
2852
- if (AtStart)
2853
- BI = BB->begin ();
2854
- else
2855
- ++BI;
2823
+ ChangedFunction |= replaceOperandsForInBlockEquality (Inst);
2824
+ ChangedFunction |= processInstruction (Inst);
2856
2825
}
2857
-
2858
2826
return ChangedFunction;
2859
2827
}
2860
2828
0 commit comments