[PATCH] D131488: [TypePromotion] Don't delete Insns when iterating
Andre Vieira via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 9 05:46:31 PDT 2022
avieira created this revision.
avieira added reviewers: dmgreen, SjoerdMeijer, fhahn, efriedma, rnk, adriantong1024, samparker.
Herald added a subscriber: hiraditya.
Herald added a project: All.
avieira requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Hi,
This patch changes the way we delete Insns in TypePromotion, such that we don't do it while iterating over the same BB we are deleting from. This hasn't been an issue before, I suspect because when searching up from icmp's we only delete Insns that are before the current Insn or in other BBs, but with the changes proposed in D111237 <https://reviews.llvm.org/D111237> it will be an issue.
https://reviews.llvm.org/D131488
Files:
llvm/lib/CodeGen/TypePromotion.cpp
Index: llvm/lib/CodeGen/TypePromotion.cpp
===================================================================
--- llvm/lib/CodeGen/TypePromotion.cpp
+++ llvm/lib/CodeGen/TypePromotion.cpp
@@ -106,9 +106,9 @@
SetVector<Value *> &Sources;
SetVector<Instruction *> &Sinks;
SmallPtrSetImpl<Instruction *> &SafeWrap;
+ SmallPtrSetImpl<Instruction *> &InstsToRemove;
IntegerType *ExtTy = nullptr;
SmallPtrSet<Value *, 8> NewInsts;
- SmallPtrSet<Instruction *, 4> InstsToRemove;
DenseMap<Value *, SmallVector<Type *, 4>> TruncTysMap;
SmallPtrSet<Value *, 8> Promoted;
@@ -120,12 +120,12 @@
void Cleanup();
public:
- IRPromoter(LLVMContext &C, unsigned Width,
- SetVector<Value *> &visited, SetVector<Value *> &sources,
- SetVector<Instruction *> &sinks,
- SmallPtrSetImpl<Instruction *> &wrap)
- : Ctx(C), PromotedWidth(Width), Visited(visited),
- Sources(sources), Sinks(sinks), SafeWrap(wrap) {
+ IRPromoter(LLVMContext &C, unsigned Width, SetVector<Value *> &visited,
+ SetVector<Value *> &sources, SetVector<Instruction *> &sinks,
+ SmallPtrSetImpl<Instruction *> &wrap,
+ SmallPtrSetImpl<Instruction *> &instsToRemove)
+ : Ctx(C), PromotedWidth(Width), Visited(visited), Sources(sources),
+ Sinks(sinks), SafeWrap(wrap), InstsToRemove(instsToRemove) {
ExtTy = IntegerType::get(Ctx, PromotedWidth);
}
@@ -139,6 +139,7 @@
SmallPtrSet<Value *, 16> AllVisited;
SmallPtrSet<Instruction *, 8> SafeToPromote;
SmallPtrSet<Instruction *, 4> SafeWrap;
+ SmallPtrSet<Instruction *, 4> InstsToRemove;
// Does V have the same size result type as TypeSize.
bool EqualTypeSize(Value *V);
@@ -602,7 +603,6 @@
for (auto *I : InstsToRemove) {
LLVM_DEBUG(dbgs() << "IR Promotion: Removing " << *I << "\n");
I->dropAllReferences();
- I->eraseFromParent();
}
}
@@ -874,7 +874,7 @@
return false;
IRPromoter Promoter(*Ctx, PromotedWidth, CurrentVisited, Sources, Sinks,
- SafeWrap);
+ SafeWrap, InstsToRemove);
Promoter.Mutate();
return true;
}
@@ -940,6 +940,11 @@
}
}
}
+ if (!InstsToRemove.empty()) {
+ for (auto *I : InstsToRemove)
+ I->eraseFromParent();
+ InstsToRemove.clear();
+ }
}
AllVisited.clear();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131488.451122.patch
Type: text/x-patch
Size: 2376 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220809/92ad4448/attachment.bin>
More information about the llvm-commits
mailing list