[llvm] [Analysis] Add getPredicatedExitCount to ScalarEvolution (PR #105649)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 30 03:28:03 PDT 2024
================
@@ -8575,30 +8592,53 @@ const SCEV *ScalarEvolution::BackedgeTakenInfo::getExact(
}
/// Get the exact not taken count for this loop exit.
-const SCEV *
-ScalarEvolution::BackedgeTakenInfo::getExact(const BasicBlock *ExitingBlock,
- ScalarEvolution *SE) const {
+const SCEV *ScalarEvolution::BackedgeTakenInfo::getExact(
+ const BasicBlock *ExitingBlock, ScalarEvolution *SE,
+ SmallVectorImpl<const SCEVPredicate *> *Predicates) const {
for (const auto &ENT : ExitNotTaken)
- if (ENT.ExitingBlock == ExitingBlock && ENT.hasAlwaysTruePredicate())
- return ENT.ExactNotTaken;
+ if (ENT.ExitingBlock == ExitingBlock) {
+ if (ENT.hasAlwaysTruePredicate())
+ return ENT.ExactNotTaken;
+ else if (Predicates) {
+ for (const auto *P : ENT.Predicates)
+ Predicates->push_back(P);
+ return ENT.ExactNotTaken;
+ }
+ }
return SE->getCouldNotCompute();
}
const SCEV *ScalarEvolution::BackedgeTakenInfo::getConstantMax(
- const BasicBlock *ExitingBlock, ScalarEvolution *SE) const {
+ const BasicBlock *ExitingBlock, ScalarEvolution *SE,
+ SmallVectorImpl<const SCEVPredicate *> *Predicates) const {
for (const auto &ENT : ExitNotTaken)
- if (ENT.ExitingBlock == ExitingBlock && ENT.hasAlwaysTruePredicate())
- return ENT.ConstantMaxNotTaken;
+ if (ENT.ExitingBlock == ExitingBlock) {
----------------
fhahn wrote:
It would be great to avoid duplicating this logic multiple times by passing a lambda that returns the desired count (or pass `ExitCountKind` and select based on that).
Not sure if that would overall be much simpler/desirable though
https://github.com/llvm/llvm-project/pull/105649
More information about the llvm-commits
mailing list