[llvm] [DA] Fix overflows when calculating Delta in the Weak Zero SIV tests (PR #184997)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 6 06:19:01 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Ryotaro Kasuga (kasuga-fj)
<details>
<summary>Changes</summary>
Add overflow checks when computing `Delta` in the Weak Zero SIV tests. The tests bail out if we cannot prove that the `Delta` computation does not overflow. These calculations are also moved later so that some analyses that do not require these checks can run first.
Fix part of the test cases added in #<!-- -->164246.
---
Full diff: https://github.com/llvm/llvm-project/pull/184997.diff
2 Files Affected:
- (modified) llvm/lib/Analysis/DependenceAnalysis.cpp (+8-4)
- (modified) llvm/test/Analysis/DependenceAnalysis/weak-zero-siv-overflow.ll (+4-7)
``````````diff
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]!
;
``````````
</details>
https://github.com/llvm/llvm-project/pull/184997
More information about the llvm-commits
mailing list