[llvm] [SCEV][LV] Invalidate LCSSA exit phis more thoroughly (PR #69909)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 16 01:15:48 PST 2023
================
@@ -8408,6 +8408,35 @@ void ScalarEvolution::forgetValue(Value *V) {
forgetMemoizedResults(ToForget);
}
+void ScalarEvolution::forgetLcssaPhiWithNewPredecessor(PHINode *V) {
+ // If SCEV looked through a trivial LCSSA phi node, we might have SCEV's
+ // directly using a SCEVUnknown defined in the loop. After an extra
+ // predecessor is added, this is no longer valid. Find all SCEVUnknown's
+ // defined in the loop and invalidate any SCEV's making use of them.
+ if (isSCEVable(V->getType())) {
+ if (const SCEV *S = getExistingSCEV(V)) {
+ struct SCEVUnknownCollector {
+ SmallVector<const SCEV *, 8> Unknowns;
+
+ bool follow(const SCEV *S) {
+ // This could be restricted to unknowns defined in the loop.
+ if (isa<SCEVUnknown>(S))
+ Unknowns.push_back(S);
+ return true;
+ }
+ bool isDone() const { return false; }
+ };
+
+ SCEVUnknownCollector C;
+ visitAll(S, C);
+ forgetMemoizedResults(C.Unknowns);
+ }
+ }
+
+ // Also perform the normal invalidation.
+ forgetValue(V);
----------------
nikic wrote:
Yes. forgetValue() will skip non-SCEVable itself. I've converted this into an early exit for the whole function.
https://github.com/llvm/llvm-project/pull/69909
More information about the llvm-commits
mailing list