[PATCH] D22377: [SCEV] trip count calculation for loops with unknown stride

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 11 19:06:10 PDT 2016


sanjoy requested changes to this revision.
This revision now requires changes to proceed.

================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:8781
@@ -8707,3 +8780,3 @@
   // behaviors like the case of C language.
   if (!Stride->isOne() && doesIVOverflowOnLT(RHS, Stride, IsSigned, NoWrap))
     return getCouldNotCompute();
----------------
I just noticed that `doesIVOverflowOnLT` only works for a positive stride, can you please take a look?  For a non-positive `Stride`, I think we can make `doesIVOverflowOnLT` just return `NoWrap`.

================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:8800
@@ +8799,3 @@
+  // for a loop with unknown stride.
+  APInt MinStride = !PositiveStride
+                        ? APInt(BitWidth, 1, IsSigned)
----------------
I'd feel safer if you short-circuited the entire max becount computation based on `PositiveStride`, since `MinStride` is no longer what it says on the tin ("the minimum value of `Stride`).  (To me) it basically looks like the expression below that computes the max be count implicitly assumes a positive stride, and forking the logic more explicitly will be more obvious.

If that's a problem, I'd suggest at least renaming `MinStride` to something more in tune with what it represents now (perhaps `StrideForMaxBECount`?).


https://reviews.llvm.org/D22377





More information about the llvm-commits mailing list