[PATCH] D89381: [SCEV] Use nw flag and symbolic iteration count to sharpen ranges of AddRecs
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 14 10:30:34 PDT 2020
efriedma added inline comments.
================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:5705
+ const SCEV *Start = AddRec->getStart();
+ const SCEV *End = AddRec->evaluateAtIteration(MaxBECount, *this);
+
----------------
I'm concerned that evaluating at iteration MaxBECount won't do what you want. In particular, if MaxBECount is larger than the number of steps required to violate nw, then the way you're comparing Start and End doesn't work.
The actual backedge-taken count at runtime can't be that large, of course, but MaxBECount is an approximation in general; I don't think we make any relevant guarantees. In particular, if the step isn't constant, we can't get this right.
I think you could explicitly compute the largest number of non-wrapping iterations, and then take the minimum of that and MaxBECount to compute the "real" maximum count.
================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:5744
+ };
+ if (isKnownPositive(Step) && isKnownPredicate(LEPred, Start, End)) {
+ if (!ProveBetween(LEPred))
----------------
At first I wasn't sure what `isKnownPredicate(LEPred, Start, End))` was checking, but then I figured out it's accounting for the possibility of crossing INT_MAX/UINT_MAX, since nw doesn't exclude that. I think an alternate way of satisfying this condition would be to check for nsw/nuw.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D89381/new/
https://reviews.llvm.org/D89381
More information about the llvm-commits
mailing list