[Mlir-commits] [mlir] [mlir] Add bubbling patterns for non intersecting reshapes (PR #103401)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Aug 13 14:14:35 PDT 2024


================
@@ -140,6 +140,76 @@ struct FoldPaddingExpandIntoInsert : public OpRewritePattern<OpTy> {
     return success();
   }
 };
+
+/// Pattern to bubble up a tensor.expand_shape op through a producer
+/// tensor.collapse_shape op that has non intersecting reassociations.
+struct BubbleUpExpandThroughParallelCollapse
+    : public OpRewritePattern<tensor::ExpandShapeOp> {
+  using OpRewritePattern<tensor::ExpandShapeOp>::OpRewritePattern;
+
+  LogicalResult matchAndRewrite(tensor::ExpandShapeOp expandOp,
+                                PatternRewriter &rewriter) const override {
+    auto collapseOp =
+        expandOp.getSrc().getDefiningOp<tensor::CollapseShapeOp>();
+    if (!collapseOp || !collapseOp->hasOneUse())
----------------
MaheshRavishankar wrote:

I think you can drop the `hasOneUse` check.

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


More information about the Mlir-commits mailing list