aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/LoopAccessAnalysis.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2021-04-28 20:02:47 +0100
committerFlorian Hahn <flo@fhahn.com>2021-04-28 20:19:40 +0100
commit1ed7f8ede564c3b11da4fdca30c36ccbff422576 (patch)
tree52cc868539bafacc327612a61c632b4449cd86b3 /llvm/lib/Analysis/LoopAccessAnalysis.cpp
parentf391de8cb6f9c8ecbd3c6fcf025a2ee203db0726 (diff)
downloadllvm-1ed7f8ede564c3b11da4fdca30c36ccbff422576.zip
llvm-1ed7f8ede564c3b11da4fdca30c36ccbff422576.tar.gz
llvm-1ed7f8ede564c3b11da4fdca30c36ccbff422576.tar.bz2
[LAA] Support pointer phis in loop by analyzing each incoming pointer.
SCEV does not look through non-header PHIs inside the loop. Such phis can be analyzed by adding separate accesses for each incoming pointer value. This results in 2 more loops vectorized in SPEC2000/186.crafty and avoids regressions when sinking instructions before vectorizing. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D101286
Diffstat (limited to 'llvm/lib/Analysis/LoopAccessAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/LoopAccessAnalysis.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index 2a69878..cd08632 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -1938,7 +1938,18 @@ void LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI,
if (blockNeedsPredication(ST->getParent(), TheLoop, DT))
Loc.AATags.TBAA = nullptr;
- Accesses.addStore(Loc);
+ // SCEV does not look through non-header PHIs inside the loop. Such phis
+ // can be analyzed by adding separate accesses for each incoming pointer
+ // value.
+ auto *PN = dyn_cast<PHINode>(Loc.Ptr);
+ if (PN && TheLoop->contains(PN->getParent()) &&
+ PN->getParent() != TheLoop->getHeader()) {
+ for (const Use &Inc : PN->incoming_values()) {
+ MemoryLocation NewLoc = Loc.getWithNewPtr(Inc);
+ Accesses.addStore(NewLoc);
+ }
+ } else
+ Accesses.addStore(Loc);
}
}
@@ -1982,7 +1993,17 @@ void LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI,
if (blockNeedsPredication(LD->getParent(), TheLoop, DT))
Loc.AATags.TBAA = nullptr;
- Accesses.addLoad(Loc, IsReadOnlyPtr);
+ // SCEV does not look through non-header PHIs inside the loop. Such phis can
+ // be analyzed by adding separate accesses for each incoming pointer value.
+ auto *PN = dyn_cast<PHINode>(Loc.Ptr);
+ if (PN && TheLoop->contains(PN->getParent()) &&
+ PN->getParent() != TheLoop->getHeader()) {
+ for (const Use &Inc : PN->incoming_values()) {
+ MemoryLocation NewLoc = Loc.getWithNewPtr(Inc);
+ Accesses.addLoad(NewLoc, IsReadOnlyPtr);
+ }
+ } else
+ Accesses.addLoad(Loc, IsReadOnlyPtr);
}
// If we write (or read-write) to a single destination and there are no