Skip to content

Conversation

@kasuga-fj
Copy link
Contributor

@kasuga-fj kasuga-fj commented Nov 28, 2025

Add overflow check when computing Delta in gcdMIVtest.

Fix one of the tests added by #169926.

Copy link
Contributor Author

kasuga-fj commented Nov 28, 2025

@kasuga-fj kasuga-fj marked this pull request as ready for review November 29, 2025 01:50
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Nov 29, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 29, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Ryotaro Kasuga (kasuga-fj)

Changes

Add overflow check when computing Delta in gcdMIVtest.

Fix one of the tests added by #169926.


Full diff: https://github.com/llvm/llvm-project/pull/169928.diff

2 Files Affected:

  • (modified) llvm/lib/Analysis/DependenceAnalysis.cpp (+3-1)
  • (modified) llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll (+1-1)
diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp
index 77b09fb15316e..73a7b59c81f27 100644
--- a/llvm/lib/Analysis/DependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -2587,7 +2587,9 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,
   const SCEV *DstConst = Coefficients;
 
   APInt ExtraGCD = APInt::getZero(BitWidth);
-  const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
+  const SCEV *Delta = minusSCEVNoSignedOverflow(DstConst, SrcConst, *SE);
+  if (!Delta)
+    return false;
   LLVM_DEBUG(dbgs() << "    Delta = " << *Delta << "\n");
   const SCEVConstant *Constant = dyn_cast<SCEVConstant>(Delta);
   if (const SCEVAddExpr *Sum = dyn_cast<SCEVAddExpr>(Delta)) {
diff --git a/llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll b/llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll
index 618d14c75faad..76bab98207c79 100644
--- a/llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll
+++ b/llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll
@@ -89,7 +89,7 @@ define void @gcdmiv_delta_ovfl(ptr %A) {
 ; CHECK-GCD-MIV-NEXT:  Src: store i8 0, ptr %idx.0, align 1 --> Dst: store i8 0, ptr %idx.0, align 1
 ; CHECK-GCD-MIV-NEXT:    da analyze - consistent output [*]!
 ; CHECK-GCD-MIV-NEXT:  Src: store i8 0, ptr %idx.0, align 1 --> Dst: store i8 1, ptr %idx.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 %idx.1, align 1 --> Dst: store i8 1, ptr %idx.1, align 1
 ; CHECK-GCD-MIV-NEXT:    da analyze - consistent output [*]!
 ;

Copy link
Member

@Meinersbur Meinersbur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

kasuga-fj added a commit that referenced this pull request Dec 1, 2025
…169926)

Add two test cases where dependencies are missed due to overflows. These
will be fixed by #169927 and #169928, respectively.
Base automatically changed from users/kasuga-fj/da-gcdmiv-delta-overflow-test to main December 1, 2025 13:36
@kasuga-fj kasuga-fj force-pushed the users/kasuga-fj/da-gcdmiv-delta-overflow-check branch from e764580 to 905e917 Compare December 1, 2025 13:38
@kasuga-fj kasuga-fj enabled auto-merge (squash) December 1, 2025 13:41
aahrun pushed a commit to aahrun/llvm-project that referenced this pull request Dec 1, 2025
…lvm#169926)

Add two test cases where dependencies are missed due to overflows. These
will be fixed by llvm#169927 and llvm#169928, respectively.
@kasuga-fj kasuga-fj merged commit 461433f into main Dec 1, 2025
9 of 10 checks passed
@kasuga-fj kasuga-fj deleted the users/kasuga-fj/da-gcdmiv-delta-overflow-check branch December 1, 2025 14:03
augusto2112 pushed a commit to augusto2112/llvm-project that referenced this pull request Dec 3, 2025
…lvm#169926)

Add two test cases where dependencies are missed due to overflows. These
will be fixed by llvm#169927 and llvm#169928, respectively.
augusto2112 pushed a commit to augusto2112/llvm-project that referenced this pull request Dec 3, 2025
Add overflow check when computing `Delta` in `gcdMIVtest`.

Fix one of the tests added by llvm#169926.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants