[llvm-branch-commits] [llvm] [DA] Add overflow check in GCD MIV (PR #172003)
Ryotaro Kasuga via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Mar 31 03:06:06 PDT 2026
https://github.com/kasuga-fj updated https://github.com/llvm/llvm-project/pull/172003
>From 48ff376d322159ef6ff21a2035849b1d2e437a67 Mon Sep 17 00:00:00 2001
From: Ryotaro Kasuga <kasuga.ryotaro at fujitsu.com>
Date: Fri, 12 Dec 2025 12:08:58 +0000
Subject: [PATCH] [DA] Add overflow check in GCD MIV
---
llvm/lib/Analysis/DependenceAnalysis.cpp | 4 +++-
llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll | 5 ++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp
index 22e486a6d3b7d..1abac06e232cc 100644
--- a/llvm/lib/Analysis/DependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -2285,7 +2285,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 6e729e86a9ce1..1d1ba010abe82 100644
--- a/llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll
+++ b/llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll
@@ -189,8 +189,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) == (1844674407370955160,1)
; ------------------------------------|----------------------------------
@@ -210,7 +209,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 [* *]!
;
More information about the llvm-branch-commits
mailing list