[llvm] [DA] Add tests for nsw doesn't hold on entier iteration (PR #162281)

Ryotaro Kasuga via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 21 09:49:31 PST 2025


kasuga-fj wrote:

> 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`.

I forgot to mention a very important precondition: they would be equivalent if the domain is consective. I wasn’t really intending to discuss that extreme example.

For the remaining parts, I'd strongly recommend you to read the code. I think Symbolic RDIV is a good one. It assumes that an addrec takes its minimum value at the first iteration and maximum value at the last iteration if the coefficient is non-negative. I think it's clear that "an addrec doesn't wrap when it's executed" is insufficient

https://github.com/llvm/llvm-project/pull/162281


More information about the llvm-commits mailing list