[Mlir-commits] [mlir] [mlir][tensor] Fold producer linalg transpose with consumer tensor pack (PR #75658)

lorenzo chelini llvmlistbot at llvm.org
Thu Dec 28 06:58:35 PST 2023


================
@@ -142,11 +143,45 @@ struct FoldProducerPackWithConsumerLinalgTransposeOp
     return success();
   }
 };
+
+/// Fold 'transpose' -> 'pack' into 'pack' since 'pack' already has transpose
+/// semantics.
+struct FoldConsumerPackWithProducerLinalgTransposeOp
+    : public OpRewritePattern<PackOp> {
+  using OpRewritePattern<PackOp>::OpRewritePattern;
+
+  LogicalResult matchAndRewrite(PackOp packOp,
+                                PatternRewriter &rewriter) const override {
+    auto transposeOp = packOp.getSource().getDefiningOp<linalg::TransposeOp>();
+
+    if (!transposeOp)
+      return failure();
+
+    auto outerDimsPerm = packOp.getOuterDimsPerm();
+    SmallVector<int64_t> newOuterDimsPermVec =
+        static_cast<SmallVector<int64_t>>(transposeOp.getPermutation());
+
+    if (!outerDimsPerm.empty()) {
----------------
chelini wrote:

nit: please drop braces here.

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


More information about the Mlir-commits mailing list