[llvm-branch-commits] [llvm] [DA] Fix overflow in the Exact RDIV test (PR #189578)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Mar 31 03:10:55 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Ryotaro Kasuga (kasuga-fj)

<details>
<summary>Changes</summary>

This patch adds an overflow check for the computation of `Delta` in the Exact RDIV test. If an overflow is detected, the analysis bails out.

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


2 Files Affected:

- (modified) llvm/lib/Analysis/DependenceAnalysis.cpp (+3-1) 
- (modified) llvm/test/Analysis/DependenceAnalysis/exact-rdiv-delta-overflow.ll (+3-3) 


``````````diff
diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp
index 22e486a6d3b7d..94970b60aa512 100644
--- a/llvm/lib/Analysis/DependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -1957,7 +1957,9 @@ bool DependenceInfo::exactRDIVtest(const SCEVAddRecExpr *Src,
   if (!Src->hasNoSignedWrap() || !Dst->hasNoSignedWrap())
     return false;
 
-  const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
+  const SCEV *Delta = minusSCEVNoSignedOverflow(DstConst, SrcConst, *SE);
+  if (!Delta)
+    return false;
   LLVM_DEBUG(dbgs() << "\t    Delta = " << *Delta << "\n");
   const SCEVConstant *ConstDelta = dyn_cast<SCEVConstant>(Delta);
   const SCEVConstant *ConstSrcCoeff = dyn_cast<SCEVConstant>(SrcCoeff);
diff --git a/llvm/test/Analysis/DependenceAnalysis/exact-rdiv-delta-overflow.ll b/llvm/test/Analysis/DependenceAnalysis/exact-rdiv-delta-overflow.ll
index 25b7ccb837709..2570ed98ea4e3 100644
--- a/llvm/test/Analysis/DependenceAnalysis/exact-rdiv-delta-overflow.ll
+++ b/llvm/test/Analysis/DependenceAnalysis/exact-rdiv-delta-overflow.ll
@@ -20,14 +20,14 @@
 ;  A[-6*i + INT64_MAX]     |       | A[3*max_i - 2]         | A[1]
 ;  A[3*i - 2]              | A[1]  |                        | A[3*max_i - 2]
 ;
-; FIXME: There is a dependency between the two stores.
+; There is a dependency between the two stores.
 ;
 define void @exact_rdiv_delta_ovfl(ptr %A) {
 ; CHECK-ALL-LABEL: 'exact_rdiv_delta_ovfl'
 ; 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!
 ;
@@ -35,7 +35,7 @@ define void @exact_rdiv_delta_ovfl(ptr %A) {
 ; CHECK-EXACT-RDIV-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1
 ; CHECK-EXACT-RDIV-NEXT:    da analyze - output [*]!
 ; CHECK-EXACT-RDIV-NEXT:  Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
-; CHECK-EXACT-RDIV-NEXT:    da analyze - none!
+; CHECK-EXACT-RDIV-NEXT:    da analyze - output [|<]!
 ; CHECK-EXACT-RDIV-NEXT:  Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
 ; CHECK-EXACT-RDIV-NEXT:    da analyze - output [*]!
 ;

``````````

</details>


https://github.com/llvm/llvm-project/pull/189578


More information about the llvm-branch-commits mailing list