Skip to content

Commit 503da3b

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 6683b55 commit 503da3b

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

llvm/lib/Analysis/DependenceAnalysis.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,14 @@ static AliasResult underlyingObjectsAlias(AAResults *AA, LoopInfo *LI,
722722
const Value *AObj = getUnderlyingObject(LocA.Ptr);
723723
const Value *BObj = getUnderlyingObject(LocB.Ptr);
724724

725-
// If the underlying objects are the same, they must alias.
726-
if (AObj == BObj)
725+
if (AObj == BObj) {
726+
// The dependence test gets confused if the size of the memory accesses differ.
727+
if (LocA.Size != LocB.Size)
728+
return AliasResult::MayAlias;
729+
730+
// If the underlying objects are the same, they must alias.
727731
return AliasResult::MustAlias;
732+
}
728733

729734
if (auto *APhi = dyn_cast<PHINode>(AObj)) {
730735
if (auto *BPhi = dyn_cast<PHINode>(BObj)) {
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)