[llvm] [SCEV] Rework IncrementWrapFlags (PR #219559)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 22 06:07:00 PDT 2026
================
@@ -15374,39 +15387,13 @@ const SCEVAddRecExpr *ScalarEvolution::convertSCEVToAddRecWithPredicates(
SmallVectorImpl<const SCEVPredicate *> &Preds) {
SmallVector<const SCEVPredicate *> TransformPreds;
S = SCEVPredicateRewriter::rewrite(S, L, *this, &TransformPreds, nullptr);
- auto *AddRec = dyn_cast<SCEVAddRecExpr>(S);
-
- if (!AddRec)
- return nullptr;
-
- // Check if any of the transformed predicates is known to be false. In that
- // case, it doesn't make sense to convert to a predicated AddRec, as the
- // versioned loop will never execute.
- for (const SCEVPredicate *Pred : TransformPreds) {
- auto *WrapPred = dyn_cast<SCEVWrapPredicate>(Pred);
- if (!WrapPred || WrapPred->getFlags() != SCEVWrapPredicate::IncrementNSSW)
- continue;
-
- const SCEVAddRecExpr *AddRecToCheck = WrapPred->getExpr();
- const SCEV *ExitCount = getBackedgeTakenCount(AddRecToCheck->getLoop());
- if (isa<SCEVCouldNotCompute>(ExitCount))
- continue;
-
- const SCEV *Step = AddRecToCheck->getStepRecurrence(*this);
- if (!Step->isOne())
- continue;
-
- ExitCount = getTruncateOrSignExtend(ExitCount, Step->getType());
- const SCEV *Add = getAddExpr(AddRecToCheck->getStart(), ExitCount);
- if (isKnownPredicate(CmpInst::ICMP_SLT, Add, AddRecToCheck->getStart()))
- return nullptr;
+ if (auto *AddRec = dyn_cast<SCEVAddRecExpr>(S)) {
+ // Since the transformation was successful, we can now transfer the SCEV
+ // predicates.
+ append_range(Preds, TransformPreds);
+ return AddRec;
}
----------------
artagnon wrote:
Split out as https://github.com/llvm/llvm-project/pull/225086.
https://github.com/llvm/llvm-project/pull/219559
More information about the llvm-commits
mailing list