This patch teaches IndVars toWhen remove the following kind of range checks:
for (i = X; cond();ing exiting loop conditions, i--) {we only consider checks for
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,which we know the exact exit count. with block
of interest excluded.We could also eliminate checks for
which the condition is always true/false.