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

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 28 10:11:18 PDT 2020


reames requested changes to this revision.
reames added inline comments.
This revision now requires changes to proceed.


================
Comment at: llvm/include/llvm/Analysis/ScalarEvolution.h:923
+  bool isKnownPredicateAt(ICmpInst::Predicate Pred, const SCEV *LHS,
+                        const SCEV *RHS, const BasicBlock *BB);
+
----------------
For the context, use an instruction even if you don't actually need it yet.  We made this mistake in LVI and spent years digging out.  The problem with using the BB is you have to be very careful in documenting where in said block the fact holds.  


================
Comment at: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:2375
+
+  // The predicate must be monotonic.
+  switch (Pred) {
----------------
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.


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

https://reviews.llvm.org/D87832



More information about the llvm-commits mailing list