From d4fe0a8efbd29d0c0173802a84b7c61503d0d804 Mon Sep 17 00:00:00 2001 From: Ryotaro Kasuga Date: Fri, 28 Nov 2025 15:20:49 +0000 Subject: [PATCH 1/2] [DA] Remove special handling for SCEVAddExpr in GCD MIV --- llvm/lib/Analysis/DependenceAnalysis.cpp | 17 ----------------- .../DependenceAnalysis/gcd-miv-overflow.ll | 9 ++++----- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp index 253f4d1441098..d03cb6a5a5cf7 100644 --- a/llvm/lib/Analysis/DependenceAnalysis.cpp +++ b/llvm/lib/Analysis/DependenceAnalysis.cpp @@ -2585,23 +2585,6 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst, const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst); LLVM_DEBUG(dbgs() << " Delta = " << *Delta << "\n"); const SCEVConstant *Constant = dyn_cast(Delta); - if (const SCEVAddExpr *Sum = dyn_cast(Delta)) { - // If Delta is a sum of products, we may be able to make further progress. - for (const SCEV *Operand : Sum->operands()) { - if (isa(Operand)) { - assert(!Constant && "Surprised to find multiple constants"); - Constant = cast(Operand); - } else if (const SCEVMulExpr *Product = dyn_cast(Operand)) { - // Search for constant operand to participate in GCD; - // If none found; return false. - std::optional ConstOp = getConstanCoefficient(Product); - if (!ConstOp) - return false; - ExtraGCD = APIntOps::GreatestCommonDivisor(ExtraGCD, ConstOp->abs()); - } else - return false; - } - } if (!Constant) return false; APInt ConstDelta = cast(Constant)->getAPInt(); diff --git a/llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll b/llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll index 618d14c75faad..f6b23f18df738 100644 --- a/llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll +++ b/llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll @@ -127,9 +127,8 @@ exit: ; A[-3*i - 3*m - INT64_MAX] = 1; ; } ; -; FIXME: DependenceAnalysis currently detects no dependency between the two -; stores, but it may exist. For example, consider `m = 1`. Then, -; `-3*m - INT64_MAX` is `INT64_MAX - 1`. So `-3*i - 3*m - INT64_MAX` is +; Dependency may exist between the two stores. For example, consider `m = 1`. +; Then, `-3*m - INT64_MAX` is `INT64_MAX - 1`. So `-3*i - 3*m - INT64_MAX` is ; effectively `-3*i + (INT64_MAX - 1)`. Thus, accesses will be as follows: ; ; memory access | i == 1 | i == max_i - 1 @@ -143,7 +142,7 @@ define void @gcdmiv_const_ovfl(ptr %A, i64 %m) { ; CHECK-ALL-NEXT: Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1 ; CHECK-ALL-NEXT: da analyze - none! ; CHECK-ALL-NEXT: Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1 -; CHECK-ALL-NEXT: da analyze - none! +; CHECK-ALL-NEXT: da analyze - output [*|<]! ; CHECK-ALL-NEXT: Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1 ; CHECK-ALL-NEXT: da analyze - none! ; @@ -151,7 +150,7 @@ define void @gcdmiv_const_ovfl(ptr %A, i64 %m) { ; 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 - consistent output [*]! ; CHECK-GCD-MIV-NEXT: Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1 -; CHECK-GCD-MIV-NEXT: da analyze - none! +; CHECK-GCD-MIV-NEXT: da analyze - consistent output [*|<]! ; CHECK-GCD-MIV-NEXT: Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1 ; CHECK-GCD-MIV-NEXT: da analyze - consistent output [*]! ; From 6b3d00864793f5663defd272565e9cf1d9304c8f Mon Sep 17 00:00:00 2001 From: Ryotaro Kasuga Date: Mon, 1 Dec 2025 22:44:49 +0900 Subject: [PATCH 2/2] remove unnecessary GCD calculation --- llvm/lib/Analysis/DependenceAnalysis.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp index d03cb6a5a5cf7..aa6c0be994d14 100644 --- a/llvm/lib/Analysis/DependenceAnalysis.cpp +++ b/llvm/lib/Analysis/DependenceAnalysis.cpp @@ -2591,7 +2591,6 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst, LLVM_DEBUG(dbgs() << " ConstDelta = " << ConstDelta << "\n"); if (ConstDelta == 0) return false; - RunningGCD = APIntOps::GreatestCommonDivisor(RunningGCD, ExtraGCD); LLVM_DEBUG(dbgs() << " RunningGCD = " << RunningGCD << "\n"); APInt Remainder = ConstDelta.srem(RunningGCD); if (Remainder != 0) {