Skip to content

Commit

Permalink
[mlir][bufferization] Fix invalid IR in SimplifyClones canonicaliza…
Browse files Browse the repository at this point in the history
…tion (#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).
  • Loading branch information
matthias-springer authored Dec 6, 2023
1 parent dbb782d commit 68f91cd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 68f91cd

Please sign in to comment.