[Mlir-commits] [mlir] [mlir][vector] Add InsertInsertToInsert to insert op canonicalize patterns (PR #147045)
lonely eagle
llvmlistbot at llvm.org
Fri Jul 4 05:48:22 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.func @main(%arg : vector) {
%v = insert %value0, %arg
use (%v) // for example, nvgpu.mma,
%v1 = insert %value1, %v
}
```
In the above case without the conditional judgement above it should become.
```
fun.func @main(%arg : vector) {
use (%v) // for example, nvgpu.mma,
%v1 = insert %value, %arg
}
```
Then mlir-opt should report an error that the deleted ssa value is still in use.So make sure there's only one use here.
https://github.com/llvm/llvm-project/pull/147045
More information about the Mlir-commits
mailing list