From ac047d9fceac73f662e06ce9ebae206b069772a5 Mon Sep 17 00:00:00 2001 From: Uday Bondhugula Date: Tue, 14 Apr 2020 01:18:37 +0530 Subject: [PATCH] [MLIR] Remove dead affine.applys while generating pointwise copies This makes no impact on the test cases because affine-data-copy-generate runs whole function canonicalization at its end; however, the latter will be removed in a pending revision. It is thus useful to clean up these affine.applys right here, and eventually, not even generate these (when the right API to compose by construction is in place). Differential Revision: https://reviews.llvm.org/D78055 --- mlir/lib/Transforms/Utils/LoopUtils.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mlir/lib/Transforms/Utils/LoopUtils.cpp b/mlir/lib/Transforms/Utils/LoopUtils.cpp index 01df259..15f5c25 100644 --- a/mlir/lib/Transforms/Utils/LoopUtils.cpp +++ b/mlir/lib/Transforms/Utils/LoopUtils.cpp @@ -1492,6 +1492,7 @@ generatePointWiseCopy(Location loc, Value memref, Value fastMemRef, SmallVector fastBufExprs; SmallVector fastBufMapOperands; AffineForOp copyNestRoot; + SmallVector mayBeDeadApplys; for (unsigned d = 0; d < rank; ++d) { auto forOp = createCanonicalizedAffineForOp(b, loc, lbOperands, lbMaps[d], ubOperands, ubMaps[d]); @@ -1510,6 +1511,7 @@ generatePointWiseCopy(Location loc, Value memref, Value fastMemRef, b.getAffineDimExpr(2 * d)); fastBufMapOperands.push_back(offset); fastBufMapOperands.push_back(forOp.getInductionVar()); + mayBeDeadApplys.push_back(offset); // Subscript for the slow memref being copied. memIndices.push_back(forOp.getInductionVar()); @@ -1520,6 +1522,11 @@ generatePointWiseCopy(Location loc, Value memref, Value fastMemRef, fastBufMap = simplifyAffineMap(fastBufMap); canonicalizeMapAndOperands(&fastBufMap, &fastBufMapOperands); + // Drop any dead affine.applys. + for (auto applyOp : mayBeDeadApplys) + if (applyOp.use_empty()) + applyOp.erase(); + if (!isCopyOut) { // Copy in. auto load = b.create(loc, memref, memIndices); @@ -2191,7 +2198,7 @@ static AffineIfOp createSeparationCondition(MutableArrayRef loops, // larger (and resp. smaller) than any other lower (or upper bound). SmallVector fullTileLb, fullTileUb; for (auto loop : loops) { - (void) loop; + (void)loop; // TODO: Non-unit stride is not an issue to generalize to. assert(loop.getStep() == 1 && "point loop step expected to be one"); // Mark everything symbols for the purpose of finding a constant diff pair. -- 2.7.4