[Mlir-commits] [mlir] [mlir][vector] Add InsertInsertToInsert to insert op canonicalize patterns (PR #147045)
lonely eagle
llvmlistbot at llvm.org
Fri Jul 4 05:28:16 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:
This ensures that dest comes from the insert op.
```
auto destInsert = op.getDest().getDefiningOp<InsertOp>();
if (!destInsert)
return failure();
```
It is already clear that the insert op that is currently matched by the pattern uses dest. we have already determined the structure of the IR when we perform the following conditional judgement.
```
if (!destInsert->hasOneUse())
return failure();
```
https://github.com/llvm/llvm-project/pull/147045
More information about the Mlir-commits
mailing list