aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2024-12-20 20:49:37 +0000
committerGitHub <noreply@github.com>2024-12-20 20:49:37 +0000
commitdf8efbdbbfcde53b0f9f4f8ceb16b50eecd6e6d3 (patch)
tree8187f36671455fb19f9ad71e4593e0b9a453bc7e /llvm/lib/Analysis/ScalarEvolution.cpp
parent131acb07d814fabcc969dcaa63f4f352cd529267 (diff)
downloadllvm-df8efbdbbfcde53b0f9f4f8ceb16b50eecd6e6d3.zip
llvm-df8efbdbbfcde53b0f9f4f8ceb16b50eecd6e6d3.tar.gz
llvm-df8efbdbbfcde53b0f9f4f8ceb16b50eecd6e6d3.tar.bz2
[SCEV] Remove existing predicates implied by newly added ones. (#118185)
When adding a new predicate to a union predicate, some of the existing predicates may be implied by the new predicate. Remove any existing predicates that are already implied by the new predicate. Depends on https://github.com/llvm/llvm-project/pull/118184 to show the main benefit. PR: https://github.com/llvm/llvm-project/pull/118185
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 1e4bb1d..8ab5602 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -15081,8 +15081,19 @@ void SCEVUnionPredicate::add(const SCEVPredicate *N, ScalarEvolution &SE) {
}
// Only add predicate if it is not already implied by this union predicate.
- if (!implies(N, SE))
- Preds.push_back(N);
+ if (implies(N, SE))
+ return;
+
+ // Build a new vector containing the current predicates, except the ones that
+ // are implied by the new predicate N.
+ SmallVector<const SCEVPredicate *> PrunedPreds;
+ for (auto *P : Preds) {
+ if (N->implies(P, SE))
+ continue;
+ PrunedPreds.push_back(P);
+ }
+ Preds = std::move(PrunedPreds);
+ Preds.push_back(N);
}
PredicatedScalarEvolution::PredicatedScalarEvolution(ScalarEvolution &SE,