diff options
author | Vivek <vivekkhandelwal1424@gmail.com> | 2021-02-23 00:48:04 +0530 |
---|---|---|
committer | Uday Bondhugula <uday@polymagelabs.com> | 2021-02-23 00:50:04 +0530 |
commit | 817d343fb048b330b77a7b4ef0af0dba7450dfb2 (patch) | |
tree | fd7208f31829f9975ad58c26a8a5ca902c817fdb /mlir/lib/Transforms/Utils/LoopUtils.cpp | |
parent | 1b968467c057df980df214a88cddac74dccff15e (diff) | |
download | llvm-817d343fb048b330b77a7b4ef0af0dba7450dfb2.zip llvm-817d343fb048b330b77a7b4ef0af0dba7450dfb2.tar.gz llvm-817d343fb048b330b77a7b4ef0af0dba7450dfb2.tar.bz2 |
[MLIR] Fix tilePerfectlyNested utility for handling non-unit step size
The current implementation of tilePerfectlyNested utility doesn't handle
the non-unit step size. We have added support to perform tiling
correctly even if the step size of the loop to be tiled is non-unit.
Fixes https://bugs.llvm.org/show_bug.cgi?id=49188.
Differential Revision: https://reviews.llvm.org/D97037
Diffstat (limited to 'mlir/lib/Transforms/Utils/LoopUtils.cpp')
-rw-r--r-- | mlir/lib/Transforms/Utils/LoopUtils.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/mlir/lib/Transforms/Utils/LoopUtils.cpp b/mlir/lib/Transforms/Utils/LoopUtils.cpp index a8c32c84..77d24fb 100644 --- a/mlir/lib/Transforms/Utils/LoopUtils.cpp +++ b/mlir/lib/Transforms/Utils/LoopUtils.cpp @@ -848,7 +848,9 @@ constructTiledIndexSetHyperRect(MutableArrayRef<AffineForOp> origLoops, OperandRange newUbOperands = origLoops[i].getUpperBoundOperands(); newLoops[i].setLowerBound(newLbOperands, origLoops[i].getLowerBoundMap()); newLoops[i].setUpperBound(newUbOperands, origLoops[i].getUpperBoundMap()); - newLoops[i].setStep(tileSizes[i]); + // If the step size of original loop is x and tileSize is y then after + // tiling the tile space loops' step size becomes x*y. + newLoops[i].setStep(tileSizes[i] * origLoops[i].getStep()); } // Bounds for intra-tile loops. for (unsigned i = 0; i < width; i++) { @@ -858,20 +860,23 @@ constructTiledIndexSetHyperRect(MutableArrayRef<AffineForOp> origLoops, AffineMap lbMap = b.getDimIdentityMap(); newLoops[width + i].setLowerBound( /*operands=*/newLoops[i].getInductionVar(), lbMap); + // The step sizes of intra-tile loops is just the original loops' step size. + newLoops[width + i].setStep(origLoops[i].getStep()); // Set the upper bound. if (mayBeConstantCount && mayBeConstantCount.getValue() < tileSizes[i]) { // Trip count is less than the tile size: upper bound is lower bound + - // trip count. - AffineMap ubMap = - b.getSingleDimShiftAffineMap(mayBeConstantCount.getValue()); + // trip count * stepSize. + AffineMap ubMap = b.getSingleDimShiftAffineMap( + mayBeConstantCount.getValue() * origLoops[i].getStep()); newLoops[width + i].setUpperBound( /*operands=*/newLoops[i].getInductionVar(), ubMap); } else if (largestDiv % tileSizes[i] != 0) { - // Intra-tile loop ii goes from i to min(i + tileSize, ub_i). + // Intra-tile loop ii goes from i to min(i + tileSize * stepSize, ub_i). // Construct the upper bound map; the operands are the original operands // with 'i' (tile-space loop) appended to it. The new upper bound map is - // the original one with an additional expression i + tileSize appended. + // the original one with an additional expression i + tileSize * stepSize + // appended. // Add dim operands from original upper bound. SmallVector<Value, 4> ubOperands; @@ -892,8 +897,8 @@ constructTiledIndexSetHyperRect(MutableArrayRef<AffineForOp> origLoops, boundExprs.reserve(1 + origUbMap.getNumResults()); AffineExpr dim = b.getAffineDimExpr(origUbMap.getNumDims()); // The new upper bound map is the original one with an additional - // expression i + tileSize appended. - boundExprs.push_back(dim + tileSizes[i]); + // expression i + tileSize * stepSize (of original loop) appended. + boundExprs.push_back(dim + tileSizes[i] * origLoops[i].getStep()); boundExprs.append(origUbMap.getResults().begin(), origUbMap.getResults().end()); AffineMap ubMap = @@ -903,7 +908,8 @@ constructTiledIndexSetHyperRect(MutableArrayRef<AffineForOp> origLoops, } else { // No need of the min expression. AffineExpr dim = b.getAffineDimExpr(0); - AffineMap ubMap = AffineMap::get(1, 0, dim + tileSizes[i]); + AffineMap ubMap = + AffineMap::get(1, 0, dim + tileSizes[i] * origLoops[i].getStep()); newLoops[width + i].setUpperBound(newLoops[i].getInductionVar(), ubMap); } } |