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

`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 (llvm#74270).
  • Loading branch information
matthias-springer committed Dec 5, 2023
1 parent 6688657 commit 052f472
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 052f472

Please sign in to comment.