[PATCH] D87832: [IndVars] Remove monotonic checks with unknown exit count

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 29 09:45:31 PDT 2020


reames added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:2375
+
+  // The predicate must be monotonic.
+  switch (Pred) {
----------------
mkazantsev wrote:
> mkazantsev wrote:
> > reames wrote:
> > > lebedev.ri wrote:
> > > > It might be good to hoist that into some ICmp method,
> > > > this is at least the second such code block.
> > > It really looks like at least part of this logic can be replaced with SE->isMonotonicPredicate(LHSS, Pred, IncreasingOut).  In particular, I think that covers all your tricky overflow logic and does so more generally.
> > > 
> > > If I'm right about that, you can also generalize this.  Consider:
> > > - If is monotonic, and proven start == proven end (without caring which direction proved), the condition is invariant for the iterations executed.  
> > > 
> > > This is starting to look a lot like it might belong in isLoopInvariantPredicate.  It seems to be a generalization of the logic there.
> > It does not. It requires proved nsw/nuw flags. We are OK if the last iteration actually does overflow, but in this case we exit the loop before our check.
> `isRelational` seems to be what we need.
Is it fair to say that what you're implementing is isMonotonicPredicate(Pred, RHS, MaxIteration)?  And that you're specifically focused on exploiting the overflow outside of MaxIteration?

If so, this seems like it might come down to a missing overflow flag on the SCEV.  SCEVs overflow flags hold for all current uses, so as long as the overflow value isn't used on the last iteration (or outside the loop), SCEV should be able to infer the lack of overflow.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87832/new/

https://reviews.llvm.org/D87832



More information about the llvm-commits mailing list