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 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 [* *]! ;