Skip to content

Commit

Permalink
[GVN] Fix verifyRemoved() verification
Browse files Browse the repository at this point in the history
Fix the verification failure reported in
https://reviews.llvm.org/D141712#4413647. We need to remove the
load from the VN table as well, not just the leader table.

Also make sure that this verification always runs when assertions
are enabled, rather than only when -debug is passed.
  • Loading branch information
nikic committed Jun 12, 2023
1 parent 2b7c347 commit 282324a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions llvm/lib/Transforms/Scalar/GVN.cpp
Expand Up @@ -721,10 +721,8 @@ void GVNPass::ValueTable::erase(Value *V) {
/// verifyRemoved - Verify that the value is removed from all internal data
/// structures.
void GVNPass::ValueTable::verifyRemoved(const Value *V) const {
for (DenseMap<Value*, uint32_t>::const_iterator
I = valueNumbering.begin(), E = valueNumbering.end(); I != E; ++I) {
assert(I->first != V && "Inst still occurs in value numbering map!");
}
assert(!valueNumbering.contains(V) &&
"Inst still occurs in value numbering map!");
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -1476,6 +1474,7 @@ void GVNPass::eliminatePartiallyRedundantLoad(
replaceValuesPerBlockEntry(ValuesPerBlock, OldLoad, NewLoad);
if (uint32_t ValNo = VN.lookup(OldLoad, false))
removeFromLeaderTable(ValNo, OldLoad, OldLoad->getParent());
VN.erase(OldLoad);
removeInstruction(OldLoad);
}
}
Expand Down Expand Up @@ -2984,7 +2983,9 @@ bool GVNPass::performScalarPRE(Instruction *CurInst) {
PREInstr = CurInst->clone();
if (!performScalarPREInsertion(PREInstr, PREPred, CurrentBlock, ValNo)) {
// If we failed insertion, make sure we remove the instruction.
LLVM_DEBUG(verifyRemoved(PREInstr));
#ifndef NDEBUG
verifyRemoved(PREInstr);
#endif
PREInstr->deleteValue();
return false;
}
Expand Down Expand Up @@ -3123,7 +3124,9 @@ void GVNPass::removeInstruction(Instruction *I) {
if (MD) MD->removeInstruction(I);
if (MSSAU)
MSSAU->removeMemoryAccess(I);
LLVM_DEBUG(verifyRemoved(I));
#ifndef NDEBUG
verifyRemoved(I);
#endif
ICF->removeInstruction(I);
I->eraseFromParent();
}
Expand Down

0 comments on commit 282324a

Please sign in to comment.