From 1f9ca5adbac08dcca73b9e12aa2c5ed777cc460e Mon Sep 17 00:00:00 2001 From: Arnab Dutta Date: Sat, 20 Nov 2021 12:00:49 +0530 Subject: [PATCH] [MLIR] Avoid creation of buggy affine maps while replacing dimension and symbol Initially before appending the newly composed dimension and symbols to the dimension and symbol list whose size is to be passed in AffineMap::get(), the call to the AffineMap::get() was made, resulting in wrong dimCount and symbolCount being passed as argument. We move the call to the AffineMap::get() after the diimension and symbol list are updated. Differential Revision: https://reviews.llvm.org/D114237 --- mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp index 9f24cfc..2ca0474 100644 --- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp +++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp @@ -625,13 +625,13 @@ static LogicalResult replaceDimOrSym(AffineMap *map, ValueRange composeSyms = affineApply.getMapOperands().take_back(composeMap.getNumSymbols()); - // Perform the replacement and append the dims and symbols where relevant. + // Append the dims and symbols where relevant and perform the replacement. MLIRContext *ctx = map->getContext(); AffineExpr toReplace = isDimReplacement ? getAffineDimExpr(pos, ctx) : getAffineSymbolExpr(pos, ctx); - *map = map->replace(toReplace, composeExpr, dims.size(), syms.size()); dims.append(composeDims.begin(), composeDims.end()); syms.append(composeSyms.begin(), composeSyms.end()); + *map = map->replace(toReplace, composeExpr, dims.size(), syms.size()); return success(); } -- 2.7.4