Skip to content

Commit 1515c4a

Browse files
fhahntstellar
authored andcommitted
[LAA] Consider accessed addrspace when mapping underlying obj to access. (#129087)
In some cases, it is possible for the same underlying object to be accessed via pointers to different address spaces. This could lead to pointers from different address spaces ending up in the same dependency set, which isn't allowed (and triggers an assertion). Update the mapping from underlying object -> last access to also include the accessing address space. Fixes #124759. PR: #129087
1 parent 1cfbb9f commit 1515c4a

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,8 +1283,10 @@ void AccessAnalysis::processMemAccesses() {
12831283

12841284
bool SetHasWrite = false;
12851285

1286-
// Map of pointers to last access encountered.
1287-
typedef DenseMap<const Value*, MemAccessInfo> UnderlyingObjToAccessMap;
1286+
// Map of (pointer to underlying objects, accessed address space) to last
1287+
// access encountered.
1288+
typedef DenseMap<std::pair<const Value *, unsigned>, MemAccessInfo>
1289+
UnderlyingObjToAccessMap;
12881290
UnderlyingObjToAccessMap ObjToLastAccess;
12891291

12901292
// Set of access to check after all writes have been processed.
@@ -1364,12 +1366,14 @@ void AccessAnalysis::processMemAccesses() {
13641366
UnderlyingObj->getType()->getPointerAddressSpace()))
13651367
continue;
13661368

1369+
unsigned AccessAS = cast<PointerType>(Ptr->getType())->getAddressSpace();
13671370
UnderlyingObjToAccessMap::iterator Prev =
1368-
ObjToLastAccess.find(UnderlyingObj);
1371+
ObjToLastAccess.find({UnderlyingObj,AccessAS
1372+
});
13691373
if (Prev != ObjToLastAccess.end())
13701374
DepCands.unionSets(Access, Prev->second);
13711375

1372-
ObjToLastAccess[UnderlyingObj] = Access;
1376+
ObjToLastAccess[{UnderlyingObj, AccessAS}] = Access;
13731377
LLVM_DEBUG(dbgs() << " " << *UnderlyingObj << "\n");
13741378
}
13751379
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -passes='print<access-info>' -disable-output %s 2>&1 | FileCheck %s
3+
4+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
5+
6+
; Test case for https://github.com/llvm/llvm-project/issues/124759. The same
7+
; underlying object is access through pointers with different address spaces.
8+
define void @same_underlying_object_different_address_spaces(ptr %dst1.as1, ptr %dst2.as1) {
9+
; CHECK-LABEL: 'same_underlying_object_different_address_spaces'
10+
; CHECK-NEXT: loop:
11+
; CHECK-NEXT: Report: cannot identify array bounds
12+
; CHECK-NEXT: Dependences:
13+
; CHECK-NEXT: Run-time memory checks:
14+
; CHECK-NEXT: Grouped accesses:
15+
; CHECK-EMPTY:
16+
; CHECK-NEXT: Non vectorizable stores to invariant address were not found in loop.
17+
; CHECK-NEXT: SCEV assumptions:
18+
; CHECK-EMPTY:
19+
; CHECK-NEXT: Expressions re-written:
20+
;
21+
entry:
22+
%alloc = alloca i8, i64 0, align 128
23+
%as3 = addrspacecast ptr %alloc to ptr addrspace(3)
24+
%as4 = addrspacecast ptr %alloc to ptr addrspace(4)
25+
br label %loop
26+
27+
loop:
28+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
29+
store i32 0, ptr addrspace(4) %as4, align 4
30+
store i32 0, ptr %dst1.as1, align 4
31+
%l = load i64, ptr addrspace(3) %as3, align 4
32+
store i64 %l, ptr %dst2.as1, align 4
33+
%iv.next = add i64 %iv, 1
34+
%c = icmp eq i64 %iv.next, 100
35+
br i1 %c, label %loop, label %exit
36+
37+
exit:
38+
ret void
39+
}

0 commit comments

Comments
 (0)