[PATCH] D100264: [SCEV] Don't walk uses of phis without SCEV expression when forgetting
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 12 14:11:41 PDT 2021
nikic updated this revision to Diff 336958.
nikic marked an inline comment as done.
nikic added a comment.
Add const qualifier.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100264/new/
https://reviews.llvm.org/D100264
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
@@ -7020,13 +7020,16 @@
}
/// Push PHI nodes in the header of the given loop onto the given Worklist.
-static void
-PushLoopPHIs(const Loop *L, SmallVectorImpl<Instruction *> &Worklist) {
+/// Only push PHIs for which a SCEV expression has been cached, otherwise there
+/// cannot be any dependent expressions to invalidate.
+void ScalarEvolution::pushCachedLoopPHIs(
+ const Loop *L, SmallVectorImpl<Instruction *> &Worklist) const {
BasicBlock *Header = L->getHeader();
-
- // Push all Loop-header PHIs onto the Worklist stack.
- for (PHINode &PN : Header->phis())
- Worklist.push_back(&PN);
+ for (PHINode &PN : Header->phis()) {
+ auto It = ValueExprMap.find_as(static_cast<Value *>(&PN));
+ if (It != ValueExprMap.end())
+ Worklist.push_back(&PN);
+ }
}
const ScalarEvolution::BackedgeTakenInfo &
@@ -7087,7 +7090,7 @@
// it handles SCEVUnknown PHI nodes specially.
if (Result.hasAnyInfo()) {
SmallVector<Instruction *, 16> Worklist;
- PushLoopPHIs(L, Worklist);
+ pushCachedLoopPHIs(L, Worklist);
SmallPtrSet<Instruction *, 8> Discovered;
while (!Worklist.empty()) {
@@ -7210,7 +7213,7 @@
}
// Drop information about expressions based on loop-header PHIs.
- PushLoopPHIs(CurrL, Worklist);
+ pushCachedLoopPHIs(CurrL, Worklist);
while (!Worklist.empty()) {
Instruction *I = Worklist.pop_back_val();
Index: llvm/include/llvm/Analysis/ScalarEvolution.h
===================================================================
--- llvm/include/llvm/Analysis/ScalarEvolution.h
+++ llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -2053,6 +2053,12 @@
std::tuple<SCEV *, FoldingSetNodeID, void *>
findExistingSCEVInCache(SCEVTypes SCEVType, ArrayRef<const SCEV *> Ops);
+ /// Push PHI nodes in the header of the given loop onto the given Worklist
+ /// if they have a cached SCEV expression. If no expression is cached, then
+ /// there also aren't any dependent expressions to invalidate.
+ void pushCachedLoopPHIs(const Loop *L,
+ SmallVectorImpl<Instruction *> &Worklist) const;
+
FoldingSet<SCEV> UniqueSCEVs;
FoldingSet<SCEVPredicate> UniquePreds;
BumpPtrAllocator SCEVAllocator;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100264.336958.patch
Type: text/x-patch
Size: 2414 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210412/886c48e6/attachment.bin>
More information about the llvm-commits
mailing list