Skip to content

Commit 4a15a58

Browse files
committed
[DA] Dependence analysis does not handle array accesses of different sizes
This fixes bug llvm#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 a9d9483 commit 4a15a58

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

llvm/lib/Analysis/DependenceAnalysis.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,14 @@ static AliasResult underlyingObjectsAlias(AAResults *AA,
730730
const Value *BObj = getUnderlyingObject(LocB.Ptr);
731731

732732
// If the underlying objects are the same, they must alias
733-
if (AObj == BObj)
733+
if (AObj == BObj) {
734+
// The dependence test gets confused if the size of the memory accesses
735+
// differ.
736+
if (LocA.Size != LocB.Size)
737+
return AliasResult::MayAlias;
738+
734739
return AliasResult::MustAlias;
740+
}
735741

736742
// We may have hit the recursion limit for underlying objects, or have
737743
// underlying objects where we don't know they will alias.
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)