[llvm] 7dda8ba - [DA] Fix the Weak Zero SIV tests when the coeff may be zero (#183736)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 5 23:28:27 PST 2026
Author: Ryotaro Kasuga
Date: 2026-03-06T07:28:21Z
New Revision: 7dda8ba3751d65ba96d1adf6c61b1e590fbfdee2
URL: https://github.com/llvm/llvm-project/commit/7dda8ba3751d65ba96d1adf6c61b1e590fbfdee2
DIFF: https://github.com/llvm/llvm-project/commit/7dda8ba3751d65ba96d1adf6c61b1e590fbfdee2.diff
LOG: [DA] Fix the Weak Zero SIV tests when the coeff may be zero (#183736)
In the Weak Zero SIV tests, given two subscripts `{c0,+,a}` and `c1`,
when `c0 == c1`, the tests conclude that a dependency exists from the
former subscript at the first iteration to the latter subscript at every
iteration. However, this conclusion is correct only when `a` is not
zero, which was not being checked.
This patch adds non-zero checks for `a` in the Weak Zero SIV tests.
Fix the test cases added in #183735 .
Added:
Modified:
llvm/lib/Analysis/DependenceAnalysis.cpp
llvm/test/Analysis/DependenceAnalysis/WeakZeroDstSIV.ll
llvm/test/Analysis/DependenceAnalysis/WeakZeroSrcSIV.ll
llvm/test/Analysis/DependenceAnalysis/weak_zero_siv_parametric_coeff.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp
index 8ac118734b8d0..b2bdefbb3afb0 100644
--- a/llvm/lib/Analysis/DependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -1847,7 +1847,7 @@ bool DependenceInfo::weakZeroSrcSIVtest(const SCEV *DstCoeff,
Level--;
const SCEV *Delta = SE->getMinusSCEV(SrcConst, DstConst);
LLVM_DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
- if (SE->isKnownPredicate(CmpInst::ICMP_EQ, SrcConst, DstConst)) {
+ if (SrcConst == DstConst && SE->isKnownNonZero(DstCoeff)) {
if (Level < CommonLevels) {
Result.DV[Level].Direction &= Dependence::DVEntry::GE;
Result.DV[Level].PeelFirst = true;
@@ -1959,7 +1959,7 @@ bool DependenceInfo::weakZeroDstSIVtest(const SCEV *SrcCoeff,
Level--;
const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
LLVM_DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
- if (SE->isKnownPredicate(CmpInst::ICMP_EQ, DstConst, SrcConst)) {
+ if (DstConst == SrcConst && SE->isKnownNonZero(SrcCoeff)) {
if (Level < CommonLevels) {
Result.DV[Level].Direction &= Dependence::DVEntry::LE;
Result.DV[Level].PeelFirst = true;
diff --git a/llvm/test/Analysis/DependenceAnalysis/WeakZeroDstSIV.ll b/llvm/test/Analysis/DependenceAnalysis/WeakZeroDstSIV.ll
index 819c8f5f76b83..4d9730a594674 100644
--- a/llvm/test/Analysis/DependenceAnalysis/WeakZeroDstSIV.ll
+++ b/llvm/test/Analysis/DependenceAnalysis/WeakZeroDstSIV.ll
@@ -94,7 +94,7 @@ define void @weakzerodst1(ptr %A, ptr %B, i64 %n) nounwind uwtable ssp {
; CHECK-NEXT: Runtime Assumptions:
; CHECK-NEXT: Compare predicate: (4 * %n) ne) 0
; CHECK-NEXT: Src: store i32 %conv, ptr %arrayidx, align 4 --> Dst: %0 = load i32, ptr %arrayidx1, align 4
-; CHECK-NEXT: da analyze - flow [p<=|<]!
+; CHECK-NEXT: da analyze - flow [*|<]!
; CHECK-NEXT: Src: store i32 %conv, ptr %arrayidx, align 4 --> Dst: store i32 %0, ptr %B.addr.02, align 4
; CHECK-NEXT: da analyze - confused!
; CHECK-NEXT: Src: %0 = load i32, ptr %arrayidx1, align 4 --> Dst: %0 = load i32, ptr %arrayidx1, align 4
diff --git a/llvm/test/Analysis/DependenceAnalysis/WeakZeroSrcSIV.ll b/llvm/test/Analysis/DependenceAnalysis/WeakZeroSrcSIV.ll
index a675215f4a2d7..f522d8b5625f3 100644
--- a/llvm/test/Analysis/DependenceAnalysis/WeakZeroSrcSIV.ll
+++ b/llvm/test/Analysis/DependenceAnalysis/WeakZeroSrcSIV.ll
@@ -90,7 +90,7 @@ define void @weakzerosrc1(ptr %A, ptr %B, i64 %n) nounwind uwtable ssp {
; CHECK-NEXT: Src: store i32 %conv, ptr %arrayidx, align 4 --> Dst: store i32 %conv, ptr %arrayidx, align 4
; CHECK-NEXT: da analyze - output [S]!
; CHECK-NEXT: Src: store i32 %conv, ptr %arrayidx, align 4 --> Dst: %0 = load i32, ptr %arrayidx1, align 4
-; CHECK-NEXT: da analyze - flow [p=>|<]!
+; CHECK-NEXT: da analyze - flow [*|<]!
; CHECK-NEXT: Src: store i32 %conv, ptr %arrayidx, align 4 --> Dst: store i32 %0, ptr %B.addr.02, align 4
; CHECK-NEXT: da analyze - confused!
; CHECK-NEXT: Src: %0 = load i32, ptr %arrayidx1, align 4 --> Dst: %0 = load i32, ptr %arrayidx1, align 4
diff --git a/llvm/test/Analysis/DependenceAnalysis/weak_zero_siv_parametric_coeff.ll b/llvm/test/Analysis/DependenceAnalysis/weak_zero_siv_parametric_coeff.ll
index 4b9af94f0a94a..533d8b99c6aff 100644
--- a/llvm/test/Analysis/DependenceAnalysis/weak_zero_siv_parametric_coeff.ll
+++ b/llvm/test/Analysis/DependenceAnalysis/weak_zero_siv_parametric_coeff.ll
@@ -12,15 +12,12 @@
; 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 - 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: 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 - output [0]!
; CHECK-ALL-NEXT: Runtime Assumptions:
@@ -30,7 +27,7 @@ define void @weak_zero_src_siv_parametric_coeff(ptr %A, i64 %a) {
; 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 - 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: 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 - output [*]!
;
@@ -61,9 +58,6 @@ exit:
; 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
@@ -71,7 +65,7 @@ define void @weak_zero_dst_siv_parametric_coeff(ptr %A, i64 %a) {
; 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: 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 - output [S]!
;
@@ -79,7 +73,7 @@ define void @weak_zero_dst_siv_parametric_coeff(ptr %A, i64 %a) {
; 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 - 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: 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 - output [S]!
;
More information about the llvm-commits
mailing list