[llvm] [DA] Add tests where dependencies are missed due to overflow (NFC) (PR #164246)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 28 08:15:51 PDT 2025


================
@@ -0,0 +1,66 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 6
+; RUN: opt < %s -disable-output "-passes=print<da>" 2>&1 \
+; RUN:     | FileCheck %s --check-prefixes=CHECK,CHECK-ALL
+; RUN: opt < %s -disable-output "-passes=print<da>" -da-enable-dependence-test=gcd-miv 2>&1 \
+; RUN:     | FileCheck %s --check-prefixes=CHECK,CHECK-GCD-MIV
+
+; offset0 = 4;
+; offset1 = 0;
+; for (i = 0; i < 100; i++) {
+;   A[offset0] = 1;
+;   A[offset1] = 2;
+;   offset0 += 3*m;
+;   offset1 += 3;
+; }
+;
+; FIXME: DependenceAnalysis currently detects no dependency between the two
+; stores, but it does exist. E.g., consider `m` is 12297829382473034411, which
+; is a modular multiplicative inverse of 3 under modulo 2^64. Then `offset0` is
+; effectively `i + 4`, so accesses will be as follows:
+;
+;   - A[offset0] : A[4], A[5], A[6], ...
+;   - A[offset1] : A[0], A[3], A[6], ...
+;
+; The root cause is that DA assumes `3*m` begin a multiple of 3 in mathematical
+; sense, which isn't necessarily true due to overflow.
----------------
Meinersbur wrote:

```suggestion
; The root cause is that DA interprets `3*m` in non-modular arithmetic, 
; which isn't necessarily true due to overflow.
```
[modular arithmetic](https://en.wikipedia.org/wiki/Modular_arithmetic) is also mathematical

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


More information about the llvm-commits mailing list