Skip to content

Commit e764580

Browse files
committed
[DA] Add overflow check when calculating Delta in GCD MIV
1 parent 7ace62a commit e764580

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

llvm/lib/Analysis/DependenceAnalysis.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2587,7 +2587,9 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,
25872587
const SCEV *DstConst = Coefficients;
25882588

25892589
APInt ExtraGCD = APInt::getZero(BitWidth);
2590-
const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
2590+
const SCEV *Delta = minusSCEVNoSignedOverflow(DstConst, SrcConst, *SE);
2591+
if (!Delta)
2592+
return false;
25912593
LLVM_DEBUG(dbgs() << " Delta = " << *Delta << "\n");
25922594
const SCEVConstant *Constant = dyn_cast<SCEVConstant>(Delta);
25932595
if (const SCEVAddExpr *Sum = dyn_cast<SCEVAddExpr>(Delta)) {

llvm/test/Analysis/DependenceAnalysis/gcd-miv-overflow.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ define void @gcdmiv_delta_ovfl(ptr %A) {
8989
; CHECK-GCD-MIV-NEXT: Src: store i8 0, ptr %idx.0, align 1 --> Dst: store i8 0, ptr %idx.0, align 1
9090
; CHECK-GCD-MIV-NEXT: da analyze - consistent output [*]!
9191
; CHECK-GCD-MIV-NEXT: Src: store i8 0, ptr %idx.0, align 1 --> Dst: store i8 1, ptr %idx.1, align 1
92-
; CHECK-GCD-MIV-NEXT: da analyze - none!
92+
; CHECK-GCD-MIV-NEXT: da analyze - consistent output [*|<]!
9393
; CHECK-GCD-MIV-NEXT: Src: store i8 1, ptr %idx.1, align 1 --> Dst: store i8 1, ptr %idx.1, align 1
9494
; CHECK-GCD-MIV-NEXT: da analyze - consistent output [*]!
9595
;

0 commit comments

Comments
 (0)