[Mlir-commits] [mlir] [mlir] Optimize const values AffineMap::compose (PR #141005)
Jeremy Kun
llvmlistbot at llvm.org
Thu May 22 09:14:01 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)] =
----------------
j2kun wrote:
Since you know you're replacing dims directly and it's not a sparse replacement (every dim is replaced), why not use `replaceDims`/`replaceDimsAndSymbols`? This avoids constructing the `getAffineDimExpr` as well as avoiding the hashmap construction/lookups (in favor of array indexing which is more performant).
https://github.com/llvm/llvm-project/pull/141005
More information about the Mlir-commits
mailing list