[Mlir-commits] [mlir] [MLIR][Affine] Fix affine.apply verifier and add functionality to demote invalid symbols to dims (PR #128289)

Uday Bondhugula llvmlistbot at llvm.org
Tue Apr 22 15:51:05 PDT 2025


================
@@ -1359,13 +1368,62 @@ static void canonicalizePromotedSymbols(MapOrSet *mapOrSet,
 
   resultOperands.append(remappedSymbols.begin(), remappedSymbols.end());
   *operands = resultOperands;
-  *mapOrSet = mapOrSet->replaceDimsAndSymbols(dimRemapping, {}, nextDim,
-                                              oldNumSyms + nextSym);
+  *mapOrSet = mapOrSet->replaceDimsAndSymbols(
+      dimRemapping, /*symReplacements=*/{}, nextDim, oldNumSyms + nextSym);
 
   assert(mapOrSet->getNumInputs() == operands->size() &&
          "map/set inputs must match number of operands");
 }
 
+// A valid affine dimension may appear as a symbol in affine.apply operations.
+// This function canonicalizes symbols that are valid dims, but not valid
+// symbols into actual dims. Without such a legalization, the affine.apply will
+// be invalid. This method is the exact inverse of canonicalizePromotedSymbols.
+template <class MapOrSet>
+static void legalizeDemotedDims(MapOrSet *mapOrSet,
----------------
bondhugula wrote:

Thanks - done. The pass by pointer was to stay consistent with `canonicalizeMapAndOperands`, but it should have been by reference even for the latter, and I've changed this.

https://github.com/llvm/llvm-project/pull/128289


More information about the Mlir-commits mailing list