[PATCH] D144848: [SCEV] Skip instrs with non-scevable types in forget[Loop,Value].
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 27 00:49:23 PST 2023
fhahn created this revision.
fhahn added reviewers: mkazantsev, nikic, reames.
Herald added subscribers: StephenFan, javed.absar, hiraditya.
Herald added a project: All.
fhahn requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
No SCEVs are formed for instructions with non-scevable types, so no
other SCEV expressions can depend on them. Skip those instructions and
their users when invalidating SCEV expressions.
To catch potential missed cases, the full def-use chains are traversed
after the cleanup to assert no entries in ValueExprMap remain.
Depends on D144847 <https://reviews.llvm.org/D144847>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D144848
Files:
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -8441,6 +8441,8 @@
SmallVectorImpl<const SCEV *> &ToForget) {
while (!Worklist.empty()) {
Instruction *I = Worklist.pop_back_val();
+ if (!isSCEVable(I->getType()))
+ continue;
ValueExprMapType::iterator It =
ValueExprMap.find_as(static_cast<Value *>(I));
@@ -8455,12 +8457,32 @@
}
}
+#ifndef NDEBUG
+void ScalarEvolution::verifyAllUsersClearedFromMap(
+ SmallVectorImpl<Instruction *> &Worklist,
+ SmallPtrSetImpl<Instruction *> &Visited) {
+ while (!Worklist.empty()) {
+ Instruction *I = Worklist.pop_back_val();
+ if (!isSCEVable(I->getType()))
+ continue;
+ assert(ValueExprMap.count(I) == 0 &&
+ "entry for I has not been removed properly");
+ PushDefUseChildren(I, Worklist, Visited);
+ }
+}
+#endif
+
void ScalarEvolution::forgetLoop(const Loop *L) {
SmallVector<const Loop *, 16> LoopWorklist(1, L);
SmallVector<Instruction *, 32> Worklist;
SmallPtrSet<Instruction *, 16> Visited;
SmallVector<const SCEV *, 16> ToForget;
+#ifndef NDEBUG
+ SmallVector<Instruction *, 16> VerificationWorklist;
+ SmallPtrSet<Instruction *, 8> VerificationVisited;
+#endif
+
// Iterate over all the loops and sub-loops to drop SCEV information.
while (!LoopWorklist.empty()) {
auto *CurrL = LoopWorklist.pop_back_val();
@@ -8487,6 +8509,9 @@
// Drop information about expressions based on loop-header PHIs.
PushLoopPHIs(CurrL, Worklist, Visited);
+#ifndef NDEBUG
+ PushLoopPHIs(CurrL, VerificationWorklist, VerificationVisited);
+#endif
visitAndClearUsers(Worklist, Visited, ToForget);
LoopPropertiesCache.erase(CurrL);
@@ -8495,6 +8520,10 @@
LoopWorklist.append(CurrL->begin(), CurrL->end());
}
forgetMemoizedResults(ToForget);
+
+#ifndef NDEBUG
+ verifyAllUsersClearedFromMap(VerificationWorklist, VerificationVisited);
+#endif
}
void ScalarEvolution::forgetTopmostLoop(const Loop *L) {
@@ -8514,6 +8543,14 @@
visitAndClearUsers(Worklist, Visited, ToForget);
forgetMemoizedResults(ToForget);
+
+#ifndef NDEBUG
+ SmallVector<Instruction *, 16> VerificationWorklist;
+ SmallPtrSet<Instruction *, 8> VerificationVisited;
+ Worklist.push_back(cast<Instruction>(V));
+ Visited.insert(cast<Instruction>(V));
+ verifyAllUsersClearedFromMap(VerificationWorklist, VerificationVisited);
+#endif
}
void ScalarEvolution::forgetLoopDispositions() { LoopDispositions.clear(); }
Index: llvm/include/llvm/Analysis/ScalarEvolution.h
===================================================================
--- llvm/include/llvm/Analysis/ScalarEvolution.h
+++ llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -2045,6 +2045,13 @@
SmallPtrSetImpl<Instruction *> &Visited,
SmallVectorImpl<const SCEV *> &ToForget);
+#ifndef NDEBUG
+ /// Iterate over instructions in \p Worlist and their users. Assert all users
+ /// have been removed from ValueExprMap.
+ void verifyAllUsersClearedFromMap(SmallVectorImpl<Instruction *> &Worklist,
+ SmallPtrSetImpl<Instruction *> &Visited);
+#endif
+
/// Return an existing SCEV for V if there is one, otherwise return nullptr.
const SCEV *getExistingSCEV(Value *V);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144848.500689.patch
Type: text/x-patch
Size: 3434 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230227/315af2b0/attachment.bin>
More information about the llvm-commits
mailing list