Skip to content

Commit 35afcbb

Browse files
mrdaybirdhiraditya
authored andcommitted
Add condition for RHS to be in the same loop, fix formatting
1 parent 778a7dd commit 35afcbb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13003,7 +13003,8 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
1300313003
const SCEV *End = nullptr, *BECount = nullptr,
1300413004
*BECountIfBackedgeTaken = nullptr;
1300513005
if (!isLoopInvariant(RHS, L)) {
13006-
if (const auto *RHSAddRec = dyn_cast<SCEVAddRecExpr>(RHS)) {
13006+
const auto *RHSAddRec = dyn_cast<SCEVAddRecExpr>(RHS);
13007+
if (RHSAddRec != nullptr && RHSAddRec->getLoop() == L) {
1300713008
/*
1300813009
The structure of loop we are trying to calculate backedge-count of:
1300913010
left = left_start
@@ -13026,7 +13027,8 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
1302613027
// check if RHSStride<0 and Stride-RHSStride will not overflow
1302713028
// FIXME: Can RHSStride be positive?
1302813029
if (isKnownNegative(RHSStride) &&
13029-
willNotOverflow(Instruction::Sub, /*Signed=*/true, Stride, RHSStride)) {
13030+
willNotOverflow(Instruction::Sub, /*Signed=*/true, Stride,
13031+
RHSStride)) {
1303013032

1303113033
const SCEV *Denominator = getMinusSCEV(Stride, RHSStride);
1303213034
if (isKnownPositive(Denominator)) {

0 commit comments

Comments
 (0)