Skip to content

Commit 282324a

Browse files
committed
[GVN] Fix verifyRemoved() verification
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.
1 parent 2b7c347 commit 282324a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

llvm/lib/Transforms/Scalar/GVN.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -721,10 +721,8 @@ void GVNPass::ValueTable::erase(Value *V) {
721721
/// verifyRemoved - Verify that the value is removed from all internal data
722722
/// structures.
723723
void GVNPass::ValueTable::verifyRemoved(const Value *V) const {
724-
for (DenseMap<Value*, uint32_t>::const_iterator
725-
I = valueNumbering.begin(), E = valueNumbering.end(); I != E; ++I) {
726-
assert(I->first != V && "Inst still occurs in value numbering map!");
727-
}
724+
assert(!valueNumbering.contains(V) &&
725+
"Inst still occurs in value numbering map!");
728726
}
729727

730728
//===----------------------------------------------------------------------===//
@@ -1476,6 +1474,7 @@ void GVNPass::eliminatePartiallyRedundantLoad(
14761474
replaceValuesPerBlockEntry(ValuesPerBlock, OldLoad, NewLoad);
14771475
if (uint32_t ValNo = VN.lookup(OldLoad, false))
14781476
removeFromLeaderTable(ValNo, OldLoad, OldLoad->getParent());
1477+
VN.erase(OldLoad);
14791478
removeInstruction(OldLoad);
14801479
}
14811480
}
@@ -2984,7 +2983,9 @@ bool GVNPass::performScalarPRE(Instruction *CurInst) {
29842983
PREInstr = CurInst->clone();
29852984
if (!performScalarPREInsertion(PREInstr, PREPred, CurrentBlock, ValNo)) {
29862985
// If we failed insertion, make sure we remove the instruction.
2987-
LLVM_DEBUG(verifyRemoved(PREInstr));
2986+
#ifndef NDEBUG
2987+
verifyRemoved(PREInstr);
2988+
#endif
29882989
PREInstr->deleteValue();
29892990
return false;
29902991
}
@@ -3123,7 +3124,9 @@ void GVNPass::removeInstruction(Instruction *I) {
31233124
if (MD) MD->removeInstruction(I);
31243125
if (MSSAU)
31253126
MSSAU->removeMemoryAccess(I);
3126-
LLVM_DEBUG(verifyRemoved(I));
3127+
#ifndef NDEBUG
3128+
verifyRemoved(I);
3129+
#endif
31273130
ICF->removeInstruction(I);
31283131
I->eraseFromParent();
31293132
}

0 commit comments

Comments
 (0)