This patch introduces guard based loop predication optimization. The new LoopPredication pass tries to convert loop variant range checks to loop invariant by widening checks across loop iterations. For example, it will convert
for (i = 0; i < n; i++) { guard(i < len); ... }
to
for (i = 0; i < n; i++) { guard(n - 1 < len); ... }
After this transformation the condition of the guard is loop invariant, so loop-unswitch can later unswitch the loop by this condition which basically predicates the loop by the widened condition:
if (n - 1 < len) for (i = 0; i < n; i++) { ... } else deoptimize
This patch relies on an NFC change to make ScalarEvolution::isMonotonicPredicate public which is not included in the review.
Please edit the header to include a description like in other .cpp files.