[PATCH] D109457: [SCEV] Use constant range of RHS to prove NUW on narrow IV in trip count logic
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 13 15:45:53 PDT 2021
efriedma added inline comments.
================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:11636
+ if (StrideMax == 0)
+ return false;
+
----------------
Why is the `StrideMax == 0` special case necessary?
================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:11640
+ const unsigned OuterBitWidth = getTypeSizeInBits(RHS->getType());
+ APInt Limit = APInt::getMaxValue(InnerBitWidth) - StrideMax;
+ Limit = Limit.zext(OuterBitWidth);
----------------
What is `APInt::getMaxValue(InnerBitWidth) - StrideMax` the limit of?
I guess you're looking for the smallest possible value of `AR` at the step before it overflows. If that value forces the loop to exit, then the loop must exit before the overflow. A conservative way to figure that is based on the stride itself: just use the smallest value X such that X+Stride might overflow.
A comment would be helpful.
Also, I think you might be off by one here? `Limit` is one less than the value X I described. But maybe that cancels out somehow...
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D109457/new/
https://reviews.llvm.org/D109457
More information about the llvm-commits
mailing list