Skip to content

Commit 150f723

Browse files
committed
[DA] Dependence analysis does not handle array accesses of different sizes
This fixes bug #16183 where the elements of a same array are accesses as i32 and i64. This is not handled by the array dependence analysis.
1 parent 182f9aa commit 150f723

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

llvm/lib/Analysis/DependenceAnalysis.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3601,14 +3601,10 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
36013601
return std::make_unique<Dependence>(Src, Dst);
36023602
}
36033603

3604-
assert(isLoadOrStore(Src) && "instruction is not load or store");
3605-
assert(isLoadOrStore(Dst) && "instruction is not load or store");
3606-
Value *SrcPtr = getLoadStorePointerOperand(Src);
3607-
Value *DstPtr = getLoadStorePointerOperand(Dst);
3604+
const MemoryLocation &LocA = MemoryLocation::get(Dst);
3605+
const MemoryLocation &LocB = MemoryLocation::get(Src);
36083606

3609-
switch (underlyingObjectsAlias(AA, F->getDataLayout(),
3610-
MemoryLocation::get(Dst),
3611-
MemoryLocation::get(Src))) {
3607+
switch (underlyingObjectsAlias(AA, F->getDataLayout(), LocA, LocB)) {
36123608
case AliasResult::MayAlias:
36133609
case AliasResult::PartialAlias:
36143610
// cannot analyse objects if we don't understand their aliasing.
@@ -3622,6 +3618,13 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
36223618
break; // The underlying objects alias; test accesses for dependence.
36233619
}
36243620

3621+
if (LocA.Size != LocB.Size) {
3622+
// The dependence test gets confused if the size of the memory accesses
3623+
// differ.
3624+
LLVM_DEBUG(dbgs() << "can't analyze must alias with different sizes\n");
3625+
return std::make_unique<Dependence>(Src, Dst);
3626+
}
3627+
36253628
// establish loop nesting levels
36263629
establishNestingLevels(Src, Dst);
36273630
LLVM_DEBUG(dbgs() << " common nesting levels = " << CommonLevels << "\n");
@@ -3632,6 +3635,8 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
36323635

36333636
unsigned Pairs = 1;
36343637
SmallVector<Subscript, 2> Pair(Pairs);
3638+
Value *SrcPtr = getLoadStorePointerOperand(Src);
3639+
Value *DstPtr = getLoadStorePointerOperand(Dst);
36353640
const SCEV *SrcSCEV = SE->getSCEV(SrcPtr);
36363641
const SCEV *DstSCEV = SE->getSCEV(DstPtr);
36373642
LLVM_DEBUG(dbgs() << " SrcSCEV = " << *SrcSCEV << "\n");
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; RUN: opt < %s -disable-output "-passes=print<da>" -aa-pipeline=basic-aa 2>&1 \
2+
; RUN: | FileCheck %s
3+
4+
; The dependence test does not handle array accesses of different sizes: i32 and i64.
5+
; Bug 16183 - https://github.com/llvm/llvm-project/issues/16183
6+
; CHECK-LABEL: bug16183_alias
7+
; CHECK: da analyze - confused!
8+
9+
define i64 @bug16183_alias(i32* nocapture %A) {
10+
entry:
11+
%arrayidx = getelementptr inbounds i32, ptr %A, i64 1
12+
store i32 2, ptr %arrayidx, align 4
13+
%0 = load i64, ptr %A, align 8
14+
ret i64 %0
15+
}

0 commit comments

Comments
 (0)