diff options
author | Sergei Grechanik <sergei.grechanik@intel.com> | 2020-12-09 11:03:56 -0800 |
---|---|---|
committer | Diego Caballero <diego.caballero@intel.com> | 2020-12-09 12:19:34 -0800 |
commit | 2d3b9fdc193fa835313f09f526b51bf6de3a54ef (patch) | |
tree | 56f8422e9fc34bec40df81abc8d49b3ef131cd77 /mlir/lib/Analysis/LoopAnalysis.cpp | |
parent | fe3b244ef7c2656c5876ff3f91232406f9854c42 (diff) | |
download | llvm-2d3b9fdc193fa835313f09f526b51bf6de3a54ef.zip llvm-2d3b9fdc193fa835313f09f526b51bf6de3a54ef.tar.gz llvm-2d3b9fdc193fa835313f09f526b51bf6de3a54ef.tar.bz2 |
[mlir][Affine] Fix vectorizability check for multiple load/stores
This patch fixes a bug that allowed vectorizing of loops with loads and
stores having indexing functions varying along different memory
dimensions.
Reviewed By: aartbik, dcaballe
Differential Revision: https://reviews.llvm.org/D92702
Diffstat (limited to 'mlir/lib/Analysis/LoopAnalysis.cpp')
-rw-r--r-- | mlir/lib/Analysis/LoopAnalysis.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/mlir/lib/Analysis/LoopAnalysis.cpp b/mlir/lib/Analysis/LoopAnalysis.cpp index 210b68e..932559c 100644 --- a/mlir/lib/Analysis/LoopAnalysis.cpp +++ b/mlir/lib/Analysis/LoopAnalysis.cpp @@ -327,11 +327,23 @@ isVectorizableLoopBodyWithOpCond(AffineForOp loop, bool mlir::isVectorizableLoopBody(AffineForOp loop, int *memRefDim, NestedPattern &vectorTransferMatcher) { + *memRefDim = -1; VectorizableOpFun fun([memRefDim](AffineForOp loop, Operation &op) { auto load = dyn_cast<AffineLoadOp>(op); auto store = dyn_cast<AffineStoreOp>(op); - return load ? isContiguousAccess(loop.getInductionVar(), load, memRefDim) - : isContiguousAccess(loop.getInductionVar(), store, memRefDim); + int thisOpMemRefDim = -1; + bool isContiguous = load ? isContiguousAccess(loop.getInductionVar(), load, + &thisOpMemRefDim) + : isContiguousAccess(loop.getInductionVar(), store, + &thisOpMemRefDim); + if (thisOpMemRefDim != -1) { + // If memory accesses vary across different dimensions then the loop is + // not vectorizable. + if (*memRefDim != -1 && *memRefDim != thisOpMemRefDim) + return false; + *memRefDim = thisOpMemRefDim; + } + return isContiguous; }); return isVectorizableLoopBodyWithOpCond(loop, fun, vectorTransferMatcher); } |