Skip to content

Commit 4de3184

Browse files
committed
[LAA] Use cross-iteration alias analysis
LAA analyzes cross-iteration memory dependencies, as such AA should not make assumptions about equality of values inside the loop, as they may come from different iterations. Fix this by exposing the MayBeCrossIteration AA flag and enabling it for LAA. Differential Revision: https://reviews.llvm.org/D137958
1 parent 1403073 commit 4de3184

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

llvm/include/llvm/Analysis/AliasAnalysis.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,11 @@ class BatchAAResults {
651651
DominatorTree *DT) {
652652
return AA.callCapturesBefore(I, MemLoc, DT, AAQI);
653653
}
654+
655+
/// Assume that values may come from different cycle iterations.
656+
void enableCrossIterationMode() {
657+
AAQI.MayBeCrossIteration = true;
658+
}
654659
};
655660

656661
/// Temporary typedef for legacy code that uses a generic \c AliasAnalysis

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,10 @@ class AccessAnalysis {
622622
AccessAnalysis(Loop *TheLoop, AAResults *AA, LoopInfo *LI,
623623
MemoryDepChecker::DepCandidates &DA,
624624
PredicatedScalarEvolution &PSE)
625-
: TheLoop(TheLoop), BAA(*AA), AST(BAA), LI(LI), DepCands(DA), PSE(PSE) {}
625+
: TheLoop(TheLoop), BAA(*AA), AST(BAA), LI(LI), DepCands(DA), PSE(PSE) {
626+
// We're analyzing dependences across loop iterations.
627+
BAA.enableCrossIterationMode();
628+
}
626629

627630
/// Register a load and whether it is only read from.
628631
void addLoad(MemoryLocation &Loc, Type *AccessTy, bool IsReadOnly) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; RUN: opt -passes='print<access-info>' -disable-output 2>&1 < %s | FileCheck %s
2+
3+
; CHECK: Dependences:
4+
; CHECK-NEXT: Unknown:
5+
; CHECK-NEXT: %t63 = load double, ptr %t62, align 8 ->
6+
; CHECK-NEXT: store double %t63, ptr %t64, align 8
7+
8+
define i32 @test() {
9+
%a1 = alloca [128 x double], align 8
10+
%a2 = alloca [128 x double], align 8
11+
%a3 = alloca [128 x double], align 8
12+
%t30 = getelementptr double, ptr %a2, i64 -32
13+
br label %loop
14+
15+
loop:
16+
%t58 = phi i64 [ %t65, %loop ], [ 0, %0 ]
17+
%t59 = icmp ule i64 %t58, 32
18+
%t60 = select i1 %t59, ptr %a1, ptr %t30
19+
%t62 = getelementptr inbounds double, ptr %t60, i64 %t58
20+
%t63 = load double, ptr %t62, align 8
21+
%t61 = select i1 %t59, ptr %a2, ptr %a3
22+
%t64 = getelementptr inbounds double, ptr %t61, i64 %t58
23+
store double %t63, ptr %t64, align 8
24+
%t65 = add nuw nsw i64 %t58, 1
25+
%t66 = icmp eq i64 %t65, 94
26+
br i1 %t66, label %exit, label %loop
27+
28+
exit:
29+
ret i32 0
30+
}

0 commit comments

Comments
 (0)