/// Compute the maximum backedge count based on the range of values
/// permitted by Start, End, and Stride. This is for loops of the form
/// {Start, +, Stride} LT End.
+ ///
+ /// Precondition: the induction variable is known to be positive. We *don't*
+ /// assert these preconditions so please be careful.
const SCEV *computeMaxBECountForLT(const SCEV *Start, const SCEV *Stride,
- const SCEV *End, unsigned BitWidth,
- bool IsSigned);
+ const SCEV *End, unsigned BitWidth,
+ bool IsSigned);
/// Verify if an linear IV with positive stride can overflow when in a
/// less-than comparison, knowing the invariant term of the comparison,
StrideForMaxBECount =
IsSigned ? getSignedRangeMin(Stride) : getUnsignedRangeMin(Stride);
else
- // Using a stride of 1 is safe when computing max backedge taken count for
- // a loop with unknown stride.
+ // Using a stride of 1 is safe when computing max backedge taken count for a
+ // loop with unknown stride, since the precondition for this function is
+ // that it is positive.
StrideForMaxBECount = APInt(BitWidth, 1, IsSigned);
APInt MaxValue = IsSigned ? APInt::getSignedMaxValue(BitWidth)