First, the motivation for this patch is to allow LLVM to optimize this code as one might hope:
void foo (int *a, int *b, int n) { for (int i = 0; i < n; ++i) { if (i > n) a[i] = b[i] + 1; } }
As i is less than n in the loop, the conditional (i > n) can be folded to false.
With this relatively-simple change, we can perform the simplification in the default pipeline: indvars can perform the folding using SCEV.
Now the obvious question is: is it correct? For now, I've XFAIL'ed two tests:
I believe that the test/Transforms/IndVarSimplify/backedge-on-min-max.ll changes are legitimate (some of the loops in those tests are actually infinite loops, this change causes indvars to make that explicit instead of making other changes - unfortunately, I've been unable to fix the tests to serve their original purpose).
The test/Transforms/LoopStrengthReduce/X86/pr17473.ll changes look more dubious, and I'd certainly appreciate a second opinion. I'll attach some screen shots with the diffs.
I think this change would be cleaner if SignedDiff took explicit LHS and RHS arguments.