[llvm] [DA] Add tests that represent edge cases for the Weak Zero SIV tests (NFC) (PR #183735)
Ryotaro Kasuga via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 3 21:06:26 PST 2026
https://github.com/kasuga-fj updated https://github.com/llvm/llvm-project/pull/183735
>From 15f7bdf4b1f468ca34760c94b402e2b2175ad8eb Mon Sep 17 00:00:00 2001
From: Ryotaro Kasuga <kasuga.ryotaro at fujitsu.com>
Date: Fri, 27 Feb 2026 11:22:45 +0000
Subject: [PATCH] [DA] Add tests for the WeakZeroSIV tests return incorrect
result (NFC)
---
.../weak_zero_siv_parametric_coeff.ll | 106 ++++++++++++++++++
.../weak_zero_siv_parametric_const.ll | 101 +++++++++++++++++
2 files changed, 207 insertions(+)
create mode 100644 llvm/test/Analysis/DependenceAnalysis/weak_zero_siv_parametric_coeff.ll
create mode 100644 llvm/test/Analysis/DependenceAnalysis/weak_zero_siv_parametric_const.ll
diff --git a/llvm/test/Analysis/DependenceAnalysis/weak_zero_siv_parametric_coeff.ll b/llvm/test/Analysis/DependenceAnalysis/weak_zero_siv_parametric_coeff.ll
new file mode 100644
index 0000000000000..7468d019e3ee5
--- /dev/null
+++ b/llvm/test/Analysis/DependenceAnalysis/weak_zero_siv_parametric_coeff.ll
@@ -0,0 +1,106 @@
+; 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-zero-siv 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-WEAK-ZERO-SIV
+
+; for (i = 0; i < 100; i++) {
+; A[42] = 0;
+; A[a*i + 42] = 1;
+; }
+;
+; When `a` is zero, the two stores access the same memory location in every
+; iteration.
+;
+; FIXME: DependenceAnalysis should yield `*` for the dependency between the two
+; stores.
+;
+define void @weak_zero_src_siv_parametric_coeff(ptr %A, i64 %a) {
+; CHECK-ALL-LABEL: 'weak_zero_src_siv_parametric_coeff'
+; 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 - consistent output [S]!
+; 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 - output [p=>|<]!
+; 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 - consistent output [0]!
+; CHECK-ALL-NEXT: Runtime Assumptions:
+; CHECK-ALL-NEXT: Compare predicate: %a ne) 0
+;
+; CHECK-WEAK-ZERO-SIV-LABEL: 'weak_zero_src_siv_parametric_coeff'
+; CHECK-WEAK-ZERO-SIV-NEXT: Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1
+; CHECK-WEAK-ZERO-SIV-NEXT: da analyze - consistent output [S]!
+; CHECK-WEAK-ZERO-SIV-NEXT: Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-WEAK-ZERO-SIV-NEXT: da analyze - output [p=>|<]!
+; CHECK-WEAK-ZERO-SIV-NEXT: Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-WEAK-ZERO-SIV-NEXT: da analyze - consistent output [*]!
+;
+entry:
+ br label %loop
+
+loop:
+ %i = phi i64 [ 0, %entry ], [ %i.inc, %loop ]
+ %offset = phi i64 [ 42, %entry ], [ %offset.next, %loop ]
+ %gep.0 = getelementptr inbounds i8, ptr %A, i64 42
+ store i8 0, ptr %gep.0
+ %gep.1 = getelementptr inbounds i8, ptr %A, i64 %offset
+ store i8 1, ptr %gep.1
+ %i.inc = add i64 %i, 1
+ %offset.next = add nuw nsw i64 %offset, %a
+ %ec = icmp eq i64 %i.inc, 100
+ br i1 %ec, label %exit, label %loop
+
+exit:
+ ret void
+}
+
+; for (i = 0; i < 100; i++) {
+; A[a*i + 42] = 0;
+; A[42] = 1;
+; }
+;
+; When `a` is zero, the two stores access the same memory location in every
+; iteration.
+;
+; FIXME: DependenceAnalysis should yield `*` for the dependency between the two
+; stores.
+;
+define void @weak_zero_dst_siv_parametric_coeff(ptr %A, i64 %a) {
+; CHECK-ALL-LABEL: 'weak_zero_dst_siv_parametric_coeff'
+; 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 - consistent output [0]!
+; CHECK-ALL-NEXT: Runtime Assumptions:
+; CHECK-ALL-NEXT: Compare predicate: %a ne) 0
+; 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 - output [p<=|<]!
+; 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 - consistent output [S]!
+;
+; CHECK-WEAK-ZERO-SIV-LABEL: 'weak_zero_dst_siv_parametric_coeff'
+; CHECK-WEAK-ZERO-SIV-NEXT: Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1
+; CHECK-WEAK-ZERO-SIV-NEXT: da analyze - consistent output [*]!
+; CHECK-WEAK-ZERO-SIV-NEXT: Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-WEAK-ZERO-SIV-NEXT: da analyze - output [p<=|<]!
+; CHECK-WEAK-ZERO-SIV-NEXT: Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-WEAK-ZERO-SIV-NEXT: da analyze - consistent output [S]!
+;
+entry:
+ br label %loop
+
+loop:
+ %i = phi i64 [ 0, %entry ], [ %i.inc, %loop ]
+ %offset = phi i64 [ 42, %entry ], [ %offset.next, %loop ]
+ %gep.0 = getelementptr inbounds i8, ptr %A, i64 %offset
+ store i8 0, ptr %gep.0
+ %gep.1 = getelementptr inbounds i8, ptr %A, i64 42
+ store i8 1, ptr %gep.1
+ %i.inc = add i64 %i, 1
+ %offset.next = add nuw nsw i64 %offset, %a
+ %ec = icmp eq i64 %i.inc, 100
+ br i1 %ec, label %exit, label %loop
+
+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_zero_siv_parametric_const.ll b/llvm/test/Analysis/DependenceAnalysis/weak_zero_siv_parametric_const.ll
new file mode 100644
index 0000000000000..aa58e30a72711
--- /dev/null
+++ b/llvm/test/Analysis/DependenceAnalysis/weak_zero_siv_parametric_const.ll
@@ -0,0 +1,101 @@
+; 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-zero-siv 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-WEAK-ZERO-SIV
+
+; for (i = 0; i < 5; i++) {
+; A[4*a] = 0;
+; A[a*i] = 1;
+; }
+;
+; When `a` is zero, the two stores access the same memory location in every
+; iteration.
+;
+define void @weak_zero_src_siv_parametric_coeff(ptr %A, i64 %a) {
+; CHECK-ALL-LABEL: 'weak_zero_src_siv_parametric_coeff'
+; 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 - consistent output [S]!
+; 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 - output [*|<]!
+; 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 - consistent output [0]!
+; CHECK-ALL-NEXT: Runtime Assumptions:
+; CHECK-ALL-NEXT: Compare predicate: %a ne) 0
+;
+; CHECK-WEAK-ZERO-SIV-LABEL: 'weak_zero_src_siv_parametric_coeff'
+; CHECK-WEAK-ZERO-SIV-NEXT: Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1
+; CHECK-WEAK-ZERO-SIV-NEXT: da analyze - consistent output [S]!
+; CHECK-WEAK-ZERO-SIV-NEXT: Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-WEAK-ZERO-SIV-NEXT: da analyze - output [*|<]!
+; CHECK-WEAK-ZERO-SIV-NEXT: Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-WEAK-ZERO-SIV-NEXT: da analyze - consistent output [*]!
+;
+entry:
+ %const = mul nuw nsw i64 %a, 4
+ br label %loop
+
+loop:
+ %i = phi i64 [ 0, %entry ], [ %i.inc, %loop ]
+ %offset = phi i64 [ 0, %entry ], [ %offset.next, %loop ]
+ %gep.0 = getelementptr inbounds i8, ptr %A, i64 %const
+ store i8 0, ptr %gep.0
+ %gep.1 = getelementptr inbounds i8, ptr %A, i64 %offset
+ store i8 1, ptr %gep.1
+ %i.inc = add i64 %i, 1
+ %offset.next = add nuw nsw i64 %offset, %a
+ %ec = icmp eq i64 %i.inc, 5
+ br i1 %ec, label %exit, label %loop
+
+exit:
+ ret void
+}
+
+; for (i = 0; i < 5; i++) {
+; A[a*i] = 0;
+; A[4*i] = 1;
+; }
+;
+; When `a` is zero, the two stores access the same memory location in every
+; iteration.
+;
+define void @weak_zero_dst_siv_parametric_coeff(ptr %A, i64 %a) {
+; CHECK-ALL-LABEL: 'weak_zero_dst_siv_parametric_coeff'
+; 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 - consistent output [0]!
+; CHECK-ALL-NEXT: Runtime Assumptions:
+; CHECK-ALL-NEXT: Compare predicate: %a ne) 0
+; 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 - output [*|<]!
+; 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 - consistent output [S]!
+;
+; CHECK-WEAK-ZERO-SIV-LABEL: 'weak_zero_dst_siv_parametric_coeff'
+; CHECK-WEAK-ZERO-SIV-NEXT: Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1
+; CHECK-WEAK-ZERO-SIV-NEXT: da analyze - consistent output [*]!
+; CHECK-WEAK-ZERO-SIV-NEXT: Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-WEAK-ZERO-SIV-NEXT: da analyze - output [*|<]!
+; CHECK-WEAK-ZERO-SIV-NEXT: Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
+; CHECK-WEAK-ZERO-SIV-NEXT: da analyze - consistent output [S]!
+;
+entry:
+ %const = mul nuw nsw i64 %a, 4
+ br label %loop
+
+loop:
+ %i = phi i64 [ 0, %entry ], [ %i.inc, %loop ]
+ %offset = phi i64 [ 0, %entry ], [ %offset.next, %loop ]
+ %gep.0 = getelementptr inbounds i8, ptr %A, i64 %offset
+ store i8 0, ptr %gep.0
+ %gep.1 = getelementptr inbounds i8, ptr %A, i64 %const
+ store i8 1, ptr %gep.1
+ %i.inc = add i64 %i, 1
+ %offset.next = add nuw nsw i64 %offset, %a
+ %ec = icmp eq i64 %i.inc, 5
+ br i1 %ec, label %exit, label %loop
+
+exit:
+ ret void
+}
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; CHECK: {{.*}}
More information about the llvm-commits
mailing list