diff options
author | Alex Zinenko <zinenko@google.com> | 2019-07-01 09:52:53 -0700 |
---|---|---|
committer | jpienaar <jpienaar@google.com> | 2019-07-01 09:56:56 -0700 |
commit | 5eef726bc8cf1e4b9d1067e52f9ad9f43bc1dec1 (patch) | |
tree | 3cff678cf241e77a56d325379eaed4678afd8283 /mlir/lib/Transforms/DialectConversion.cpp | |
parent | a83fd0d2c7c28dc8d3c3a7f45869782de3d1fb64 (diff) | |
download | bcm5719-llvm-5eef726bc8cf1e4b9d1067e52f9ad9f43bc1dec1.tar.gz bcm5719-llvm-5eef726bc8cf1e4b9d1067e52f9ad9f43bc1dec1.zip |
TypeConversion: do not materialize conversion of the type to itself
Type conversion does not necessarily affect all types, some of them may remain
untouched. The type conversion tool from the dialect conversion framework will
unconditionally insert a temporary cast operation from the type to itself
anyway, and will try to materialize it to a real conversion operation if there
are remaining uses. Simply use the original value instead.
PiperOrigin-RevId: 255975450
Diffstat (limited to 'mlir/lib/Transforms/DialectConversion.cpp')
-rw-r--r-- | mlir/lib/Transforms/DialectConversion.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/mlir/lib/Transforms/DialectConversion.cpp b/mlir/lib/Transforms/DialectConversion.cpp index f6d6329900b..be60ada6a43 100644 --- a/mlir/lib/Transforms/DialectConversion.cpp +++ b/mlir/lib/Transforms/DialectConversion.cpp @@ -170,6 +170,15 @@ void ArgConverter::applyRewrites() { continue; } + // If mapping is from type to itself, replace the remaining uses and drop + // the cast operation. + if (op->getNumOperands() == 1 && + op->getResult(0)->getType() == op->getOperand(0)->getType()) { + op->getResult(0)->replaceAllUsesWith(op->getOperand(0)); + op->destroy(); + continue; + } + // Otherwise, if there are any dangling uses then replace the fake // conversion operation with one generated by the type converter. This // is necessary as the cast must persist in the IR after conversion. |