[PATCH] D87344: [IndVars] Remove range checks for which we can predicate ends of the range

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 8 21:19:50 PDT 2020


mkazantsev created this revision.
mkazantsev added reviewers: fhahn, lebedev.ri, sanjoy.google, reames, skatkov.
Herald added subscribers: llvm-commits, javed.absar, hiraditya.
Herald added a project: LLVM.
mkazantsev requested review of this revision.

This patch teaches IndVars to remove the following kind of range checks:

  for (i = X; cond(); i--) {
    if (i predicate Y) deopt();
    ...
  }

basing on the following set of facts:

- Predicate is monotonic;
- Condition is met on the 1st iteration;
- Max possible number of iterations (given that we do not exit by the check being deleted) is limited and does not exceed max unsigned value of `Type(i)`;
- Condition is met on the max possible iteration;
- `X - max possible itereration` does not overflow.

If all conditions above are true, then the range check can be trivially eliminated on every iteration.

The max number of iterations is computed by SCEV basing on all loop exit blocks, with block
of interest excluded.


https://reviews.llvm.org/D87344

Files:
  llvm/include/llvm/Analysis/ScalarEvolution.h
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
  llvm/test/Transforms/IndVarSimplify/monotonic_checks.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87344.290635.patch
Type: text/x-patch
Size: 8060 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200909/3b2da6cc/attachment.bin>


More information about the llvm-commits mailing list