-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SCEV] Add predicated version of getSymbolicMaxBackedgeTakenCount. #93498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8295,6 +8295,11 @@ const SCEV *ScalarEvolution::getBackedgeTakenCount(const Loop *L, | |
llvm_unreachable("Invalid ExitCountKind!"); | ||
} | ||
|
||
const SCEV *ScalarEvolution::getPredicatedSymbolicMaxBackedgeTakenCount( | ||
const Loop *L, SmallVector<const SCEVPredicate *, 4> &Preds) { | ||
return getPredicatedBackedgeTakenInfo(L).getSymbolicMax(L, this, &Preds); | ||
} | ||
|
||
bool ScalarEvolution::isBackedgeTakenCountMaxOrZero(const Loop *L) { | ||
return getBackedgeTakenInfo(L).isConstantMaxOrZero(this); | ||
} | ||
|
@@ -8311,7 +8316,7 @@ static void PushLoopPHIs(const Loop *L, | |
Worklist.push_back(&PN); | ||
} | ||
|
||
const ScalarEvolution::BackedgeTakenInfo & | ||
ScalarEvolution::BackedgeTakenInfo & | ||
ScalarEvolution::getPredicatedBackedgeTakenInfo(const Loop *L) { | ||
auto &BTI = getBackedgeTakenInfo(L); | ||
if (BTI.hasFullInfo()) | ||
|
@@ -8644,9 +8649,9 @@ ScalarEvolution::BackedgeTakenInfo::getConstantMax(ScalarEvolution *SE) const { | |
return getConstantMax(); | ||
} | ||
|
||
const SCEV * | ||
ScalarEvolution::BackedgeTakenInfo::getSymbolicMax(const Loop *L, | ||
ScalarEvolution *SE) { | ||
const SCEV *ScalarEvolution::BackedgeTakenInfo::getSymbolicMax( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps I'm wrong but this change looks to have taken inspiration (and a little code) from #88385. I'm happy for the collaboration but LLVM rules suggest it would have been polite to reference my PR or indicate co-authorship? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, this should have been referenced, apologies for that! To rectify that, how about reverting the patch and then recommitting with an adjusted message to include an attribution like
Happy to adjust as needed, if you think a different wording would be better There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's ok, there's no need to revert the patch and no harm done! Perhaps just something to remember in future that's all. Thanks! |
||
const Loop *L, ScalarEvolution *SE, | ||
SmallVector<const SCEVPredicate *, 4> *Predicates) { | ||
if (!SymbolicMax) { | ||
// Form an expression for the maximum exit count possible for this loop. We | ||
// merge the max and exact information to approximate a version of | ||
|
@@ -8661,6 +8666,12 @@ ScalarEvolution::BackedgeTakenInfo::getSymbolicMax(const Loop *L, | |
"We should only have known counts for exiting blocks that " | ||
"dominate latch!"); | ||
ExitCounts.push_back(ExitCount); | ||
if (Predicates) | ||
for (const auto *P : ENT.Predicates) | ||
Predicates->push_back(P); | ||
|
||
assert((Predicates || ENT.hasAlwaysTruePredicate()) && | ||
"Predicate should be always true!"); | ||
} | ||
} | ||
if (ExitCounts.empty()) | ||
|
@@ -13609,6 +13620,24 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE, | |
P->print(OS, 4); | ||
} | ||
|
||
Preds.clear(); | ||
auto *PredSymbolicMax = | ||
SE->getPredicatedSymbolicMaxBackedgeTakenCount(L, Preds); | ||
if (SymbolicBTC != PredSymbolicMax) { | ||
OS << "Loop "; | ||
L->getHeader()->printAsOperand(OS, /*PrintType=*/false); | ||
OS << ": "; | ||
if (!isa<SCEVCouldNotCompute>(PredSymbolicMax)) { | ||
OS << "Predicated symbolic max backedge-taken count is "; | ||
PrintSCEVWithTypeHint(OS, PredSymbolicMax); | ||
} else | ||
OS << "Unpredictable predicated symbolic max backedge-taken count."; | ||
OS << "\n"; | ||
OS << " Predicates:\n"; | ||
for (const auto *P : Preds) | ||
P->print(OS, 4); | ||
} | ||
|
||
if (SE->hasLoopInvariantBackedgeTakenCount(L)) { | ||
OS << "Loop "; | ||
L->getHeader()->printAsOperand(OS, /*PrintType=*/false); | ||
|
@@ -14822,6 +14851,17 @@ const SCEV *PredicatedScalarEvolution::getBackedgeTakenCount() { | |
return BackedgeCount; | ||
} | ||
|
||
const SCEV *PredicatedScalarEvolution::getSymbolicMaxBackedgeTakenCount() { | ||
if (!SymbolicMaxBackedgeCount) { | ||
SmallVector<const SCEVPredicate *, 4> Preds; | ||
SymbolicMaxBackedgeCount = | ||
SE.getPredicatedSymbolicMaxBackedgeTakenCount(&L, Preds); | ||
for (const auto *P : Preds) | ||
addPredicate(*P); | ||
} | ||
return SymbolicMaxBackedgeCount; | ||
} | ||
|
||
void PredicatedScalarEvolution::addPredicate(const SCEVPredicate &Pred) { | ||
if (Preds->implies(&Pred)) | ||
return; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added, thanks!