[Mlir-commits] [mlir] [mlir][tensor][memref] Enhance collapse(expand(src)) canonicalization pattern. (PR #145995)
Han-Chung Wang
llvmlistbot at llvm.org
Thu Jun 26 19:00:06 PDT 2025
================
@@ -305,8 +306,42 @@ struct ComposeCollapseOfExpandOp : public OpRewritePattern<CollapseOpTy> {
rewriter.replaceOpWithNewOp<CollapseOpTy>(
collapseOp, resultType, expandOp.getSrc(), composedReassociation);
} else if (srcRank < resultRank) {
+ // Compute the dynamic output shape for the new expand_shape op.
+ Location loc = collapseOp.getLoc();
+ SmallVector<OpFoldResult> origOutputShape =
+ expandOp.getMixedOutputShape();
+ SmallVector<OpFoldResult> newOutputShape;
+ for (auto indices : collapseOp.getReassociationIndices()) {
+ int64_t numStaticElems = 1;
+ SmallVector<Value> dynamicSizes;
+ for (auto idx : indices) {
+ OpFoldResult size = origOutputShape[idx];
+ if (auto maybeCst = getConstantIntValue(size)) {
----------------
hanhanW wrote:
> Use auto if and only if it makes the code more readable or easier to maintain.
https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable
This is a neutral case to me, because I think we don't really are the actual type name and it makes it easier to maintain. E.g., I've been wanting to remove `, 2` from the SmallVector, and you don't need to update it if we use auto here. reassociation indices is a list of int array is quite common in MLIR, so I don't think spelling the type is necessary. I can see some people find it helpful, so I'm going to make the change.
https://github.com/llvm/llvm-project/pull/145995
More information about the Mlir-commits
mailing list