[llvm] [DA] Add initial support for monotonicity check (PR #162280)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 17 06:54:04 PDT 2025
amehsan wrote:
> However, it's incorrect to assume that the subscript `2 * i` never overflows across the entire iteration space.
My mistake. I think this makes the situation worse, not better. For a platform that ignores upper 8 bits of a 64-bit pointer, even in a simple loop like this
```
for (long long i = 0 ; i < n; i++)
A[i] = 0;
```
Every time the lower 56 bits of `i` wrap (and for a 64 bit value a 56 bit signed wrap happens 2^9 times), the subscripts wraps. This patch can detect 64 bit wraps, but that is a small fraction of all possible 56-bit wraps. for example see the following code:
```
size_t size =2000;
unsigned long long T = (1ULL << 58) - 1ULL ;
char *p = malloc(size);
if (p) {
p[1] = 98;
printf("ptr: T = %llx\n", T);
printf("ptr: %p\n", &p[1]);
printf("ptr: %p\n", &p[T+2]);
printf("val: %d\n", p[1]);
printf("val: %d\n", p[T+2]);
free(p);
}
output:
T = 3ffffffffffffff
ptr: 0xd1892a1
ptr: 0x40000000d1892a1
val: 98
val: 98
```
I don't have objections to merging this patch. This works well if effective pointer size is 32 or 64. But I think this issue needs to be discussed further, independent of this patch (for example, I suspect we can write test cases that are vectorized but they are not legal, and it is question for me how important is to fix all these unlikely corner cases).
https://github.com/llvm/llvm-project/pull/162280
More information about the llvm-commits
mailing list