[llvm] [DA] Fix overflows when calculating Delta in the Weak Zero SIV tests (PR #184997)
Ryotaro Kasuga via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 6 05:30:31 PST 2026
https://github.com/kasuga-fj updated https://github.com/llvm/llvm-project/pull/184997
>From 81f886c3fb547f999320f504894ec5c56dd7944b Mon Sep 17 00:00:00 2001
From: Ryotaro Kasuga <kasuga.ryotaro at fujitsu.com>
Date: Fri, 6 Mar 2026 12:14:10 +0000
Subject: [PATCH] [DA] Fix overflows when calculating Delta in the Weak Zero
SIV tests
---
llvm/lib/Analysis/DependenceAnalysis.cpp | 12 ++++++++----
.../DependenceAnalysis/weak-zero-siv-overflow.ll | 11 ++++-------
2 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp
index a9f436c0d32a7..56177f11cc870 100644
--- a/llvm/lib/Analysis/DependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -1829,8 +1829,6 @@ bool DependenceInfo::weakZeroSrcSIVtest(const SCEV *DstCoeff,
++WeakZeroSIVapplications;
assert(0 < Level && Level <= MaxLevels && "Level out of range");
Level--;
- const SCEV *Delta = SE->getMinusSCEV(SrcConst, DstConst);
- LLVM_DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
if (SrcConst == DstConst && SE->isKnownNonZero(DstCoeff)) {
if (Level < CommonLevels) {
Result.DV[Level].Direction &= Dependence::DVEntry::GE;
@@ -1838,6 +1836,10 @@ bool DependenceInfo::weakZeroSrcSIVtest(const SCEV *DstCoeff,
}
return false; // dependences caused by first iteration
}
+ const SCEV *Delta = minusSCEVNoSignedOverflow(SrcConst, DstConst, *SE);
+ if (!Delta)
+ return false;
+ LLVM_DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
const SCEVConstant *ConstCoeff = dyn_cast<SCEVConstant>(DstCoeff);
if (!ConstCoeff)
return false;
@@ -1939,8 +1941,6 @@ bool DependenceInfo::weakZeroDstSIVtest(const SCEV *SrcCoeff,
++WeakZeroSIVapplications;
assert(0 < Level && Level <= SrcLevels && "Level out of range");
Level--;
- const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
- LLVM_DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
if (DstConst == SrcConst && SE->isKnownNonZero(SrcCoeff)) {
if (Level < CommonLevels) {
Result.DV[Level].Direction &= Dependence::DVEntry::LE;
@@ -1948,6 +1948,10 @@ bool DependenceInfo::weakZeroDstSIVtest(const SCEV *SrcCoeff,
}
return false; // dependences caused by first iteration
}
+ const SCEV *Delta = minusSCEVNoSignedOverflow(DstConst, SrcConst, *SE);
+ if (!Delta)
+ return false;
+ LLVM_DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
const SCEVConstant *ConstCoeff = dyn_cast<SCEVConstant>(SrcCoeff);
if (!ConstCoeff)
return false;
diff --git a/llvm/test/Analysis/DependenceAnalysis/weak-zero-siv-overflow.ll b/llvm/test/Analysis/DependenceAnalysis/weak-zero-siv-overflow.ll
index f388502ac2a43..9c63346e5d752 100644
--- a/llvm/test/Analysis/DependenceAnalysis/weak-zero-siv-overflow.ll
+++ b/llvm/test/Analysis/DependenceAnalysis/weak-zero-siv-overflow.ll
@@ -66,18 +66,15 @@ exit:
; A[INT64_MAX] = 2;
; }
;
-; FIXME: DependenceAnalysis currently detects no dependency between the two
-; stores, but it does exist. When `%n` is 2^62, the value of `%offset` will be
-; the same as INT64_MAX at the last iteration.
-; The root cause is that the calculation of the difference between the two
-; constants (INT64_MAX and -1) overflows in a signed sense.
+; When `%n` is 2^62, the value of `%offset` will be the same as INT64_MAX at
+; the last iteration.
;
define void @weakzero_dst_siv_delta_ovfl(ptr %A, i64 %n) {
; CHECK-ALL-LABEL: 'weakzero_dst_siv_delta_ovfl'
; CHECK-ALL-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.0, align 1
; CHECK-ALL-NEXT: da analyze - none!
; CHECK-ALL-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
-; CHECK-ALL-NEXT: da analyze - none!
+; CHECK-ALL-NEXT: da analyze - output [*|<]!
; CHECK-ALL-NEXT: Src: store i8 2, ptr %gep.1, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
; CHECK-ALL-NEXT: da analyze - output [S]!
;
@@ -85,7 +82,7 @@ define void @weakzero_dst_siv_delta_ovfl(ptr %A, i64 %n) {
; CHECK-WEAK-ZERO-SIV-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.0, align 1
; CHECK-WEAK-ZERO-SIV-NEXT: da analyze - output [*]!
; CHECK-WEAK-ZERO-SIV-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
-; CHECK-WEAK-ZERO-SIV-NEXT: da analyze - none!
+; CHECK-WEAK-ZERO-SIV-NEXT: da analyze - output [*|<]!
; CHECK-WEAK-ZERO-SIV-NEXT: Src: store i8 2, ptr %gep.1, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
; CHECK-WEAK-ZERO-SIV-NEXT: da analyze - output [S]!
;
More information about the llvm-commits
mailing list