[Mlir-commits] [mlir] [mlir] Optimize const values AffineMap::compose (PR #141005)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu May 22 21:53:28 PDT 2025


================
@@ -579,16 +579,16 @@ AffineMap AffineMap::compose(AffineMap map) const {
 
 SmallVector<int64_t, 4> AffineMap::compose(ArrayRef<int64_t> values) const {
   assert(getNumSymbols() == 0 && "Expected symbol-less map");
-  SmallVector<AffineExpr, 4> exprs;
-  exprs.reserve(values.size());
+  unsigned numValues = values.size();
+  DenseMap<AffineExpr, AffineExpr> mapping;
   MLIRContext *ctx = getContext();
-  for (auto v : values)
-    exprs.push_back(getAffineConstantExpr(v, ctx));
-  auto resMap = compose(AffineMap::get(0, 0, exprs, ctx));
+  for (unsigned idx = 0; idx < numValues; ++idx)
+    mapping[getAffineDimExpr(idx, ctx)] =
----------------
qazwsxedcrfvtg14 wrote:

Yeah, it makes sense. I rewrote the code with `replaceDims`.

Thanks!

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


More information about the Mlir-commits mailing list