[mlir][bufferization] Fix invalid IR in SimplifyClones canonicalization (#74417)

`SimplifyClones` used to generate an invalid op:
```
error: 'memref.cast' op operand type 'memref<*xf32>' and result type 'memref<*xf32>' are cast incompatible
  %2 = bufferization.clone %1 : memref<*xf32> to memref<*xf32
```

This commit fixes tests such as
`mlir/test/Dialect/Bufferization/canonicalize.mlir` when verifying the
IR after each pattern (#74270).
This commit is contained in:
Matthias Springer 2023-12-06 09:41:57 +09:00 committed by GitHub
parent dbb782dffd
commit 68f91cd257
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -507,8 +507,10 @@ struct SimplifyClones : public OpRewritePattern<CloneOp> {
return failure();
}
rewriter.replaceOpWithNewOp<memref::CastOp>(cloneOp, cloneOp.getType(),
source);
if (source.getType() != cloneOp.getType())
source = rewriter.create<memref::CastOp>(cloneOp.getLoc(),
cloneOp.getType(), source);
rewriter.replaceOp(cloneOp, source);
rewriter.eraseOp(redundantDealloc);
return success();
}