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

Mehdi Amini llvmlistbot at llvm.org
Fri Jul 4 05:21:06 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();
----------------
joker-eph wrote:

What's the thinking here behind this condition?
Seems like we're just taking a vector that we're overriding elements already inserted, I don't quite get the heuristics?

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


More information about the Mlir-commits mailing list