aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/LoopAccessAnalysis.cpp
diff options
context:
space:
mode:
authorAlexandros Lamprineas <alexandros.lamprineas@arm.com>2023-12-05 15:27:30 +0000
committerGitHub <noreply@github.com>2023-12-05 15:27:30 +0000
commit3ad6d1cbe54dc06554303097cc51d590edaa1c1c (patch)
tree8ceeeda2aada1863fd652d80303ab6a69800e4bc /llvm/lib/Analysis/LoopAccessAnalysis.cpp
parenta28e4eac26ccd2e17f041b8d96da93df4a2414c0 (diff)
downloadllvm-3ad6d1cbe54dc06554303097cc51d590edaa1c1c.zip
llvm-3ad6d1cbe54dc06554303097cc51d590edaa1c1c.tar.gz
llvm-3ad6d1cbe54dc06554303097cc51d590edaa1c1c.tar.bz2
[LAA] Fix incorrect dependency classification. (#70819)
As shown in #70473, the following loop was not considered safe to vectorize. When determining the memory access dependencies in a loop which has negative iteration step, we invert the source and sink of the dependence. Perhaps we should just invert the operands to getMinusSCEV(). This way the dependency is not regarded to be true, since the users of the `IsWrite` variables, which correspond to each of the memory accesses, rely on program order and therefore should not be swapped. void vectorizable_Read_Write(int *A) { for (unsigned i = 1022; i >= 0; i--) A[i+1] = A[i] + 1; }
Diffstat (limited to 'llvm/lib/Analysis/LoopAccessAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/LoopAccessAnalysis.cpp9
1 files changed, 3 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index 91f5eab0..a8dbb66 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -1916,15 +1916,12 @@ getDependenceDistanceStrideAndSize(
const SCEV *Src = PSE.getSCEV(APtr);
const SCEV *Sink = PSE.getSCEV(BPtr);
- // If the induction step is negative we have to invert source and sink of
- // the dependence.
+ // If the induction step is negative we have to invert source and sink of the
+ // dependence when measuring the distance between them. We should not swap
+ // AIsWrite with BIsWrite, as their uses expect them in program order.
if (StrideAPtr < 0) {
- std::swap(APtr, BPtr);
- std::swap(ATy, BTy);
std::swap(Src, Sink);
- std::swap(AIsWrite, BIsWrite);
std::swap(AInst, BInst);
- std::swap(StrideAPtr, StrideBPtr);
}
const SCEV *Dist = SE.getMinusSCEV(Sink, Src);