[llvm] [DA] Add tests for dependencies are missed due to addrecs wrap (NFC) (PR #179683)

via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 4 07:53:43 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Ryotaro Kasuga (kasuga-fj)

<details>
<summary>Changes</summary>

Add test cases where dependencies are missed since nowrap properties of addrecs are not checked properly. This patch doesn't contain test cases for the MIV tests.

---
Full diff: https://github.com/llvm/llvm-project/pull/179683.diff


5 Files Affected:

- (added) llvm/test/Analysis/DependenceAnalysis/exact-rdiv-addrec-wrap.ll (+79) 
- (added) llvm/test/Analysis/DependenceAnalysis/exact-siv-addrec-wrap.ll (+71) 
- (added) llvm/test/Analysis/DependenceAnalysis/strong-siv-addrec-wrap.ll (+71) 
- (added) llvm/test/Analysis/DependenceAnalysis/symbolic-rdiv-addrec-wrap.ll (+69) 
- (added) llvm/test/Analysis/DependenceAnalysis/weak-crossing-siv-addrec-wrap.ll (+78) 


``````````diff
diff --git a/llvm/test/Analysis/DependenceAnalysis/exact-rdiv-addrec-wrap.ll b/llvm/test/Analysis/DependenceAnalysis/exact-rdiv-addrec-wrap.ll
new file mode 100644
index 0000000000000..ec974e0f070fb
--- /dev/null
+++ b/llvm/test/Analysis/DependenceAnalysis/exact-rdiv-addrec-wrap.ll
@@ -0,0 +1,79 @@
+; 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=exact-rdiv 2>&1 \
+; RUN:     | FileCheck %s --check-prefixes=CHECK,CHECK-EXACT-RDIV
+
+
+; a = 6148914691236517210; // 6148914691236517210 = ((2^64) - 1) / 3 + 5
+; for (i = 0; i < 10; i++) {
+;   if (0 <=s a*i)
+;     A[a*i] = 0;
+; }
+;
+; for (i = 0; i < 9; i++) {
+;   A[5*i + 14] = 1;
+; }
+;
+; The dependency exists between the two stores, for example,
+;
+;  memory access | i == 0 | i == 3
+; ---------------|--------|--------
+;  A[a*i]        |        | A[14]
+;  A[5*i + 14]   | A[14]  |
+;
+; FIXME: DependenceAnalysis fails to detect the dependency between the two
+; stores.
+;
+define void @exact_rdiv_no_nsw(ptr %A) {
+; CHECK-ALL-LABEL: 'exact_rdiv_no_nsw'
+; CHECK-ALL-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1
+; CHECK-ALL-NEXT:    da analyze - none!
+; CHECK-ALL-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-ALL-NEXT:    da analyze - none!
+; CHECK-ALL-NEXT:  Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-ALL-NEXT:    da analyze - none!
+;
+; CHECK-EXACT-RDIV-LABEL: 'exact_rdiv_no_nsw'
+; CHECK-EXACT-RDIV-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1
+; CHECK-EXACT-RDIV-NEXT:    da analyze - consistent output [*]!
+; CHECK-EXACT-RDIV-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-EXACT-RDIV-NEXT:    da analyze - none!
+; CHECK-EXACT-RDIV-NEXT:  Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-EXACT-RDIV-NEXT:    da analyze - consistent output [*]!
+;
+entry:
+  br label %loop.0.header
+
+loop.0.header:
+  %i.0 = phi i64 [ 0, %entry ], [ %i.0.inc, %loop.0.latch ]
+  %offset.0 = phi i64 [ 0, %entry ], [ %offset.0.next, %loop.0.latch ]
+  %cond.0 = icmp sge i64 %i.0, 0
+  br i1 %cond.0, label %if.then.0, label %loop.0.latch
+
+if.then.0:
+  %gep.0 = getelementptr i8, ptr %A, i64 %offset.0
+  store i8 0, ptr %gep.0
+  br label %loop.0.latch
+
+loop.0.latch:
+  %i.0.inc = add i64 %i.0, 1
+  %offset.0.next = add i64 %offset.0, 6148914691236517210
+  %ec.0 = icmp eq i64 %i.0.inc, 10
+  br i1 %ec.0, label %loop.1, label %loop.0.header
+
+loop.1:
+  %i.1 = phi i64 [ 0, %loop.0.latch ], [ %i.1.inc, %loop.1 ]
+  %offset.1 = phi i64 [ 14, %loop.0.latch ], [ %offset.1.next, %loop.1 ]
+  %gep.1 = getelementptr i8, ptr %A, i64 %offset.1
+  store i8 1, ptr %gep.1
+  %i.1.inc = add i64 %i.1, 1
+  %offset.1.next = add i64 %offset.1, 5
+  %ec.1 = icmp eq i64 %i.1.inc, 9
+  br i1 %ec.1, label %exit, label %loop.1
+
+exit:
+  ret void
+}
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; CHECK: {{.*}}
diff --git a/llvm/test/Analysis/DependenceAnalysis/exact-siv-addrec-wrap.ll b/llvm/test/Analysis/DependenceAnalysis/exact-siv-addrec-wrap.ll
new file mode 100644
index 0000000000000..f8a63333183a4
--- /dev/null
+++ b/llvm/test/Analysis/DependenceAnalysis/exact-siv-addrec-wrap.ll
@@ -0,0 +1,71 @@
+; 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=exact-siv 2>&1 \
+; RUN:     | FileCheck %s --check-prefixes=CHECK,CHECK-EXACT-SIV
+
+
+; a = 6148914691236517210; // 6148914691236517210 = ((2^64) - 1) / 3 + 5
+; for (i = 0; i < 10; i++) {
+;   if (0 <=s a*i)
+;     A[a*i] = 0;
+;
+;   A[5*i + 14] = 1;
+; }
+;
+; The dependency exists between the two stores, for example,
+;
+;  memory access | i == 0 | i == 3
+; ---------------|--------|--------
+;  A[a*i]        |        | A[14]
+;  A[5*i + 14]   | A[14]  |
+;
+; FIXME: DependenceAnalysis fails to detect the dependency between the two
+; stores.
+;
+define void @exact_siv_no_nsw(ptr %A) {
+; CHECK-ALL-LABEL: 'exact_siv_no_nsw'
+; CHECK-ALL-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1
+; CHECK-ALL-NEXT:    da analyze - none!
+; CHECK-ALL-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-ALL-NEXT:    da analyze - none!
+; CHECK-ALL-NEXT:  Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-ALL-NEXT:    da analyze - none!
+;
+; CHECK-EXACT-SIV-LABEL: 'exact_siv_no_nsw'
+; CHECK-EXACT-SIV-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1
+; CHECK-EXACT-SIV-NEXT:    da analyze - consistent output [*]!
+; CHECK-EXACT-SIV-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-EXACT-SIV-NEXT:    da analyze - none!
+; CHECK-EXACT-SIV-NEXT:  Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-EXACT-SIV-NEXT:    da analyze - consistent output [*]!
+;
+entry:
+  br label %loop.header
+
+loop.header:
+  %i = phi i64 [ 0, %entry ], [ %i.inc, %loop.latch ]
+  %offset.0 = phi i64 [ 0, %entry ], [ %offset.0.next, %loop.latch ]
+  %offset.1 = phi i64 [ 14, %entry ], [ %offset.1.next, %loop.latch ]
+  %cond = icmp sge i64 %offset.0, 0
+  br i1 %cond, label %if.then, label %loop.latch
+
+if.then:
+  %gep.0 = getelementptr i8, ptr %A, i64 %offset.0
+  store i8 0, ptr %gep.0
+  br label %loop.latch
+
+loop.latch:
+  %gep.1 = getelementptr i8, ptr %A, i64 %offset.1
+  store i8 1, ptr %gep.1
+  %i.inc = add i64 %i, 1
+  %offset.0.next = add i64 %offset.0, 6148914691236517210
+  %offset.1.next = add i64 %offset.1, 5
+  %ec = icmp eq i64 %i.inc, 10
+  br i1 %ec, label %exit, label %loop.header
+
+exit:
+  ret void
+}
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; CHECK: {{.*}}
diff --git a/llvm/test/Analysis/DependenceAnalysis/strong-siv-addrec-wrap.ll b/llvm/test/Analysis/DependenceAnalysis/strong-siv-addrec-wrap.ll
new file mode 100644
index 0000000000000..05807458d4de5
--- /dev/null
+++ b/llvm/test/Analysis/DependenceAnalysis/strong-siv-addrec-wrap.ll
@@ -0,0 +1,71 @@
+; 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=strong-siv 2>&1 \
+; RUN:     | FileCheck %s --check-prefixes=CHECK,CHECK-STRONG-SIV
+
+; a = (1 << 62) + 1;
+; for (i = 0; i < 10; i++) {
+;   if (0 <=s a*i)
+;     A[a*i] = 0;
+;
+;   if (0 <=s a*i + 4)
+;     A[a*i + 4] = 1;
+; }
+;
+; The dependency exists between the two stores, for example,
+;
+;  memory access     | i == 0 | i == 4
+; -------------------|--------|--------
+;  A[(2^62+1)*i]     |        | A[4]
+;  A[(2^62+1)*i + 4] | A[4]   |
+;
+; FIXME: DependenceAnalysis fails to detect the dependency between the two
+; stores.
+;
+define void @strong_siv_no_nsw(ptr %A) {
+; CHECK-LABEL: 'strong_siv_no_nsw'
+; CHECK-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1
+; CHECK-NEXT:    da analyze - none!
+; CHECK-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-NEXT:    da analyze - none!
+; CHECK-NEXT:  Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-NEXT:    da analyze - none!
+;
+entry:
+  br label %loop.header
+
+loop.header:
+  %i = phi i64 [ 0, %entry ], [ %i.inc, %loop.latch ]
+  %offset.0 = phi i64 [ 0, %entry ], [ %offset.0.next, %loop.latch ]
+  %offset.1 = phi i64 [ 4, %entry ], [ %offset.1.next, %loop.latch ]
+  %cond.0 = icmp sge i64 %offset.0, 0
+  br i1 %cond.0, label %if.then.0, label %loop.middle
+
+if.then.0:
+  %gep.0 = getelementptr i8, ptr %A, i64 %offset.0
+  store i8 0, ptr %gep.0
+  br label %loop.middle
+
+loop.middle:
+  %cond.1 = icmp sge i64 %offset.1, 0
+  br i1 %cond.1, label %if.then.1, label %loop.latch
+
+if.then.1:
+  %gep.1 = getelementptr i8, ptr %A, i64 %offset.1
+  store i8 1, ptr %gep.1
+  br label %loop.latch
+
+loop.latch:
+  %i.inc = add i64 %i, 1
+  %offset.0.next = add i64 %offset.0, 4611686018427387905 ; (1LL << 62) + 1
+  %offset.1.next = add i64 %offset.1, 4611686018427387905
+  %ec = icmp eq i64 %i.inc, 10
+  br i1 %ec, label %exit, label %loop.header
+
+exit:
+  ret void
+}
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; CHECK-ALL: {{.*}}
+; CHECK-STRONG-SIV: {{.*}}
diff --git a/llvm/test/Analysis/DependenceAnalysis/symbolic-rdiv-addrec-wrap.ll b/llvm/test/Analysis/DependenceAnalysis/symbolic-rdiv-addrec-wrap.ll
new file mode 100644
index 0000000000000..77663431abc7f
--- /dev/null
+++ b/llvm/test/Analysis/DependenceAnalysis/symbolic-rdiv-addrec-wrap.ll
@@ -0,0 +1,69 @@
+; 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=symbolic-rdiv 2>&1 \
+; RUN:     | FileCheck %s --check-prefixes=CHECK,CHECK-SYMBOLIC-RDIV
+
+; for (i = 0; i < (1 << 60); i++) {
+;   A[i] = 0;
+;
+;   if (0 <=s 32*i + (1 << 62))
+;     A[32*i + (1 << 62)] = 1;
+; }
+;
+; The dependency exists between the two stores, for exmaple,
+;
+;  memory access  | i == 0 | i == 2^59 - 2^57 | i == 2^59 - 2^57 + 2^55 - 1 | i == 2^60 - 32
+; ----------------|--------|------------------|-----------------------------|----------------
+;  A[i]           | A[0]   |                  |                             | A[2^60 - 32]
+;  A[32*i + 2^62] |        | A[0]             | A[2^60 - 32]                |
+;
+; FIXME: DependenceAnalysis fails to detect the dependency between the two
+; stores.
+;
+define void @symbolic_rdiv_addrec_wrap(ptr %A) {
+; CHECK-ALL-LABEL: 'symbolic_rdiv_addrec_wrap'
+; CHECK-ALL-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1
+; CHECK-ALL-NEXT:    da analyze - none!
+; CHECK-ALL-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-ALL-NEXT:    da analyze - none!
+; CHECK-ALL-NEXT:  Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-ALL-NEXT:    da analyze - none!
+;
+; CHECK-SYMBOLIC-RDIV-LABEL: 'symbolic_rdiv_addrec_wrap'
+; CHECK-SYMBOLIC-RDIV-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1
+; CHECK-SYMBOLIC-RDIV-NEXT:    da analyze - consistent output [*]!
+; CHECK-SYMBOLIC-RDIV-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-SYMBOLIC-RDIV-NEXT:    da analyze - none!
+; CHECK-SYMBOLIC-RDIV-NEXT:  Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-SYMBOLIC-RDIV-NEXT:    da analyze - none!
+;
+entry:
+  %tc = shl i64 1, 60
+  %const.1 = shl i64 1, 62
+  br label %loop.header
+
+loop.header:
+  %i = phi i64 [ 0, %entry ], [ %i.inc, %loop.latch ]
+  %offset = phi i64 [ 4611686018427387904, %entry ], [ %offset.next, %loop.latch ]
+  %gep.0 = getelementptr i8, ptr %A, i64 %i
+  store i8 0, ptr %gep.0
+  %cond = icmp sge i64 %offset, 0
+  br i1 %cond, label %if.then, label %loop.latch
+
+if.then:
+  %gep.1 = getelementptr i8, ptr %A, i64 %offset
+  store i8 1, ptr %gep.1
+  br label %loop.latch
+
+loop.latch:
+  %i.inc = add i64 %i, 1
+  %offset.next = add i64 %offset, 32
+  %ec = icmp eq i64 %i.inc, 1152921504606846976 ; 2^60
+  br i1 %ec, label %exit, label %loop.header
+
+exit:
+  ret void
+}
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; CHECK: {{.*}}
diff --git a/llvm/test/Analysis/DependenceAnalysis/weak-crossing-siv-addrec-wrap.ll b/llvm/test/Analysis/DependenceAnalysis/weak-crossing-siv-addrec-wrap.ll
new file mode 100644
index 0000000000000..e0f3eda30e63d
--- /dev/null
+++ b/llvm/test/Analysis/DependenceAnalysis/weak-crossing-siv-addrec-wrap.ll
@@ -0,0 +1,78 @@
+; 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=weak-crossing-siv 2>&1 \
+; RUN:     | FileCheck %s --check-prefixes=CHECK,CHECK-WEAK-CROSSING-SIV
+
+; a = (1 << 62) + 1;
+; for (i = 0; i < 10; i++) {
+;   if (0 <=s a*i)
+;     A[a*i] = 0;
+;
+;   if (0 <=s -a*i + 4)
+;     A[-a*i + 4] = 1;
+; }
+;
+; The dependency exists between the two stores, for example,
+;
+;  memory access      | i == 0 | i == 4
+; --------------------|--------|--------
+;  A[(2^62+1)*i]      | A[0]   | A[4]
+;  A[-(2^62+1)*i + 4] | A[4]   | A[0]
+;
+; FIXME: DependenceAnalysis fails to detect the dependency between the two
+; stores.
+;
+define void @weak_crossing_siv_no_nsw(ptr %A) {
+; CHECK-ALL-LABEL: 'weak_crossing_siv_no_nsw'
+; CHECK-ALL-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1
+; CHECK-ALL-NEXT:    da analyze - none!
+; CHECK-ALL-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-ALL-NEXT:    da analyze - none!
+; CHECK-ALL-NEXT:  Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-ALL-NEXT:    da analyze - none!
+;
+; CHECK-WEAK-CROSSING-SIV-LABEL: 'weak_crossing_siv_no_nsw'
+; CHECK-WEAK-CROSSING-SIV-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1
+; CHECK-WEAK-CROSSING-SIV-NEXT:    da analyze - consistent output [*]!
+; CHECK-WEAK-CROSSING-SIV-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-WEAK-CROSSING-SIV-NEXT:    da analyze - none!
+; CHECK-WEAK-CROSSING-SIV-NEXT:  Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-WEAK-CROSSING-SIV-NEXT:    da analyze - consistent output [*]!
+;
+entry:
+  br label %loop.header
+
+loop.header:
+  %i = phi i64 [ 0, %entry ], [ %i.inc, %loop.latch ]
+  %offset.0 = phi i64 [ 0, %entry ], [ %offset.0.next, %loop.latch ]
+  %offset.1 = phi i64 [ 4, %entry ], [ %offset.1.next, %loop.latch ]
+  %cond.0 = icmp sge i64 %offset.0, 0
+  br i1 %cond.0, label %if.then.0, label %loop.middle
+
+if.then.0:
+  %gep.0 = getelementptr i8, ptr %A, i64 %offset.0
+  store i8 0, ptr %gep.0
+  br label %loop.middle
+
+loop.middle:
+  %cond.1 = icmp sge i64 %offset.1, 0
+  br i1 %cond.1, label %if.then.1, label %loop.latch
+
+if.then.1:
+  %gep.1 = getelementptr i8, ptr %A, i64 %offset.1
+  store i8 1, ptr %gep.1
+  br label %loop.latch
+
+loop.latch:
+  %i.inc = add i64 %i, 1
+  %offset.0.next = add i64 %offset.0, 4611686018427387905 ; (1LL << 62) + 1
+  %offset.1.next = sub i64 %offset.1, 4611686018427387905
+  %ec = icmp eq i64 %i.inc, 10
+  br i1 %ec, label %exit, label %loop.header
+
+exit:
+  ret void
+}
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; CHECK: {{.*}}

``````````

</details>


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


More information about the llvm-commits mailing list