[PATCH] D28393: [SCEV] Make howFarToZero produce a smaller max backedge-taken count
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 10 10:26:35 PST 2017
efriedma added inline comments.
================
Comment at: lib/Analysis/ScalarEvolution.cpp:7217
+ const SCEV *DistancePlusOne = getAddExpr(Distance, getOne(Distance->getType()));
+ if (isLoopEntryGuardedByCond(L, ICmpInst::ICMP_NE, DistancePlusOne, Zero)) {
+ ConstantRange CR = getUnsignedRange(DistancePlusOne);
----------------
sbaranga wrote:
> This looks correct to me, but I think it could use a comment.
>
> Do we only need to match against Distance + 1 because this is what we typically get from rotating the loop? Otherwise I think this could be generalized to Distance + constant, but we would need to do some work to find the value of the constant.
The transform is correct because we prove "Distance + 1" doesn't overflow. I'll add a comment explaining that.
You could generalize this to "Distance + Constant", but it's not clear what sort of pattern we would be looking for. (Also, at that point, it would probably be better to just write a context-sensitive version of getUnsignedRange().)
Repository:
rL LLVM
https://reviews.llvm.org/D28393
More information about the llvm-commits
mailing list