Skip to content

Commit 3ccda93

Browse files
committed
[LAA] Update pointer-bounds cache to also consider access type.
The same pointer may be accessed with different types and the bound includes the size of the accessed type to compute the end. Update the cache to correctly disambiguate between different accessed types.
1 parent 3aae4ca commit 3ccda93

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

llvm/include/llvm/Analysis/LoopAccessAnalysis.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ class MemoryDepChecker {
269269

270270
const Loop *getInnermostLoop() const { return InnermostLoop; }
271271

272-
DenseMap<const SCEV *, std::pair<const SCEV *, const SCEV *>> &
272+
DenseMap<std::pair<const SCEV *, Type *>,
273+
std::pair<const SCEV *, const SCEV *>> &
273274
getPointerBounds() {
274275
return PointerBounds;
275276
}
@@ -334,7 +335,9 @@ class MemoryDepChecker {
334335

335336
/// Mapping of SCEV expressions to their expanded pointer bounds (pair of
336337
/// start and end pointer expressions).
337-
DenseMap<const SCEV *, std::pair<const SCEV *, const SCEV *>> PointerBounds;
338+
DenseMap<std::pair<const SCEV *, Type *>,
339+
std::pair<const SCEV *, const SCEV *>>
340+
PointerBounds;
338341

339342
/// Check whether there is a plausible dependence between the two
340343
/// accesses.

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,13 @@ RuntimeCheckingPtrGroup::RuntimeCheckingPtrGroup(
206206
static std::pair<const SCEV *, const SCEV *> getStartAndEndForAccess(
207207
const Loop *Lp, const SCEV *PtrExpr, Type *AccessTy,
208208
PredicatedScalarEvolution &PSE,
209-
DenseMap<const SCEV *, std::pair<const SCEV *, const SCEV *>>
210-
&PointerBounds) {
209+
DenseMap<std::pair<const SCEV *, Type *>,
210+
std::pair<const SCEV *, const SCEV *>> &PointerBounds) {
211211
ScalarEvolution *SE = PSE.getSE();
212212

213213
auto [Iter, Ins] = PointerBounds.insert(
214-
{PtrExpr, {SE->getCouldNotCompute(), SE->getCouldNotCompute()}});
214+
{{PtrExpr, AccessTy},
215+
{SE->getCouldNotCompute(), SE->getCouldNotCompute()}});
215216
if (!Ins)
216217
return Iter->second;
217218

llvm/test/Analysis/LoopAccessAnalysis/different-access-types-rt-checks.ll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
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"
55

6-
; FIXME: The runtime checks for A are based on i8 accesses, but should be based
7-
; on i32.
86
define void @loads_of_same_pointer_with_different_sizes1(ptr %A, ptr %B, i64 %N) {
97
; CHECK-LABEL: 'loads_of_same_pointer_with_different_sizes1'
108
; CHECK-NEXT: loop:
@@ -22,7 +20,7 @@ define void @loads_of_same_pointer_with_different_sizes1(ptr %A, ptr %B, i64 %N)
2220
; CHECK-NEXT: (Low: %B High: ((4 * %N) + %B))
2321
; CHECK-NEXT: Member: {%B,+,4}<nuw><%loop>
2422
; CHECK-NEXT: Group [[GRP2]]:
25-
; CHECK-NEXT: (Low: %A High: (%N + %A))
23+
; CHECK-NEXT: (Low: %A High: (3 + %N + %A))
2624
; CHECK-NEXT: Member: {%A,+,1}<nuw><%loop>
2725
; CHECK-NEXT: Member: {%A,+,1}<nuw><%loop>
2826
; CHECK-EMPTY:
@@ -101,8 +99,6 @@ exit:
10199
ret void
102100
}
103101

104-
; FIXME: The both runtime checks for A are based on i8 accesses, but one should
105-
; be based on i32.
106102
define void @loads_of_same_pointer_with_different_sizes_retry_with_runtime_checks(ptr %A, ptr %B, i64 %N, i64 %off) {
107103
; CHECK-LABEL: 'loads_of_same_pointer_with_different_sizes_retry_with_runtime_checks'
108104
; CHECK-NEXT: loop:
@@ -145,7 +141,7 @@ define void @loads_of_same_pointer_with_different_sizes_retry_with_runtime_check
145141
; CHECK-NEXT: (Low: %A High: (%N + %A))
146142
; CHECK-NEXT: Member: {%A,+,1}<nuw><%loop>
147143
; CHECK-NEXT: Group [[GRP8]]:
148-
; CHECK-NEXT: (Low: %A High: (%N + %A))
144+
; CHECK-NEXT: (Low: %A High: (3 + %N + %A))
149145
; CHECK-NEXT: Member: {%A,+,1}<nuw><%loop>
150146
; CHECK-EMPTY:
151147
; CHECK-NEXT: Non vectorizable stores to invariant address were not found in loop.

0 commit comments

Comments
 (0)