[llvm] Adding the support for vectorization of loops with load based tripcount (PR #209390)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 18 13:57:12 PDT 2026
================
@@ -15684,28 +15761,45 @@ const SCEV *PredicatedScalarEvolution::getPredicatedSCEV(const SCEV *Expr) {
Expr = Entry.second;
const SCEV *NewSCEV = SE.rewriteUsingPredicate(Expr, &L, *Preds);
+
+ if (!TripCountInvariantMap.empty()) {
+ NewSCEV =
+ SCEVParameterRewriter::rewrite(NewSCEV, SE, TripCountInvariantMap);
+ }
+
Entry = {Generation, NewSCEV};
return NewSCEV;
}
const SCEV *PredicatedScalarEvolution::getBackedgeTakenCount() {
if (!BackedgeCount) {
- SmallVector<const SCEVPredicate *, 4> Preds;
- BackedgeCount = SE.getPredicatedBackedgeTakenCount(&L, Preds);
- for (const auto *P : Preds)
- addPredicate(*P);
+ if (!TripCountInvariantPreds.empty()) {
+ BackedgeCount = SE.computeBackedgeTakenCountWithTripCountInvariants(
+ &L, TripCountInvariantPreds, /*SymbolicMax=*/false);
+ } else {
+ SmallVector<const SCEVPredicate *, 4> Preds;
+ BackedgeCount = SE.getPredicatedBackedgeTakenCount(&L, Preds);
+ for (const auto *P : Preds)
+ addPredicate(*P);
+ }
}
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);
+ if (!TripCountInvariantPreds.empty()) {
+ SymbolicMaxBackedgeCount =
+ SE.computeBackedgeTakenCountWithTripCountInvariants(
+ &L, TripCountInvariantPreds, /*SymbolicMax=*/true);
+ } else {
+ SmallVector<const SCEVPredicate *, 4> Preds;
+ SymbolicMaxBackedgeCount =
+ SE.getPredicatedSymbolicMaxBackedgeTakenCount(&L, Preds);
+ for (const auto *P : Preds)
+ addPredicate(*P);
+ }
----------------
artagnon wrote:
Actually, as the TripCountPredicate is logically independent, can we avoid making changes to SCEV, and create the predicate in LV directly? See also https://github.com/llvm/llvm-project/pull/182595?
https://github.com/llvm/llvm-project/pull/209390
More information about the llvm-commits
mailing list