Skip to content

Commit 5c0f0d7

Browse files
kasuga-fjaugusto2112
authored andcommitted
[DA] Remove special handling for SCEVAddExpr in GCD MIV (llvm#169927)
In `gcdMIVtest`, there is logic that assumes the addition(s) of `SCEVAddExpr` don't overflow without any checks. Adding overflow checks would be fine, but this part appeart to be less useful. So this patch removes it. Fix one of the tests added in llvm#169926.
1 parent 1961dcf commit 5c0f0d7

File tree

2 files changed

+4
-23
lines changed

2 files changed

+4
-23
lines changed

llvm/lib/Analysis/DependenceAnalysis.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2587,30 +2587,12 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,
25872587
return false;
25882588
LLVM_DEBUG(dbgs() << " Delta = " << *Delta << "\n");
25892589
const SCEVConstant *Constant = dyn_cast<SCEVConstant>(Delta);
2590-
if (const SCEVAddExpr *Sum = dyn_cast<SCEVAddExpr>(Delta)) {
2591-
// If Delta is a sum of products, we may be able to make further progress.
2592-
for (const SCEV *Operand : Sum->operands()) {
2593-
if (isa<SCEVConstant>(Operand)) {
2594-
assert(!Constant && "Surprised to find multiple constants");
2595-
Constant = cast<SCEVConstant>(Operand);
2596-
} else if (const SCEVMulExpr *Product = dyn_cast<SCEVMulExpr>(Operand)) {
2597-
// Search for constant operand to participate in GCD;
2598-
// If none found; return false.
2599-
std::optional<APInt> ConstOp = getConstanCoefficient(Product);
2600-
if (!ConstOp)
2601-
return false;
2602-
ExtraGCD = APIntOps::GreatestCommonDivisor(ExtraGCD, ConstOp->abs());
2603-
} else
2604-
return false;
2605-
}
2606-
}
26072590
if (!Constant)
26082591
return false;
26092592
APInt ConstDelta = cast<SCEVConstant>(Constant)->getAPInt();
26102593
LLVM_DEBUG(dbgs() << " ConstDelta = " << ConstDelta << "\n");
26112594
if (ConstDelta == 0)
26122595
return false;
2613-
RunningGCD = APIntOps::GreatestCommonDivisor(RunningGCD, ExtraGCD);
26142596
LLVM_DEBUG(dbgs() << " RunningGCD = " << RunningGCD << "\n");
26152597
APInt Remainder = ConstDelta.srem(RunningGCD);
26162598
if (Remainder != 0) {

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ exit:
127127
; A[-3*i - 3*m - INT64_MAX] = 1;
128128
; }
129129
;
130-
; FIXME: DependenceAnalysis currently detects no dependency between the two
131-
; stores, but it may exist. For example, consider `m = 1`. Then,
132-
; `-3*m - INT64_MAX` is `INT64_MAX - 1`. So `-3*i - 3*m - INT64_MAX` is
130+
; Dependency may exist between the two stores. For example, consider `m = 1`.
131+
; Then, `-3*m - INT64_MAX` is `INT64_MAX - 1`. So `-3*i - 3*m - INT64_MAX` is
133132
; effectively `-3*i + (INT64_MAX - 1)`. Thus, accesses will be as follows:
134133
;
135134
; memory access | i == 1 | i == max_i - 1
@@ -143,15 +142,15 @@ define void @gcdmiv_const_ovfl(ptr %A, i64 %m) {
143142
; CHECK-ALL-NEXT: Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1
144143
; CHECK-ALL-NEXT: da analyze - none!
145144
; CHECK-ALL-NEXT: Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
146-
; CHECK-ALL-NEXT: da analyze - none!
145+
; CHECK-ALL-NEXT: da analyze - output [*|<]!
147146
; CHECK-ALL-NEXT: Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
148147
; CHECK-ALL-NEXT: da analyze - none!
149148
;
150149
; CHECK-GCD-MIV-LABEL: 'gcdmiv_const_ovfl'
151150
; CHECK-GCD-MIV-NEXT: Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 0, ptr %gep.0, align 1
152151
; CHECK-GCD-MIV-NEXT: da analyze - consistent output [*]!
153152
; CHECK-GCD-MIV-NEXT: Src: store i8 0, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
154-
; CHECK-GCD-MIV-NEXT: da analyze - none!
153+
; CHECK-GCD-MIV-NEXT: da analyze - consistent output [*|<]!
155154
; CHECK-GCD-MIV-NEXT: Src: store i8 1, ptr %gep.1, align 1 --> Dst: store i8 1, ptr %gep.1, align 1
156155
; CHECK-GCD-MIV-NEXT: da analyze - consistent output [*]!
157156
;

0 commit comments

Comments
 (0)