[llvm-branch-commits] [llvm] [DA] Fix overflow in the Exact test (PR #200781)
Ryotaro Kasuga via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Jun 1 03:52:14 PDT 2026
https://github.com/kasuga-fj created https://github.com/llvm/llvm-project/pull/200781
None
>From 02d839ad337f1ef04a16e0592706b5a6512bb57a Mon Sep 17 00:00:00 2001
From: Ryotaro Kasuga <kasuga.ryotaro at fujitsu.com>
Date: Mon, 1 Jun 2026 10:43:37 +0000
Subject: [PATCH] [DA] Fix overflow in the Exact test
---
llvm/lib/Analysis/DependenceAnalysis.cpp | 14 ++++++++------
.../DependenceAnalysis/exact-siv-mul-overflow.ll | 4 +---
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp
index aa5ae814c934f..e56207e374524 100644
--- a/llvm/lib/Analysis/DependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -1588,12 +1588,14 @@ bool DependenceInfo::exactTestImpl(const SCEVAddRecExpr *Src,
APInt TU(APInt::getSignedMaxValue(Bits));
APInt TL(APInt::getSignedMinValue(Bits));
- APInt TC = CM.sdiv(G);
- APInt TX = X * TC;
- APInt TY = Y * TC;
- LLVM_DEBUG(dbgs() << "\t TC = " << TC << "\n");
- LLVM_DEBUG(dbgs() << "\t TX = " << TX << "\n");
- LLVM_DEBUG(dbgs() << "\t TY = " << TY << "\n");
+ OverflowSafeSignedAPInt TC = CM.sdiv(G);
+ OverflowSafeSignedAPInt TX = OverflowSafeSignedAPInt(X) * TC;
+ OverflowSafeSignedAPInt TY = OverflowSafeSignedAPInt(Y) * TC;
+ if (!TC || !TX || !TY)
+ return false;
+ LLVM_DEBUG(dbgs() << "\t TC = " << *TC << "\n");
+ LLVM_DEBUG(dbgs() << "\t TX = " << *TX << "\n");
+ LLVM_DEBUG(dbgs() << "\t TY = " << *TY << "\n");
APInt TB = BM.sdiv(G);
APInt TA = AM.sdiv(G);
diff --git a/llvm/test/Analysis/DependenceAnalysis/exact-siv-mul-overflow.ll b/llvm/test/Analysis/DependenceAnalysis/exact-siv-mul-overflow.ll
index 92e1f9ac565fd..5cb617099a0c8 100644
--- a/llvm/test/Analysis/DependenceAnalysis/exact-siv-mul-overflow.ll
+++ b/llvm/test/Analysis/DependenceAnalysis/exact-siv-mul-overflow.ll
@@ -18,15 +18,13 @@ target datalayout = "e-m:e-p:32:32-i64:64-n32-S128"
; A[5*i] | | A[750000000]
; A[8*i + 750000000]| A[750000000] |
;
-; FIXME: DependenceAnalysis currently fails to detect this dependency due to
-; mishandling of overflow.
;
define void @exactsiv_mul_overflow(ptr %A) {
; CHECK-LABEL: 'exactsiv_mul_overflow'
; CHECK-NEXT: Src: store i8 0, ptr %src.ptr, align 1 --> Dst: store i8 0, ptr %src.ptr, align 1
; CHECK-NEXT: da analyze - none!
; CHECK-NEXT: Src: store i8 0, ptr %src.ptr, align 1 --> Dst: store i8 1, ptr %dst.ptr, align 1
-; CHECK-NEXT: da analyze - none!
+; CHECK-NEXT: da analyze - output [*|<]!
; CHECK-NEXT: Src: store i8 1, ptr %dst.ptr, align 1 --> Dst: store i8 1, ptr %dst.ptr, align 1
; CHECK-NEXT: da analyze - none!
;
More information about the llvm-branch-commits
mailing list