[llvm-branch-commits] [llvm] [DA] Add overflow check in GCD MIV (PR #172003)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Dec 12 06:07:50 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Ryotaro Kasuga (kasuga-fj)
<details>
<summary>Changes</summary>
Add an overflow check in GCD MIV. Fix the test case added in #<!-- -->172002 .
---
Full diff: https://github.com/llvm/llvm-project/pull/172003.diff
2 Files Affected:
- (modified) llvm/lib/Analysis/DependenceAnalysis.cpp (+3-1)
- (modified) llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll (+2-3)
``````````diff
diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp
index 9b9c80a9b3266..b5d1a325d6ffe 100644
--- a/llvm/lib/Analysis/DependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -2653,7 +2653,9 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,
!accumulateCoefficientsGCD(Dst, CurLoop, DstCoeff, RunningGCD))
return false;
- Delta = SE->getMinusSCEV(SrcCoeff, DstCoeff);
+ Delta = minusSCEVNoSignedOverflow(DstCoeff, SrcCoeff, *SE);
+ if (!Delta)
+ continue;
// If the coefficient is the product of a constant and other stuff,
// we can use the constant in the GCD computation.
std::optional<APInt> ConstCoeff = getConstantCoefficient(Delta);
diff --git a/llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll b/llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll
index 2b00856aa9a52..6496cb41e733b 100644
--- a/llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll
+++ b/llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll
@@ -190,8 +190,7 @@ exit:
; if (offset1 == -5) A[offset1] = 0;
; }
;
-; FIXME: DependenceAnalysis fails to detect dependency between two stores. Also
-; GCD MIV misses '='-dependency.
+; FIXME: DependenceAnalysis fails to detect dependency between two stores.
;
; memory accesses | (i,j) == (1844674407370955161,1) | (i,j) == (1844674407370955160,1)
; ------------------------------------|----------------------------------|----------------------------------
@@ -211,7 +210,7 @@ define void @gcdmiv_delta_ovfl2(ptr %A) {
; CHECK-GCD-MIV-NEXT: Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1
; CHECK-GCD-MIV-NEXT: da analyze - output [* *]!
; CHECK-GCD-MIV-NEXT: Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.1, align 1
-; CHECK-GCD-MIV-NEXT: da analyze - output [* <>]!
+; CHECK-GCD-MIV-NEXT: da analyze - output [* *|<]!
; CHECK-GCD-MIV-NEXT: Src: store i8 0, ptr %gep.1, align 1 --> Dst: store i8 0, ptr %gep.1, align 1
; CHECK-GCD-MIV-NEXT: da analyze - output [* *]!
;
``````````
</details>
https://github.com/llvm/llvm-project/pull/172003
More information about the llvm-branch-commits
mailing list