[llvm] [DA] Add tests for nsw doesn't hold on entier iteration (PR #162281)
Ehsan Amiri via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 21 09:06:53 PST 2025
amehsan wrote:
> * I selected the term "monotonicity" instead of "no-wrap" because the former is easier to define. For a polynomial with its degree is less than 2, monotonicity would be equivalent no-wrap.
They are not equivalent and that is important for your example
```
; stride = INT64_MAX;
; for (i = 0; i < 10; i++)
; if (i % 2 == 0) {
; A[stride*i + 100] = 1; // A[100], A[98], A[96], ...
; A[stride*i + 102] = 2; // A[102], A[100], A[98], ...
; }
;
```
because here it doesn't matter whether you interpret numbers as signed or unsigned `stride*i + 102` cannot have no wrap flags on both operations when `i = 2`. So this addresses your concern about control flow in this loop. But currently this loop is being discussed because according to definition of monotonicity `stride*i + 102` is monotonic for values of `i = 0, i = 2, ....10`.
Do I misunderstand something here?
> * The example `A[i*i - 1]` doesn't make much sense to me since I believe that DA doesn't support quadratic or higher degree addrecs for the foreseeable future (or possibly ever). Also you may want to pay attention to how SCEV represents such higher degree expressions. It doesn't hold the multiplications explicitly (though I don't know what it implies for DA).
I agree that this is not a practically interesting example, but the point is this: we don't need monotonicity for proving correctness of a given test. We just need existance of nowrap flags.
> * As I mentioned in the previous comment, there exists dependence tests with different characteristics (Category 1 and 2). It seems to me that you only consider the tests in Category 2. I'm saying that entire domain monotonicity is necessary for Category 1 tests.
Yes, I had the same understanding for some time, but now I believe we don't need to distinguish between them. I will write down proofs soon. You can look into them and try to find a mistake in them.
https://github.com/llvm/llvm-project/pull/162281
More information about the llvm-commits
mailing list