[llvm] d39f4ac - [SCEV] Unwind SCEVUnionPredicate from getPredicatedBackedgeTakenCount [NFC]
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 9 12:55:55 PST 2022
Author: Philip Reames
Date: 2022-02-09T12:55:40-08:00
New Revision: d39f4ac49428333988837ac51983aa1d757cbf5a
URL: https://github.com/llvm/llvm-project/commit/d39f4ac49428333988837ac51983aa1d757cbf5a
DIFF: https://github.com/llvm/llvm-project/commit/d39f4ac49428333988837ac51983aa1d757cbf5a.diff
LOG: [SCEV] Unwind SCEVUnionPredicate from getPredicatedBackedgeTakenCount [NFC]
For those curious, the whole reason for tracking the predicate set seperately as opposed to just immediately registering the dependencies appears to be allowing the printing code to print a result without changing the PSE state. It's slightly questionable if this justifies the complexity, but since we can preserve it with local ugliness, I did so.
Added:
Modified:
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h
index 07eb7678bc8cc..1af37422d5822 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -886,7 +886,7 @@ class ScalarEvolution {
/// the answer to be correct. Predicates can be checked with run-time
/// checks and can be used to perform loop versioning.
const SCEV *getPredicatedBackedgeTakenCount(const Loop *L,
- SCEVUnionPredicate &Predicates);
+ SmallVector<const SCEVPredicate *, 4> &Predicates);
/// When successful, this returns a SCEVConstant that is greater than or equal
/// to (i.e. a "conservative over-approximation") of the value returend by
@@ -1455,7 +1455,7 @@ class ScalarEvolution {
/// vector, this information can contain them and therefore a
/// SCEVPredicate argument should be added to getExact.
const SCEV *getExact(const Loop *L, ScalarEvolution *SE,
- SCEVUnionPredicate *Predicates = nullptr) const;
+ SmallVector<const SCEVPredicate *, 4> *Predicates = nullptr) const;
/// Return the number of times this loop exit may fall through to the back
/// edge, or SCEVCouldNotCompute. The loop is guaranteed not to exit via
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 1b270de4ed01d..79c0129846f5f 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -7708,7 +7708,7 @@ const SCEV *ScalarEvolution::getExitCount(const Loop *L,
const SCEV *
ScalarEvolution::getPredicatedBackedgeTakenCount(const Loop *L,
- SCEVUnionPredicate &Preds) {
+ SmallVector<const SCEVPredicate *, 4> &Preds) {
return getPredicatedBackedgeTakenInfo(L).getExact(L, this, &Preds);
}
@@ -7944,7 +7944,7 @@ void ScalarEvolution::forgetLoopDispositions(const Loop *L) {
/// the relevant loop exiting block using getExact(ExitingBlock, SE).
const SCEV *
ScalarEvolution::BackedgeTakenInfo::getExact(const Loop *L, ScalarEvolution *SE,
- SCEVUnionPredicate *Preds) const {
+ SmallVector<const SCEVPredicate *, 4> *Preds) const {
// If any exits were not computable, the loop is not computable.
if (!isComplete() || ExitNotTaken.empty())
return SE->getCouldNotCompute();
@@ -7968,7 +7968,7 @@ ScalarEvolution::BackedgeTakenInfo::getExact(const Loop *L, ScalarEvolution *SE,
if (Preds)
for (auto *P : ENT.Predicates)
- Preds->add(P);
+ Preds->push_back(P);
assert((Preds || ENT.hasAlwaysTruePredicate()) &&
"Predicate should be always true!");
@@ -12813,12 +12813,15 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
L->getHeader()->printAsOperand(OS, /*PrintType=*/false);
OS << ": ";
- SCEVUnionPredicate Pred;
- auto PBT = SE->getPredicatedBackedgeTakenCount(L, Pred);
+ SmallVector<const SCEVPredicate *, 4> Preds;
+ auto PBT = SE->getPredicatedBackedgeTakenCount(L, Preds);
if (!isa<SCEVCouldNotCompute>(PBT)) {
OS << "Predicated backedge-taken count is " << *PBT << "\n";
OS << " Predicates:\n";
- Pred.print(OS, 4);
+ SCEVUnionPredicate Dedup;
+ for (auto *P : Preds)
+ Dedup.add(P);
+ Dedup.print(OS, 4);
} else {
OS << "Unpredictable predicated backedge-taken count. ";
}
@@ -13894,9 +13897,10 @@ const SCEV *PredicatedScalarEvolution::getSCEV(Value *V) {
const SCEV *PredicatedScalarEvolution::getBackedgeTakenCount() {
if (!BackedgeCount) {
- SCEVUnionPredicate BackedgePred;
- BackedgeCount = SE.getPredicatedBackedgeTakenCount(&L, BackedgePred);
- addPredicate(BackedgePred);
+ SmallVector<const SCEVPredicate *, 4> Preds;
+ BackedgeCount = SE.getPredicatedBackedgeTakenCount(&L, Preds);
+ for (auto *P : Preds)
+ addPredicate(*P);
}
return BackedgeCount;
}
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index fbd42ce41a999..007578d9ada7e 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -2497,7 +2497,8 @@ Value *SCEVExpander::generateOverflowCheck(const SCEVAddRecExpr *AR,
assert(AR->isAffine() && "Cannot generate RT check for "
"non-affine expression");
- SCEVUnionPredicate Pred;
+ // FIXME: It is highly suspicious that we're ignoring the predicates here.
+ SmallVector<const SCEVPredicate *, 4> Pred;
const SCEV *ExitCount =
SE.getPredicatedBackedgeTakenCount(AR->getLoop(), Pred);
More information about the llvm-commits
mailing list