[MLIR] Avoid creation of buggy affine maps while replacing dimension and symbol
authorArnab Dutta <arnab.dutta@cerebras.net>
Sat, 20 Nov 2021 06:30:49 +0000 (12:00 +0530)
committerUday Bondhugula <uday@polymagelabs.com>
Sat, 20 Nov 2021 06:31:29 +0000 (12:01 +0530)
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

index 9f24cfc..2ca0474 100644 (file)
@@ -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();
 }