Skip to content

Commit 3394ae0

Browse files
mrdaybirdhiraditya
authored andcommitted
Update comment formatting
1 parent 35afcbb commit 3394ae0

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13005,26 +13005,28 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
1300513005
if (!isLoopInvariant(RHS, L)) {
1300613006
const auto *RHSAddRec = dyn_cast<SCEVAddRecExpr>(RHS);
1300713007
if (RHSAddRec != nullptr && RHSAddRec->getLoop() == L) {
13008-
/*
13009-
The structure of loop we are trying to calculate backedge-count of:
13010-
left = left_start
13011-
right = right_start
13012-
while(left < right){
13013-
// ... do something here ...
13014-
left += s1; // stride of left is s1>0
13015-
right -= s2; // stride of right is -s2 (s2 > 0)
13016-
}
13017-
// left and right are converging at the middle
13018-
// (maybe not exactly at center)
13008+
// The structure of loop we are trying to calculate backedge count of:
13009+
//
13010+
// left = left_start
13011+
// right = right_start
13012+
//
13013+
// while(left < right){
13014+
// ... do something here ...
13015+
// left += s1; // stride of left is s1>0
13016+
// right -= s2; // stride of right is -s2 (s2 > 0)
13017+
// }
13018+
//
13019+
// Here, left and right are converging somewhere in the middle.
1301913020

13020-
*/
1302113021
const SCEV *RHSStart = RHSAddRec->getStart();
1302213022
const SCEV *RHSStride = RHSAddRec->getStepRecurrence(*this);
13023-
// if Stride-RHSStride>0 and does not overflow, we can write
13024-
// backedge count as:
13025-
// RHSStart >= Start ? (RHSStart - Start)/(Stride - RHSStride) ? 0
1302613023

13027-
// check if RHSStride<0 and Stride-RHSStride will not overflow
13024+
// If Stride - RHSStride is positive and does not overflow, we can write
13025+
// backedge count as ->
13026+
// ceil((End - Start) /u (Stride - RHSStride))
13027+
// Where, End = max(RHSStart, Start)
13028+
13029+
// Check if RHSStride < 0 and Stride - RHSStride will not overflow.
1302813030
// FIXME: Can RHSStride be positive?
1302913031
if (isKnownNegative(RHSStride) &&
1303013032
willNotOverflow(Instruction::Sub, /*Signed=*/true, Stride,
@@ -13033,9 +13035,10 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
1303313035
const SCEV *Denominator = getMinusSCEV(Stride, RHSStride);
1303413036
if (isKnownPositive(Denominator)) {
1303513037
End = IsSigned ? getSMaxExpr(RHSStart, Start)
13036-
: getUMaxExpr(RHSStart, Start); // max(RHSStart, Start)
13038+
: getUMaxExpr(RHSStart, Start);
1303713039

13038-
const SCEV *Delta = getMinusSCEV(End, Start); // End >= Start
13040+
// We can do this because End >= Start, as End = max(RHSStart, Start)
13041+
const SCEV *Delta = getMinusSCEV(End, Start);
1303913042

1304013043
BECount = getUDivCeilSCEV(Delta, Denominator);
1304113044
BECountIfBackedgeTaken =

0 commit comments

Comments
 (0)