[mlir][DialectConversion] Do not prematurely drop unused cast operations
authorStephan Herhut <herhut@google.com>
Thu, 26 Nov 2020 16:08:49 +0000 (17:08 +0100)
committerStephan Herhut <herhut@google.com>
Thu, 26 Nov 2020 16:39:14 +0000 (17:39 +0100)
commit20c926e0797e074bfb946d2c8ce002888ebc2bcd
tree6fb2412d2359d27540e2572fd7e0bda1e7e08758
parent0b20d0af3f0ac71a037479984813e0da95ea0ff9
[mlir][DialectConversion] Do not prematurely drop unused cast operations

The rewrite logic has an optimization to drop a cast operation after
rewriting block arguments if the cast operation has no users. This is
unsafe as there might be a pending rewrite that replaced the cast operation
itself and hence would trigger a second free.

Instead, do not remove the casts and leave it up to a later canonicalization
to do so.

Differential Revision: https://reviews.llvm.org/D92184
mlir/lib/Transforms/Utils/DialectConversion.cpp
mlir/test/Transforms/test-legalizer.mlir