[Mlir-commits] [mlir] [mlir][vector] Add InsertInsertToInsert to insert op canonicalize patterns (PR #147045)

lonely eagle llvmlistbot at llvm.org
Fri Jul 4 05:31:31 PDT 2025


================
@@ -3335,6 +3335,28 @@ class InsertSplatToSplat final : public OpRewritePattern<InsertOp> {
   }
 };
 
+/// Pattern to rewrite a InsertOp(InsertOp) to InsertOp.
+class InsertInsertToInsert final : public OpRewritePattern<InsertOp> {
+public:
+  using OpRewritePattern::OpRewritePattern;
+  LogicalResult matchAndRewrite(InsertOp op,
+                                PatternRewriter &rewriter) const override {
+    auto destInsert = op.getDest().getDefiningOp<InsertOp>();
+    if (!destInsert)
+      return failure();
+
+    if (!destInsert->hasOneUse())
+      return failure();
----------------
linuxlonelyeagle wrote:

```
fun xxx {
  %v = insert xxx // has only one use, this use is next insert,make sure no other ops use %v.
  %v1 = insert xxx (use %v)
}
```

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


More information about the Mlir-commits mailing list