[llvm] [SCEV] Init BE vars to CouldNotCompute in howManyLT (NFC) (PR #222892)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 11 02:10:43 PDT 2026
https://github.com/artagnon created https://github.com/llvm/llvm-project/pull/222892
This avoids the risk of initializing ExitLimit with nullptr BE variables, and cast-asserts on nullptr.
>From cc2f6f89aaf4eb567f903c663708175242e57c0c Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Fri, 11 Sep 2026 10:06:15 +0100
Subject: [PATCH] [SCEV] Init BE vars to CouldNotCompute in howManyLT (NFC)
This avoids the risk of initializing ExitLimit with nullptr BE
variables, and cast-asserts on nullptr.
---
llvm/lib/Analysis/ScalarEvolution.cpp | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 06f350fd2179b..f7063661403ef 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -13538,8 +13538,8 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
return RHS;
}
- const SCEV *End = nullptr, *BECount = nullptr,
- *BECountIfBackedgeTaken = nullptr;
+ const SCEV *End = nullptr, *BECount = getCouldNotCompute(),
+ *BECountIfBackedgeTaken = getCouldNotCompute();
if (!isLoopInvariant(RHS, L)) {
const auto *RHSAddRec = dyn_cast<SCEVAddRecExpr>(RHS);
if (PositiveStride && RHSAddRec != nullptr && RHSAddRec->getLoop() == L &&
@@ -13717,7 +13717,7 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
BECount = getUDivExpr(Numerator, Stride);
}
- if (!BECount) {
+ if (isa<SCEVCouldNotCompute>(BECount)) {
auto canProveRHSGreaterThanEqualStart = [&]() {
auto CondGE = IsSigned ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE;
const SCEV *GuardedRHS = applyLoopGuards(OrigRHS, L);
@@ -13780,8 +13780,7 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
bool MaxOrZero = false;
if (isa<SCEVConstant>(BECount)) {
ConstantMaxBECount = BECount;
- } else if (BECountIfBackedgeTaken &&
- isa<SCEVConstant>(BECountIfBackedgeTaken)) {
+ } else if (isa<SCEVConstant>(BECountIfBackedgeTaken)) {
// If we know exactly how many times the backedge will be taken if it's
// taken at least once, then the backedge count will either be that or
// zero.
More information about the llvm-commits
mailing list