This change moves logic which we'd added specifically for less than tests so that it applies to equalities and greater than tests as well. The basic idea is that if we can show an IV cycles infinitely through the same series on self-wrap, and that the exit condition must be taken to prevent UB, we can conclude that it must be taken before self-wrap and thus infer said flag.
The motivation here is simple loops with unsigned induction variables w/non-one steps and inequality tests. A toy example would be:
for (unsigned i = 0; i != N; i += 2) { body; }
If body contains no side effects, and this is a mustprogress function, we can assume that this must be a finite loop and thus that the exit count is N/2.
Note that we canonicalize to NE tests in LFTR, so after the previous change we'd compute an exit count, perform LFTR, and then "forget" what the exit count was again.
A couple notes on things left out of this patch:
- Looking back through multiple invertible functions, and anything other than ZExt. This is easy to add, but deserves it's own test coverage and review. I add Zext only so that I could delete the less than version of the same code.
- Forming the IV as an addrec where possible. Doing this will (further) help our ability to handle extended ne tests, but will be done separately. (See the existing less than code for what I mean here - note that code will still be triggered if we prove no-self-wrap in this patch.)
It is only true if this condition dominates the latch. If not, it might exit at some point during the iteration space, but it was guarded by a volatile condition that prevented it. If my understanding is correct, please specify this requirement explicitly in function's comment.
Maybe (I'm not sure) this still holds for non-dominating exits if it is the only exit from the loop.